/// <summary> /// Checks if the input string has error and executes the callback. (using callback) /// </summary> /// <param name="text">Input string</param> /// <param name="mode">Check Mode</param> /// <param name="callBack">Action after the callback</param> public static void CheckWithCallback(string text, TextCheckMode mode, Action <TextCheckResult> callBack = null) { string loweredText = text.ToLower(); // is not case-specific if (mode == TextCheckMode.Chat) { if (hasCensoredWords(loweredText, mode)) { callBack(TextCheckResult.Invalid_Censored); } else { callBack(TextCheckResult.Valid); } } else // TextCheckMode.Nickname { if (string.IsNullOrEmpty(loweredText)) { callBack(TextCheckResult.Invalid_Length); } else if (hasCensoredWords(loweredText, mode)) { callBack(TextCheckResult.Invalid_Censored); } else if (IsRegExError(loweredText)) { callBack(TextCheckResult.Invalid_RegEx); } else { callBack(TextCheckResult.Valid); } } }
/// <summary> /// Checks if the input string has error. (using return values) /// </summary> /// <param name="text">input string</param> /// <param name="mode">Chat or Nickname</param> /// <returns>isError</returns> public static bool Check(string text, TextCheckMode mode) { string loweredText = text.ToLower(); // is not case-specific if (mode == TextCheckMode.Chat) { if (hasCensoredWords(loweredText, mode)) { return(true); } else { return(false); } } else // TextCheckMode.Nickname { if (string.IsNullOrEmpty(loweredText)) { return(true); } else if (hasCensoredWords(loweredText, mode)) { return(true); } else if (IsRegExError(loweredText)) { return(true); } else { return(false); } } }
/// <summary> /// Censored Word Check. /// </summary> /// <param name="text"></param> /// <returns></returns> private static bool hasCensoredWords(string text, TextCheckMode mode) { bool flag = false; // The result becomes true at any single occurrences. foreach (string word in CensoredWordsTrie.Find(text)) { flag = true; } return(flag); }