12 [__DynamicallyInvokable]
15 [OptionalField(VersionAdded = 2)]
16 private string m_listSeparator;
18 [OptionalField(VersionAdded = 2)]
19 private bool m_isReadOnly;
21 [OptionalField(VersionAdded = 3)]
22 private string m_cultureName;
25 private CultureData m_cultureData;
28 private string m_textInfoName;
31 private IntPtr m_dataHandle;
34 private IntPtr m_handleOrigin;
37 private bool? m_IsAsciiCasingSameAsInvariant;
39 internal static volatile TextInfo s_Invariant;
41 [OptionalField(VersionAdded = 2)]
42 private string customCultureName;
44 [OptionalField(VersionAdded = 1)]
45 internal int m_nDataItem;
47 [OptionalField(VersionAdded = 1)]
48 internal bool m_useUserOverride;
50 [OptionalField(VersionAdded = 1)]
51 internal int m_win32LangID;
53 private const int wordSeparatorMask = 536672256;
59 if (s_Invariant ==
null)
61 s_Invariant =
new TextInfo(CultureData.Invariant);
69 public virtual int ANSICodePage => m_cultureData.IDEFAULTANSICODEPAGE;
73 public virtual int OEMCodePage => m_cultureData.IDEFAULTOEMCODEPAGE;
77 public virtual int MacCodePage => m_cultureData.IDEFAULTMACCODEPAGE;
97 [__DynamicallyInvokable]
100 [__DynamicallyInvokable]
103 return m_textInfoName;
111 [__DynamicallyInvokable]
114 [__DynamicallyInvokable]
125 [__DynamicallyInvokable]
128 [SecuritySafeCritical]
129 [__DynamicallyInvokable]
132 if (m_listSeparator ==
null)
134 m_listSeparator = m_cultureData.SLIST;
136 return m_listSeparator;
139 [__DynamicallyInvokable]
147 m_listSeparator = value;
151 private bool IsAsciiCasingSameAsInvariant
155 if (!m_IsAsciiCasingSameAsInvariant.HasValue)
159 return m_IsAsciiCasingSameAsInvariant.Value;
167 [__DynamicallyInvokable]
170 [__DynamicallyInvokable]
173 return m_cultureData.IsRightToLeft;
177 internal TextInfo(CultureData cultureData)
179 m_cultureData = cultureData;
181 m_textInfoName = m_cultureData.STEXTINFO;
182 m_dataHandle =
CompareInfo.InternalInitSortHandle(m_textInfoName, out
IntPtr handleOrigin);
183 m_handleOrigin = handleOrigin;
189 m_cultureData =
null;
190 m_cultureName =
null;
193 private void OnDeserialized()
195 if (m_cultureData !=
null)
199 if (m_cultureName ==
null)
201 if (customCultureName !=
null)
203 m_cultureName = customCultureName;
205 else if (m_win32LangID == 0)
207 m_cultureName =
"ar-SA";
211 m_cultureName = CultureInfo.GetCultureInfo(m_win32LangID).m_cultureData.CultureName;
214 m_cultureData = CultureInfo.GetCultureInfo(m_cultureName).m_cultureData;
215 m_textInfoName = m_cultureData.STEXTINFO;
216 m_dataHandle = CompareInfo.InternalInitSortHandle(m_textInfoName, out IntPtr handleOrigin);
217 m_handleOrigin = handleOrigin;
229 m_useUserOverride =
false;
230 customCultureName = m_cultureName;
231 m_win32LangID = CultureInfo.GetCultureInfo(m_cultureName).LCID;
234 internal static int GetHashCodeOrdinalIgnoreCase(
string s)
236 return GetHashCodeOrdinalIgnoreCase(s, forceRandomizedHashing:
false, 0L);
239 internal static int GetHashCodeOrdinalIgnoreCase(
string s,
bool forceRandomizedHashing,
long additionalEntropy)
241 return Invariant.GetCaseInsensitiveHashCode(s, forceRandomizedHashing, additionalEntropy);
244 [SecuritySafeCritical]
245 internal static bool TryFastFindStringOrdinalIgnoreCase(
int searchFlags,
string source,
int startIndex,
string value,
int count, ref
int foundIndex)
247 return InternalTryFindStringOrdinalIgnoreCase(searchFlags, source, count, startIndex, value, value.Length, ref foundIndex);
250 [SecuritySafeCritical]
251 internal static int CompareOrdinalIgnoreCase(
string str1,
string str2)
253 return InternalCompareStringOrdinalIgnoreCase(str1, 0, str2, 0, str1.Length, str2.Length);
256 [SecuritySafeCritical]
257 internal static int CompareOrdinalIgnoreCaseEx(
string strA,
int indexA,
string strB,
int indexB,
int lengthA,
int lengthB)
259 return InternalCompareStringOrdinalIgnoreCase(strA, indexA, strB, indexB, lengthA, lengthB);
262 internal static int IndexOfStringOrdinalIgnoreCase(
string source,
string value,
int startIndex,
int count)
264 if (source.Length == 0 && value.Length == 0)
269 if (TryFastFindStringOrdinalIgnoreCase(4194304, source, startIndex, value, count, ref foundIndex))
273 int num = startIndex + count;
274 int num2 = num - value.Length;
275 while (startIndex <= num2)
277 if (CompareOrdinalIgnoreCaseEx(source, startIndex, value, 0, value.Length, value.Length) == 0)
286 internal static int LastIndexOfStringOrdinalIgnoreCase(
string source,
string value,
int startIndex,
int count)
288 if (value.Length == 0)
293 if (TryFastFindStringOrdinalIgnoreCase(8388608, source, startIndex, value, count, ref foundIndex))
297 int num = startIndex - count + 1;
298 if (value.Length > 0)
300 startIndex -= value.Length - 1;
302 while (startIndex >= num)
304 if (CompareOrdinalIgnoreCaseEx(source, startIndex, value, 0, value.Length, value.Length) == 0)
318 object obj = MemberwiseClone();
319 ((
TextInfo)obj).SetReadOnlyState(readOnly:
false);
331 if (textInfo ==
null)
340 textInfo2.SetReadOnlyState(readOnly:
true);
344 private void VerifyWritable()
352 internal void SetReadOnlyState(
bool readOnly)
354 m_isReadOnly = readOnly;
360 [SecuritySafeCritical]
361 [__DynamicallyInvokable]
364 if (IsAscii(c) && IsAsciiCasingSameAsInvariant)
366 return ToLowerAsciiInvariant(c);
368 return InternalChangeCaseChar(m_dataHandle, m_handleOrigin, m_textInfoName, c, isToUpper:
false);
376 [SecuritySafeCritical]
377 [__DynamicallyInvokable]
384 return InternalChangeCaseString(m_dataHandle, m_handleOrigin, m_textInfoName, str, isToUpper:
false);
387 private static char ToLowerAsciiInvariant(
char c)
389 if (
'A' <= c && c <=
'Z')
391 c = (char)(c | 0x20);
399 [SecuritySafeCritical]
400 [__DynamicallyInvokable]
403 if (IsAscii(c) && IsAsciiCasingSameAsInvariant)
405 return ToUpperAsciiInvariant(c);
407 return InternalChangeCaseChar(m_dataHandle, m_handleOrigin, m_textInfoName, c, isToUpper:
true);
415 [SecuritySafeCritical]
416 [__DynamicallyInvokable]
423 return InternalChangeCaseString(m_dataHandle, m_handleOrigin, m_textInfoName, str, isToUpper:
true);
426 private static char ToUpperAsciiInvariant(
char c)
428 if (
'a' <= c && c <=
'z')
435 private static bool IsAscii(
char c)
444 [__DynamicallyInvokable]
448 if (textInfo !=
null)
457 [__DynamicallyInvokable]
465 [__DynamicallyInvokable]
468 return "TextInfo - " + m_cultureData.CultureName;
489 for (num = 0; num < str.Length; num++)
492 if (
char.CheckLetter(unicodeCategory))
494 num = AddTitlecaseLetter(ref result, ref str, num, charLength) + 1;
497 while (num < str.Length)
499 unicodeCategory =
CharUnicodeInfo.InternalGetUnicodeCategory(str, num, out charLength);
500 if (IsLetterCategory(unicodeCategory))
508 else if (str[num] ==
'\'')
517 result.Append(text, num2, num - num2);
521 result.Append(str, num2, num - num2);
528 if (IsWordSeparator(unicodeCategory))
535 int num3 = num - num2;
544 result.Append(text, num2, num3);
548 result.Append(str, num2, num3);
551 if (num < str.Length)
553 num = AddNonLetter(ref result, ref str, num, charLength);
558 num = AddNonLetter(ref result, ref str, num, charLength);
564 private static int AddNonLetter(ref
StringBuilder result, ref
string input,
int inputIndex,
int charLen)
568 result.Append(input[inputIndex++]);
569 result.Append(input[inputIndex]);
573 result.Append(input[inputIndex]);
578 private int AddTitlecaseLetter(ref
StringBuilder result, ref
string input,
int inputIndex,
int charLen)
582 result.Append(
ToUpper(input.Substring(inputIndex, charLen)));
587 switch (input[inputIndex])
610 result.Append(
ToUpper(input[inputIndex]));
619 return (0x1FFCF800 & (1 << (
int)category)) != 0;
638 [SecuritySafeCritical]
639 internal int GetCaseInsensitiveHashCode(
string str)
641 return GetCaseInsensitiveHashCode(str, forceRandomizedHashing:
false, 0L);
644 [SecuritySafeCritical]
645 internal int GetCaseInsensitiveHashCode(
string str,
bool forceRandomizedHashing,
long additionalEntropy)
649 throw new ArgumentNullException(
"str");
651 return InternalGetCaseInsHash(m_dataHandle, m_handleOrigin, m_textInfoName, str, forceRandomizedHashing, additionalEntropy);
656 private static extern char InternalChangeCaseChar(IntPtr handle, IntPtr handleOrigin,
string localeName,
char ch,
bool isToUpper);
660 private static extern string InternalChangeCaseString(IntPtr handle, IntPtr handleOrigin,
string localeName,
string str,
bool isToUpper);
664 private static extern int InternalGetCaseInsHash(IntPtr handle, IntPtr handleOrigin,
string localeName,
string str,
bool forceRandomizedHashing,
long additionalEntropy);
668 [SuppressUnmanagedCodeSecurity]
669 private static extern int InternalCompareStringOrdinalIgnoreCase(
string string1,
int index1,
string string2,
int index2,
int length1,
int length2);
673 [SuppressUnmanagedCodeSecurity]
675 private static extern bool InternalTryFindStringOrdinalIgnoreCase(
int searchFlags,
string source,
int sourceCount,
int startIndex,
string target,
int targetCount, ref
int foundIndex);
string ToTitleCase(string str)
Converts the specified string to title case (except for words that are entirely in uppercase,...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
bool IsRightToLeft
Gets a value indicating whether the current T:System.Globalization.TextInfo object represents a writi...
override bool Equals(object obj)
Determines whether the specified object represents the same writing system as the current T:System....
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
virtual CompareInfo? CompareInfo
Gets the T:System.Globalization.CompareInfo that defines how to compare strings for the culture.
virtual string ToLower(string str)
Converts the specified string to lowercase.
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
virtual int MacCodePage
Gets the Macintosh code page used by the writing system represented by the current T:System....
Describes the source and destination of a given serialized stream, and provides an additional caller-...
virtual string ListSeparator
Gets or sets the string that separates items in a list.
virtual string ToUpper(string str)
Converts the specified string to uppercase.
static CultureInfo GetCultureInfo(int culture)
Retrieves a cached, read-only instance of a culture by using the specified culture identifier.
static TextInfo ReadOnly(TextInfo textInfo)
Returns a read-only version of the specified T:System.Globalization.TextInfo object.
Provides information about, and means to manipulate, the current environment and platform....
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
void OnDeserialization(object sender)
Runs when the entire object graph has been deserialized.
virtual int Compare(string string1, string string2)
Compares two strings.
virtual object Clone()
Creates a new object that is a copy of the current T:System.Globalization.TextInfo object.
Implements a set of methods for culture-sensitive string comparisons.
A platform-specific type that is used to represent a pointer or a handle.
virtual char ToLower(char c)
Converts the specified character to lowercase.
Supports cloning, which creates a new instance of a class with the same value as an existing instance...
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
override int GetHashCode()
Serves as a hash function for the current T:System.Globalization.TextInfo, suitable for hashing algor...
virtual int ANSICodePage
Gets the American National Standards Institute (ANSI) code page used by the writing system represente...
Retrieves information about a Unicode character. This class cannot be inherited.
virtual int OEMCodePage
Gets the original equipment manufacturer (OEM) code page used by the writing system represented by th...
UnicodeCategory
Defines the Unicode category of a character.
virtual int EBCDICCodePage
Gets the Extended Binary Coded Decimal Interchange Code (EBCDIC) code page used by the writing system...
int LCID
Gets the culture identifier for the culture associated with the current T:System.Globalization....
Specifies that the class can be serialized.
string CultureName
Gets the name of the culture associated with the current T:System.Globalization.TextInfo object.
The exception that is thrown when a method call is invalid for the object's current state.
virtual int LCID
Gets the culture identifier for the current T:System.Globalization.CultureInfo.
Defines text properties and behaviors, such as casing, that are specific to a writing system.
Provides information about a specific culture (called a locale for unmanaged code development)....
CompareOptions
Defines the string comparison options to use with T:System.Globalization.CompareInfo.
override string ToString()
Returns a string that represents the current T:System.Globalization.TextInfo.
virtual char ToUpper(char c)
Converts the specified character to uppercase.
bool IsReadOnly
Gets a value indicating whether the current T:System.Globalization.TextInfo object is read-only.