/// <summary>Returns true if caseFoldedChars matches the chars in the stream /// beginning with the char pointed to by the Iterator. /// The chars in the stream are case-folded before they are matched, /// while the chars in the string argument are assumed to already be case-folded. /// If the chars do not match or if there are not enough chars remaining in the stream, false is returned. /// If caseFoldedChars is empty, true is returned.</summary> /// <exception cref="NullReferenceException">caseFoldedChars is null.</exception> public bool MatchCaseFolded(string caseFoldedChars) { if (unchecked ((uint)Idx) + (uint)caseFoldedChars.Length <= (uint)Stream.IndexEnd) { char[] cftable = CaseFoldTable.FoldedChars; if (cftable == null) { cftable = CaseFoldTable.Initialize(); } var s = Stream.String; for (int i = 0; i < caseFoldedChars.Length; ++i) { if (caseFoldedChars[i] != cftable[s[Idx + i]]) { goto ReturnFalse; } } return(true); } if (caseFoldedChars.Length == 0) { return(true); } ReturnFalse: return(false); }
/// <summary>Returns a case-folded copy of the string argument. All chars are mapped /// using the (non-Turkic) 1-to-1 case folding mappings (v. 5.1) for Unicode code /// points in the Basic Multilingual Plane, i.e. code points below 0x10000. /// If the argument is null, null is returned.</summary> static public string FoldCase(string str) { char[] cftable = CaseFoldTable.FoldedChars; if (cftable == null) { cftable = CaseFoldTable.Initialize(); } if (str != null) { for (int i = 0; i < str.Length; ++i) { char c = str[i]; char cfc = cftable[c]; if (c != cfc) { StringBuilder sb = new StringBuilder(str); sb[i++] = cfc; for (; i < str.Length; ++i) { c = str[i]; cfc = cftable[c]; if (c != cfc) { sb[i] = cfc; } } return(sb.ToString()); } } } return(str); }