Advertisement
ivandrofly

SubtitileEdit

Feb 15th, 2015
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1.         public static string FixEllipsesStartHelper(string text)
  2.         {
  3.             if (string.IsNullOrEmpty(text) || text.Trim().Length < 4 || !(text.Contains("..", StringComparison.Ordinal) || text.Contains(". .", StringComparison.Ordinal)))
  4.                 return text;
  5.  
  6.             const string preChars = ">-\"”“'‘`´¶#♪♫¿¡—";
  7.             var pre = string.Empty;
  8.             text = text.TrimStart();
  9.  
  10.             for (int i = 0; i < 3; i++)
  11.             {
  12.                 while (text.Length > 1 && preChars.Contains(text[0]))
  13.                 {
  14.                     pre += text[0];
  15.                     text = text.Substring(1).TrimStart();
  16.                 }
  17.                 //<font color="#000000">
  18.                 if (text.StartsWith("<font", StringComparison.OrdinalIgnoreCase) && text.IndexOf('>', 5) >= 5)
  19.                 {
  20.                     var idx = text.IndexOf('>', 5);
  21.                     if (idx >= 5)
  22.                     {
  23.                         pre += text.Substring(0, text.IndexOf('>') + 1);
  24.                         text = text.Substring(idx + 1).TrimStart();
  25.                     }
  26.                 }
  27.                 // <b>, <u>, <i>
  28.                 while (text.Length > 3 && text[0] == '<' && text[2] == '>')
  29.                 {
  30.                     pre += "<" + text[1] + ">";
  31.                     text = text.Substring(3).TrimStart();
  32.                 }
  33.                 text = text.TrimStart('.', ' ');
  34.             }
  35.             text = text.Replace("  ", " ");
  36.             // WOMAN 2: <i>...24 hours a day at BabyC.</i>
  37.             var index = text.IndexOf(':');
  38.             if (index >= 1 && !Utilities.IsBetweenNumbers(text, index) &&
  39.                 (text.Contains("..", StringComparison.Ordinal)|| text.Contains(". .", StringComparison.Ordinal)))
  40.             {
  41.                 pre += text.Substring(0, index + 1);
  42.                 text = text.Substring(index + 1).TrimStart();
  43.                 text = FixEllipsesStartHelper(text);
  44.             }
  45.             if (pre.Length > 0 && !" >\"".Contains(pre[pre.Length - 1]))
  46.                 pre += " ";
  47.             return pre + text;
  48.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement