Ejemplo n.º 1
0
 static string RegexWith(SurroundConfig config, string input, string pattern, RegexOptions options)
 {
     if (config.Activated)
     {
         openingClosingBuilder.Clear();
         UseSb(openingClosingBuilder, config, "$1");
         return(new Regex(pattern, options).Replace(input, openingClosingBuilder.ToString()));
     }
     else
     {
         return(input);
     }
 }
Ejemplo n.º 2
0
        private static void UseSb(StringBuilder sb, SurroundConfig conf, string middle)
        {
            if (conf.styleSurround)
            {
                string styleOpening = $"<style=\"{conf.styleName}\">";
                sb.Append(styleOpening);
            }

            if (conf.customSurround)
            {
                sb.Append(conf.customOpening);
            }

            sb.Append(middle);
            if (conf.customSurround)
            {
                sb.Append(conf.customClosing);
            }

            if (conf.styleSurround)
            {
                sb.Append(styleClosing);
            }
        }
Ejemplo n.º 3
0
        private static void ManualLineBreakProcessing(StringBuilder sb, Config config)
        {
            var symbol        = config.manualBreakingConfig.symbol;
            var stringVersion = sb.ToString();

            if (stringVersion.IndexOf(symbol) == -1)
            {
                return;
            }

            spaces[spaces.Length - 1] = symbol;
            var splitted = stringVersion.Split(symbol);

            //If we wrap <nobr> now it will also wrap over spaces and make them unbreakable.
            //Split more according to white space characters which make it more breakable
            //in addition to the symbols. But unlike the symbols, keep those characters.
            splitList.Clear();
            splitList.AddRange(splitted);
            for (int i = 0; i < splitList.Count; i++)
            {
                var theString = splitList[i];
                if (string.IsNullOrEmpty(theString))
                {
                    splitList.RemoveAt(i);
                    i--;
                    continue;
                }

                var find = theString.IndexOfAny(spaces);
                //If we have "AAAA BBBBBB"
                //Then we have to split to [AAAA][ ][BBBBBB]
                //If more, then let that process the next round.
                //e.g. AAAA BBBBBB CCC -> [AAAA][ ][BBBBBB CCC] -> [AAAA][ ][BBBBBB][ ][CCC]
                //TODO : Make other symbols only valid at beginning or ending of line only.
                //e.g. AAAA(BBBBBB -> [AAAA][(BBBBBB]
                if (find != -1)
                {
                    bool   final = find == theString.Length - 1;
                    string left  = theString.Substring(0, find);
                    char   mid   = theString[find];
                    splitList.RemoveAt(i);
                    splitList.Insert(i, left);
                    splitList.Insert(i + 1, mid.ToString());
                    if (!final)
                    {
                        string right = theString.Substring(find + 1);
                        splitList.Insert(i + 2, right);
                    }

                    i += 1; //One more is added on the next round
                }
            }

            sb.Clear();
            var surr = new SurroundConfig
            {
                customSurround = true,
                customOpening  = "<nobr>",
                customClosing  = "</nobr>",
            };

            for (int j = 0; j < splitList.Count; j++)
            {
                UseSb(sb, surr, splitList[j]);
                if (j < splitList.Count - 1)
                {
                    sb.Append("<zwsp>");
                }
            }
        }