private static TextCaseClassification MergeClassifications(TextCaseClassification a, TextCaseClassification b) { if (a == b || b == TextCaseClassification.Unknown) { return(a); } if (a == TextCaseClassification.Unknown) { return(b); } // they are not equal and are either mixed, upper, or lower so combined they must be mixed return(TextCaseClassification.Mixed); }
/// <summary> /// Force the casing of the first character in a string to the desired case. /// </summary> /// <param name="text">The text to adjust.</param> /// <param name="textCase">The case to adjust the first letter to.</param> /// <returns>The adjusted string.</returns> protected static string ForceFirstCharCase(string text, TextCaseClassification textCase) { if (String.IsNullOrEmpty(text)) { return(text); } char firstLetter; switch (textCase) { case TextCaseClassification.Upper: { firstLetter = Char.ToUpper(text[0]); break; } case TextCaseClassification.Lower: { firstLetter = Char.ToLower(text[0]); break; } default: return(text); } if (firstLetter == text[0]) { return(text); // it was already correct, so just return it } return(String.Concat(firstLetter, text.Length > 1 ? text.Substring(1) : String.Empty)); }