Advertisement
ivandrofly

AI: Refact

Jul 19th, 2023 (edited)
1,163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. ============================== old
  2. if (lines.Count == 1 && text != oldText && Utilities.GetNumberOfLines(oldText) == 2)
  3.    
  4.  
  5.  
  6. ============================== new
  7. private static bool ContainsPunctuationFollowedByNewLine(string text)
  8. {
  9.     string[] punctuations = new[] { ".", ".</i>", "!", "!</i>", "?", "?</i>" };
  10.  
  11.     return punctuations.Any(punct => oldText.Contains(punct + Environment.NewLine));
  12. }
  13.  
  14. public void SomeMethod()
  15. {
  16.     if (lines.Count == 1 && text != oldText && Utilities.GetNumberOfLines(oldText) == 2)
  17.     {
  18.         string[] startPatterns = new[] { "-", "<i>-"};
  19.         string[] lineBreakPatterns = new[] { Environment.NewLine + "-", Environment.NewLine + "<i>-" };
  20.  
  21.         if ((startPatterns.Any(pattern => oldText.StartsWith(pattern, StringComparison.Ordinal)) ||
  22.              lineBreakPatterns.Any(pattern => oldText.Contains(pattern))) &&
  23.             ContainsPunctuationFollowedByNewLine(oldText))
  24.         {
  25.             if (text.StartsWith("<i>-", StringComparison.Ordinal))
  26.             {
  27.                 text = "<i>" + text.Remove(0, 4).TrimStart();
  28.             }
  29.             else
  30.             {
  31.                 text = text.TrimStart('-').TrimStart();
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement