summaryrefslogtreecommitdiff
path: root/src/mscorlib/src/System/Globalization/TextInfo.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/mscorlib/src/System/Globalization/TextInfo.cs')
-rw-r--r--src/mscorlib/src/System/Globalization/TextInfo.cs77
1 files changed, 23 insertions, 54 deletions
diff --git a/src/mscorlib/src/System/Globalization/TextInfo.cs b/src/mscorlib/src/System/Globalization/TextInfo.cs
index 9b84486f4e..c8108e4922 100644
--- a/src/mscorlib/src/System/Globalization/TextInfo.cs
+++ b/src/mscorlib/src/System/Globalization/TextInfo.cs
@@ -24,6 +24,7 @@ namespace System.Globalization {
using System.Runtime.Serialization;
using System.Runtime.Versioning;
using System.Security.Permissions;
+ using System.Diagnostics;
using System.Diagnostics.Contracts;
@@ -106,11 +107,6 @@ namespace System.Globalization {
this.m_cultureData = cultureData;
this.m_cultureName = this.m_cultureData.CultureName;
this.m_textInfoName = this.m_cultureData.STEXTINFO;
-#if !FEATURE_CORECLR
- IntPtr handleOrigin;
- this.m_dataHandle = CompareInfo.InternalInitSortHandle(m_textInfoName, out handleOrigin);
- this.m_handleOrigin = handleOrigin;
-#endif
}
////////////////////////////////////////////////////////////////////////
@@ -179,30 +175,18 @@ namespace System.Globalization {
// Get the text info name belonging to that culture
this.m_cultureData = CultureInfo.GetCultureInfo(m_cultureName).m_cultureData;
this.m_textInfoName = this.m_cultureData.STEXTINFO;
-#if !FEATURE_CORECLR
- IntPtr handleOrigin;
- this.m_dataHandle = CompareInfo.InternalInitSortHandle(m_textInfoName, out handleOrigin);
- this.m_handleOrigin = handleOrigin;
-#endif
- }
+ }
}
-
[OnDeserialized]
private void OnDeserialized(StreamingContext ctx)
{
OnDeserialized();
- }
-
+ }
+
[OnSerializing]
private void OnSerializing(StreamingContext ctx)
- {
-#if !FEATURE_CORECLR
- // Initialize the fields Whidbey expects:
- // Whidbey expected this, so set it, but the value doesn't matter much
- this.m_useUserOverride = false;
-#endif // FEATURE_CORECLR
-
+ {
// Relabel our name since Whidbey expects it to be called customCultureName
this.customCultureName = this.m_cultureName;
@@ -229,7 +213,6 @@ namespace System.Globalization {
return (Invariant.GetCaseInsensitiveHashCode(s, forceRandomizedHashing, additionalEntropy));
}
- [System.Security.SecuritySafeCritical]
internal static unsafe bool TryFastFindStringOrdinalIgnoreCase(int searchFlags, String source, int startIndex, String value, int count, ref int foundIndex)
{
return InternalTryFindStringOrdinalIgnoreCase(searchFlags, source, count, startIndex, value, value.Length, ref foundIndex);
@@ -237,7 +220,6 @@ namespace System.Globalization {
// This function doesn't check arguments. Please do check in the caller.
// The underlying unmanaged code will assert the sanity of arguments.
- [System.Security.SecuritySafeCritical] // auto-generated
internal static unsafe int CompareOrdinalIgnoreCase(String str1, String str2)
{
// Compare the whole string and ignore case.
@@ -246,19 +228,18 @@ namespace System.Globalization {
// This function doesn't check arguments. Please do check in the caller.
// The underlying unmanaged code will assert the sanity of arguments.
- [System.Security.SecuritySafeCritical] // auto-generated
internal static unsafe int CompareOrdinalIgnoreCaseEx(String strA, int indexA, String strB, int indexB, int lengthA, int lengthB )
{
- Contract.Assert(strA.Length >= indexA + lengthA, "[TextInfo.CompareOrdinalIgnoreCaseEx] Caller should've validated strA.Length >= indexA + lengthA");
- Contract.Assert(strB.Length >= indexB + lengthB, "[TextInfo.CompareOrdinalIgnoreCaseEx] Caller should've validated strB.Length >= indexB + lengthB");
+ Debug.Assert(strA.Length >= indexA + lengthA, "[TextInfo.CompareOrdinalIgnoreCaseEx] Caller should've validated strA.Length >= indexA + lengthA");
+ Debug.Assert(strB.Length >= indexB + lengthB, "[TextInfo.CompareOrdinalIgnoreCaseEx] Caller should've validated strB.Length >= indexB + lengthB");
return InternalCompareStringOrdinalIgnoreCase(strA, indexA, strB, indexB, lengthA, lengthB);
}
internal static int IndexOfStringOrdinalIgnoreCase(String source, String value, int startIndex, int count)
{
- Contract.Assert(source != null, "[TextInfo.IndexOfStringOrdinalIgnoreCase] Caller should've validated source != null");
- Contract.Assert(value != null, "[TextInfo.IndexOfStringOrdinalIgnoreCase] Caller should've validated value != null");
- Contract.Assert(startIndex + count <= source.Length, "[TextInfo.IndexOfStringOrdinalIgnoreCase] Caller should've validated startIndex + count <= source.Length");
+ Debug.Assert(source != null, "[TextInfo.IndexOfStringOrdinalIgnoreCase] Caller should've validated source != null");
+ Debug.Assert(value != null, "[TextInfo.IndexOfStringOrdinalIgnoreCase] Caller should've validated value != null");
+ Debug.Assert(startIndex + count <= source.Length, "[TextInfo.IndexOfStringOrdinalIgnoreCase] Caller should've validated startIndex + count <= source.Length");
// We return 0 if both inputs are empty strings
if (source.Length == 0 && value.Length == 0)
@@ -285,7 +266,7 @@ namespace System.Globalization {
for (; startIndex <= maxStartIndex; startIndex++)
{
// We should always have the same or more characters left to search than our actual pattern
- Contract.Assert(end - startIndex >= value.Length);
+ Debug.Assert(end - startIndex >= value.Length);
// since this is an ordinal comparison, we can assume that the lengths must match
if (CompareOrdinalIgnoreCaseEx(source, startIndex, value, 0, value.Length, value.Length) == 0)
{
@@ -299,10 +280,10 @@ namespace System.Globalization {
internal static int LastIndexOfStringOrdinalIgnoreCase(String source, String value, int startIndex, int count)
{
- Contract.Assert(source != null, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated source != null");
- Contract.Assert(value != null, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated value != null");
- Contract.Assert(startIndex - count+1 >= 0, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated startIndex - count+1 >= 0");
- Contract.Assert(startIndex <= source.Length, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated startIndex <= source.Length");
+ Debug.Assert(source != null, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated source != null");
+ Debug.Assert(value != null, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated value != null");
+ Debug.Assert(startIndex - count+1 >= 0, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated startIndex - count+1 >= 0");
+ Debug.Assert(startIndex <= source.Length, "[TextInfo.LastIndexOfStringOrdinalIgnoreCase] Caller should've validated startIndex <= source.Length");
// If value is Empty, the return value is startIndex
if (value.Length == 0)
@@ -462,7 +443,7 @@ namespace System.Globalization {
[System.Runtime.InteropServices.ComVisible(false)]
public static TextInfo ReadOnly(TextInfo textInfo)
{
- if (textInfo == null) { throw new ArgumentNullException("textInfo"); }
+ if (textInfo == null) { throw new ArgumentNullException(nameof(textInfo)); }
Contract.EndContractBlock();
if (textInfo.IsReadOnly) { return (textInfo); }
@@ -498,7 +479,6 @@ namespace System.Globalization {
public virtual String ListSeparator
{
- [System.Security.SecuritySafeCritical] // auto-generated
get
{
if (m_listSeparator == null) {
@@ -512,7 +492,7 @@ namespace System.Globalization {
{
if (value == null)
{
- throw new ArgumentNullException("value", Environment.GetResourceString("ArgumentNull_String"));
+ throw new ArgumentNullException(nameof(value), Environment.GetResourceString("ArgumentNull_String"));
}
Contract.EndContractBlock();
VerifyWritable();
@@ -529,7 +509,6 @@ namespace System.Globalization {
//
////////////////////////////////////////////////////////////////////////
- [System.Security.SecuritySafeCritical] // auto-generated
public unsafe virtual char ToLower(char c)
{
if(IsAscii(c) && IsAsciiCasingSameAsInvariant)
@@ -539,10 +518,9 @@ namespace System.Globalization {
return (InternalChangeCaseChar(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, c, false));
}
- [System.Security.SecuritySafeCritical] // auto-generated
public unsafe virtual String ToLower(String str)
{
- if (str == null) { throw new ArgumentNullException("str"); }
+ if (str == null) { throw new ArgumentNullException(nameof(str)); }
Contract.EndContractBlock();
return InternalChangeCaseString(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, false);
@@ -567,7 +545,6 @@ namespace System.Globalization {
//
////////////////////////////////////////////////////////////////////////
- [System.Security.SecuritySafeCritical] // auto-generated
public unsafe virtual char ToUpper(char c)
{
if (IsAscii(c) && IsAsciiCasingSameAsInvariant)
@@ -578,10 +555,9 @@ namespace System.Globalization {
}
- [System.Security.SecuritySafeCritical] // auto-generated
public unsafe virtual String ToUpper(String str)
{
- if (str == null) { throw new ArgumentNullException("str"); }
+ if (str == null) { throw new ArgumentNullException(nameof(str)); }
Contract.EndContractBlock();
return InternalChangeCaseString(this.m_dataHandle, this.m_handleOrigin, this.m_textInfoName, str, true);
}
@@ -698,7 +674,7 @@ namespace System.Globalization {
{
if (str == null)
{
- throw new ArgumentNullException("str");
+ throw new ArgumentNullException(nameof(str));
}
Contract.EndContractBlock();
if (str.Length == 0)
@@ -809,7 +785,7 @@ namespace System.Globalization {
private static int AddNonLetter(ref StringBuilder result, ref String input, int inputIndex, int charLen)
{
- Contract.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddNonLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
+ Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddNonLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
if (charLen == 2)
{
// Surrogate pair
@@ -826,7 +802,7 @@ namespace System.Globalization {
private int AddTitlecaseLetter(ref StringBuilder result, ref String input, int inputIndex, int charLen)
{
- Contract.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddTitlecaseLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
+ Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddTitlecaseLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
// for surrogate pairs do a simple ToUpper operation on the substring
if (charLen == 2)
@@ -947,19 +923,17 @@ namespace System.Globalization {
// is not null before calling this. Currenlty, CaseInsensitiveHashCodeProvider
// does that.
//
- [System.Security.SecuritySafeCritical] // auto-generated
internal unsafe int GetCaseInsensitiveHashCode(String str)
{
return GetCaseInsensitiveHashCode(str, false, 0);
}
- [System.Security.SecuritySafeCritical] // auto-generated
internal unsafe int GetCaseInsensitiveHashCode(String str, bool forceRandomizedHashing, long additionalEntropy)
{
// Validate inputs
if (str==null)
{
- throw new ArgumentNullException("str");
+ throw new ArgumentNullException(nameof(str));
}
Contract.EndContractBlock();
@@ -968,23 +942,19 @@ namespace System.Globalization {
}
// Change case (ToUpper/ToLower) -- COMNlsInfo::InternalChangeCaseChar
- [System.Security.SecurityCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static unsafe extern char InternalChangeCaseChar(IntPtr handle, IntPtr handleOrigin, String localeName, char ch, bool isToUpper);
// Change case (ToUpper/ToLower) -- COMNlsInfo::InternalChangeCaseString
- [System.Security.SecurityCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static unsafe extern String InternalChangeCaseString(IntPtr handle, IntPtr handleOrigin, String localeName, String str, bool isToUpper);
// Get case insensitive hash -- ComNlsInfo::InternalGetCaseInsHash
- [System.Security.SecurityCritical] // auto-generated
[MethodImplAttribute(MethodImplOptions.InternalCall)]
private static unsafe extern int InternalGetCaseInsHash(IntPtr handle, IntPtr handleOrigin, String localeName, String str, bool forceRandomizedHashing, long additionalEntropy);
// Call ::CompareStringOrdinal -- ComNlsInfo::InternalCompareStringOrdinalIgnoreCase
// Start at indexes and compare for length characters (or remainder of string if length == -1)
- [System.Security.SecurityCritical] // auto-generated
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
private static unsafe extern int InternalCompareStringOrdinalIgnoreCase(String string1, int index1, String string2, int index2, int length1, int length2);
@@ -992,7 +962,6 @@ namespace System.Globalization {
// ComNlsInfo::InternalTryFindStringOrdinalIgnoreCase attempts a faster IndexOf/LastIndexOf OrdinalIgnoreCase using a kernel function.
// Returns true if FindStringOrdinal was handled, with foundIndex set to the target's index into the source
// Returns false when FindStringOrdinal wasn't handled
- [System.Security.SecurityCritical] // auto-generated
[DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)]
[SuppressUnmanagedCodeSecurity]
[return: MarshalAs(UnmanagedType.Bool)]