/// <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); }
/// <summary> /// Returns true if newRawValue does not match wildex gridValue, unless contains is like $"..." or $@"...". /// </summary> /// <param name="gridValue">A wildex string, usually from a ParamGrid control cell. Can be raw or verbatim. Can be null.</param> /// <param name="newRawValue">New raw string, not wildex. Can be null.</param> public static bool ShouldChangeGridWildex(string gridValue, string newRawValue) { if (gridValue == null) { gridValue = ""; } if (newRawValue == null) { newRawValue = ""; } if (IsVerbatim(gridValue, out _)) { if (gridValue[0] == '$') { return(false); } gridValue = gridValue.Substring(2, gridValue.Length - 3).Replace("\"\"", "\""); } AWildex x = gridValue; return(!x.Match(newRawValue)); }
/// <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); }