예제 #1
0
 /// <summary>
 /// If s has *? characters, prepends "**t ".
 /// s can be null.
 /// </summary>
 public static string EscapeWildex(string s)
 {
     if (AWildex.HasWildcardChars(s))
     {
         s = "**t " + s;
     }
     return(s);
 }
예제 #2
0
 /// <summary>
 /// If s has *? characters, prepends "**t ".
 /// But if s has single * character, converts to "**r regexp" that ignores it. Because single * often is used to indicate unsaved state.
 /// If canMakeVerbatim and makes regex or s contains '\' and no newlines/controlchars, prepends @" and appends " and replaces all " with "".
 /// s can be null.
 /// </summary>
 public static string EscapeWindowName(string s, bool canMakeVerbatim)
 {
     if (s == null)
     {
         return(s);
     }
     if (AWildex.HasWildcardChars(s))
     {
         int i = s.IndexOf('*');
         if (i >= 0 && s.IndexOf('*', i + 1) < 0)
         {
             s = "**r " + ARegex.EscapeQE(s.Remove(i)) + @"\*?" + ARegex.EscapeQE(s.Substring(i + 1));
         }
         else
         {
             s = "**t " + s;
         }
     }
     if (canMakeVerbatim && s.IndexOf('\\') >= 0 && !s.RegexIsMatch(@"[\x00-\x1F\x85\x{2028}\x{2029}]"))
     {
         s = "@\"" + s.Replace("\"", "\"\"") + "\"";
     }
     return(s);
 }