<commit_before>﻿using System;
using System.Text;

namespace WebIrc
{
    public class TitleBuilder
    {
        string _title = string.Empty;
        public string HtmlTitle
        {
            get { return _title; }
            set
            {
                if (value != null)
                    _title = value;
                else
                    _title = string.Empty;
            }
        }

        readonly StringBuilder sb;


        public TitleBuilder()
        {
            sb = new StringBuilder(256);
        }


        public TitleBuilder Append(string s)
        {
            if (!string.IsNullOrEmpty(s))
            {
                sb.Append(' ');
                sb.Append(s);
            }
            return this;
        }

        public TitleBuilder Append(char c)
        {
            sb.Append(' ').Append(c);
            return this;
        }

        public TitleBuilder AppendFormat(string format, params object[] args)
        {
            if (!string.IsNullOrEmpty(format))
            {
                sb.Append(' ');
                sb.AppendFormat(format, args);
            }
            return this;
        }


        public TitleBuilder Set(string s)
        {
            sb.Clear();
            if (!string.IsNullOrEmpty(s))
            {
                sb.Append(s);
            }
            return this;
        }

        public TitleBuilder SetFormat(string format, params object[] args)
        {
            sb.Clear();
            if (!string.IsNullOrEmpty(format))
            {
                sb.AppendFormat(format, args);
            }
            return this;
        }

        public TitleBuilder SetHtmlTitle()
        {
            sb.Clear();
            sb.Append(string.Concat("[ ", HtmlTitle, " ]"));

            return this;
        }


        public TitleBuilder AppendTime(TimeSpan duration)
        {
            if (duration.TotalSeconds >= 0.5d)
            {
                sb.Append(' ');

                var hours = (int)duration.TotalHours;
                int seconds = duration.Seconds;
                if (duration.Milliseconds >= 500)
                    seconds++;

                if (hours > 0)
                    sb.AppendFormat("[{0}:{1:00}:{2:00}]", hours, duration.Minutes, seconds);
                else
                    sb.AppendFormat("[{0}:{1:00}]", duration.Minutes, seconds);
            }
            return this;
        }

        public TitleBuilder AppendSize(long size)
        {
            if (size >= 1)
            {
                sb.Append(' ');
                var sizeInK = size / 1024d;
                if (sizeInK > 1024)
                {
                    var sizeInM = sizeInK / 1024d;
                    sb.Append(sizeInM.ToString("#.#"));
                    sb.Append("MB");
                }
                else
                {
                    sb.Append(sizeInK.ToString("#.#"));
                    sb.Append("KB");
                }
            }
            return this;
        }


        public override string ToString()
        {
            if (sb.Length > 0)
                return sb.ToString();
            else
                return string.Concat("[ ", HtmlTitle, " ]");
        }
    }
}<commit_msg>UrlTitling: Make TitleBuilder use common format<commit_after>﻿using System;
using System.Text;
using MeidoCommon.Formatting;


namespace WebIrc
{
    public class TitleBuilder
    {
        string _title = string.Empty;
        public string HtmlTitle
        {
            get { return _title; }
            set
            {
                if (value != null)
                    _title = value;
                else
                    _title = string.Empty;
            }
        }

        readonly StringBuilder sb;


        public TitleBuilder()
        {
            sb = new StringBuilder(256);
        }


        public TitleBuilder Append(string s)
        {
            if (!string.IsNullOrEmpty(s))
            {
                sb.Append(' ');
                sb.Append(s);
            }
            return this;
        }

        public TitleBuilder Append(char c)
        {
            sb.Append(' ').Append(c);
            return this;
        }

        public TitleBuilder AppendFormat(string format, params object[] args)
        {
            if (!string.IsNullOrEmpty(format))
            {
                sb.Append(' ');
                sb.AppendFormat(format, args);
            }
            return this;
        }


        public TitleBuilder Set(string s)
        {
            sb.Clear();
            if (!string.IsNullOrEmpty(s))
            {
                sb.Append(s);
            }
            return this;
        }

        public TitleBuilder SetFormat(string format, params object[] args)
        {
            sb.Clear();
            if (!string.IsNullOrEmpty(format))
            {
                sb.AppendFormat(format, args);
            }
            return this;
        }

        public TitleBuilder SetHtmlTitle()
        {
            sb.Clear();
            sb.Append(string.Concat("[ ", HtmlTitle, " ]"));

            return this;
        }


        public TitleBuilder AppendTime(TimeSpan duration)
        {
            if (duration.TotalSeconds >= 0.5d)
            {
                sb.Append(' ');
                sb.Append( Format.Duration(duration) );
            }
            return this;
        }

        public TitleBuilder AppendSize(long size)
        {
            if (size >= 1)
            {
                sb.Append(' ');
                sb.Append( Format.Size(size) );
            }
            return this;
        }


        public override string ToString()
        {
            if (sb.Length > 0)
                return sb.ToString();
            else
                return string.Concat("[ ", HtmlTitle, " ]");
        }
    }
}
{'fraction_non_alphanumeric': 0.10027192386131883, 'fraction_numerical': 0.006968048946295037, 'mean_word_length': 1.0258175559380378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2115448', 'n_tokens_mistral': 1547, 'n_tokens_neox': 1449, 'n_words': 312}