diff options
Diffstat (limited to 'src/mscorlib/src/System/Globalization/CompareInfo.cs')
-rw-r--r-- | src/mscorlib/src/System/Globalization/CompareInfo.cs | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/mscorlib/src/System/Globalization/CompareInfo.cs b/src/mscorlib/src/System/Globalization/CompareInfo.cs index 285a81d906..b2c2208db7 100644 --- a/src/mscorlib/src/System/Globalization/CompareInfo.cs +++ b/src/mscorlib/src/System/Globalization/CompareInfo.cs @@ -752,7 +752,6 @@ namespace System.Globalization return IndexOfCore(source, new string(value, 1), startIndex, count, options, null); } - public unsafe virtual int IndexOf(string source, string value, int startIndex, int count, CompareOptions options) { // Validate inputs @@ -802,6 +801,53 @@ namespace System.Globalization return IndexOfCore(source, value, startIndex, count, options, null); } + // The following IndexOf overload is mainly used by String.Replace. This overload assumes the parameters are already validated + // and the caller is passing a valid matchLengthPtr pointer. + internal unsafe int IndexOf(string source, string value, int startIndex, int count, CompareOptions options, int* matchLengthPtr) + { + Debug.Assert(source != null); + Debug.Assert(value != null); + Debug.Assert(startIndex >= 0); + Debug.Assert(matchLengthPtr != null); + *matchLengthPtr = 0; + + if (source.Length == 0) + { + if (value.Length == 0) + { + return 0; + } + return -1; + } + + if (startIndex >= source.Length) + { + return -1; + } + + if (options == CompareOptions.OrdinalIgnoreCase) + { + int res = IndexOfOrdinal(source, value, startIndex, count, ignoreCase: true); + if (res >= 0) + { + *matchLengthPtr = value.Length; + } + return res; + } + + if (_invariantMode) + { + int res = IndexOfOrdinal(source, value, startIndex, count, ignoreCase: (options & (CompareOptions.IgnoreCase | CompareOptions.OrdinalIgnoreCase)) != 0); + if (res >= 0) + { + *matchLengthPtr = value.Length; + } + return res; + } + + return IndexOfCore(source, value, startIndex, count, options, matchLengthPtr); + } + internal int IndexOfOrdinal(string source, string value, int startIndex, int count, bool ignoreCase) { if (_invariantMode) |