know how to resolve custom locle names to sort ids so we have to have already resolved this.
*/
- private String _cultureName; // Name of the culture that created this text info
- private CultureData _cultureData; // Data record for the culture that made us, not for this textinfo
- private String _textInfoName; // Name of the text info we're using (ie: _cultureData.STEXTINFO)
+ private readonly string _cultureName; // Name of the culture that created this text info
+ private readonly CultureData _cultureData; // Data record for the culture that made us, not for this textinfo
+ private readonly string _textInfoName; // Name of the text info we're using (ie: _cultureData.STEXTINFO)
+
private Tristate _isAsciiCasingSameAsInvariant = Tristate.NotInitialized;
// _invariantMode is defined for the perf reason as accessing the instance field is faster than access the static property GlobalizationMode.Invariant
//// Implements CultureInfo.TextInfo.
////
//////////////////////////////////////////////////////////////////////////
- internal unsafe TextInfo(CultureData cultureData)
+ internal TextInfo(CultureData cultureData)
{
// This is our primary data source, we don't need most of the rest of this
_cultureData = cultureData;
_cultureName = _cultureData.CultureName;
_textInfoName = _cultureData.STEXTINFO;
- FinishInitialization(_textInfoName);
+
+ FinishInitialization();
}
void IDeserializationCallback.OnDeserialization(Object sender)
// Internal ordinal comparison functions
//
- internal static int GetHashCodeOrdinalIgnoreCase(String s)
+ internal static int GetHashCodeOrdinalIgnoreCase(string s)
{
// This is the same as an case insensitive hash for Invariant
// (not necessarily true for sorting, but OK for casing & then we apply normal hash code rules)
- return (Invariant.GetCaseInsensitiveHashCode(s));
+ return Invariant.GetCaseInsensitiveHashCode(s);
}
// Currently we don't have native functions to do this, so we do it the hard way
- internal static int IndexOfStringOrdinalIgnoreCase(String source, String value, int startIndex, int count)
+ internal static int IndexOfStringOrdinalIgnoreCase(string source, string value, int startIndex, int count)
{
if (count > source.Length || count < 0 || startIndex < 0 || startIndex > source.Length - count)
{
}
// Currently we don't have native functions to do this, so we do it the hard way
- internal static int LastIndexOfStringOrdinalIgnoreCase(String source, String value, int startIndex, int count)
+ internal static int LastIndexOfStringOrdinalIgnoreCase(string source, string value, int startIndex, int count)
{
if (count > source.Length || count < 0 || startIndex < 0 || startIndex > source.Length - 1 || (startIndex - count + 1 < 0))
{
return CultureInfo.InvariantCulture.CompareInfo.LastIndexOfOrdinal(source, value, startIndex, count, ignoreCase: true);
}
- ////////////////////////////////////////////////////////////////////////
- //
- // CodePage
- //
- // Returns the number of the code page used by this writing system.
- // The type parameter can be any of the following values:
- // ANSICodePage
- // OEMCodePage
- // MACCodePage
- //
- ////////////////////////////////////////////////////////////////////////
+ public virtual int ANSICodePage => _cultureData.IDEFAULTANSICODEPAGE;
+ public virtual int OEMCodePage => _cultureData.IDEFAULTOEMCODEPAGE;
- public virtual int ANSICodePage
- {
- get
- {
- return (_cultureData.IDEFAULTANSICODEPAGE);
- }
- }
-
-
- public virtual int OEMCodePage
- {
- get
- {
- return (_cultureData.IDEFAULTOEMCODEPAGE);
- }
- }
+ public virtual int MacCodePage => _cultureData.IDEFAULTMACCODEPAGE;
+ public virtual int EBCDICCodePage => _cultureData.IDEFAULTEBCDICCODEPAGE;
- public virtual int MacCodePage
- {
- get
- {
- return (_cultureData.IDEFAULTMACCODEPAGE);
- }
- }
+ // Just use the LCID from our text info name
+ public int LCID => CultureInfo.GetCultureInfo(_textInfoName).LCID;
+ public string CultureName => _textInfoName;
- public virtual int EBCDICCodePage
- {
- get
- {
- return (_cultureData.IDEFAULTEBCDICCODEPAGE);
- }
- }
-
- public int LCID
- {
- get
- {
- // Just use the LCID from our text info name
- return CultureInfo.GetCultureInfo(_textInfoName).LCID;
- }
- }
-
- //////////////////////////////////////////////////////////////////////////
- ////
- //// CultureName
- ////
- //// The name of the culture associated with the current TextInfo.
- ////
- //////////////////////////////////////////////////////////////////////////
- public string CultureName
- {
- get
- {
- return _textInfoName;
- }
- }
-
- ////////////////////////////////////////////////////////////////////////
- //
- // IsReadOnly
- //
- // Detect if the object is readonly.
- //
- ////////////////////////////////////////////////////////////////////////
- public bool IsReadOnly
- {
- get { return (_isReadOnly); }
- }
+ public bool IsReadOnly => _isReadOnly;
//////////////////////////////////////////////////////////////////////////
////
{
object o = MemberwiseClone();
((TextInfo)o).SetReadOnlyState(false);
- return (o);
+ return o;
}
////////////////////////////////////////////////////////////////////////
public static TextInfo ReadOnly(TextInfo textInfo)
{
if (textInfo == null) { throw new ArgumentNullException(nameof(textInfo)); }
- if (textInfo.IsReadOnly) { return (textInfo); }
+ if (textInfo.IsReadOnly) { return textInfo; }
TextInfo clonedTextInfo = (TextInfo)(textInfo.MemberwiseClone());
clonedTextInfo.SetReadOnlyState(true);
- return (clonedTextInfo);
+ return clonedTextInfo;
}
private void VerifyWritable()
// Returns the string used to separate items in a list.
//
////////////////////////////////////////////////////////////////////////
- public virtual String ListSeparator
+ public virtual string ListSeparator
{
get
{
{
_listSeparator = _cultureData.SLIST;
}
- return (_listSeparator);
+ return _listSeparator;
}
set
return ToLowerAsciiInvariant(c);
}
- return (ChangeCase(c, toUpper: false));
+ return ChangeCase(c, toUpper: false);
}
- public unsafe virtual String ToLower(String str)
+ public unsafe virtual string ToLower(string str)
{
if (str == null) { throw new ArgumentNullException(nameof(str)); }
pResult[j] = pSource[j];
}
- pResult[i] = (Char)(pSource[i] | 0x20);
+ pResult[i] = (char)(pSource[i] | 0x20);
i++;
while (i < s.Length)
}
}
- private static Char ToLowerAsciiInvariant(Char c)
+ private static char ToLowerAsciiInvariant(char c)
{
if ((uint)(c - 'A') <= (uint)('Z' - 'A'))
{
- c = (Char)(c | 0x20);
+ c = (char)(c | 0x20);
}
return c;
}
return ToUpperAsciiInvariant(c);
}
- return (ChangeCase(c, toUpper: true));
+ return ChangeCase(c, toUpper: true);
}
- public unsafe virtual String ToUpper(String str)
+ public unsafe virtual string ToUpper(string str)
{
if (str == null) { throw new ArgumentNullException(nameof(str)); }
return ChangeCase(str, toUpper: true);
}
- internal static Char ToUpperAsciiInvariant(Char c)
+ internal static char ToUpperAsciiInvariant(char c)
{
if ((uint)(c - 'a') <= (uint)('z' - 'a'))
{
- c = (Char)(c & ~0x20);
+ c = (char)(c & ~0x20);
}
return c;
}
- private static bool IsAscii(Char c)
+ private static bool IsAscii(char c)
{
return c < 0x80;
}
//
// Returns true if the dominant direction of text and UI such as the relative position of buttons and scroll bars
//
- public bool IsRightToLeft
- {
- get
- {
- return _cultureData.IsRightToLeft;
- }
- }
+ public bool IsRightToLeft => _cultureData.IsRightToLeft;
////////////////////////////////////////////////////////////////////////
//
if (that != null)
{
- return this.CultureName.Equals(that.CultureName);
+ return CultureName.Equals(that.CultureName);
}
- return (false);
+ return false;
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
public override int GetHashCode()
{
- return (this.CultureName.GetHashCode());
+ return CultureName.GetHashCode();
}
////////////////////////////////////////////////////////////////////////
// TextInfo.
//
////////////////////////////////////////////////////////////////////////
- public override String ToString()
+ public override string ToString()
{
- return ("TextInfo - " + _cultureData.CultureName);
+ return "TextInfo - " + _cultureData.CultureName;
}
//
// influence which letter or letters of a "word" are uppercased when titlecasing strings. For example
// "l'arbre" is considered two words in French, whereas "can't" is considered one word in English.
//
- public unsafe String ToTitleCase(String str)
+ public unsafe string ToTitleCase(string str)
{
if (str == null)
{
}
if (str.Length == 0)
{
- return (str);
+ return str;
}
StringBuilder result = new StringBuilder();
int charLen;
charType = CharUnicodeInfo.InternalGetUnicodeCategory(str, i, out charLen);
- if (Char.CheckLetter(charType))
+ if (char.CheckLetter(charType))
{
// Special case to check for Dutch specific titlecasing with "IJ" characters
// at the beginning of a word
{
if (lowercaseData == null)
{
- lowercaseData = this.ToLower(str);
+ lowercaseData = ToLower(str);
}
result.Append(lowercaseData, lowercaseStart, i - lowercaseStart);
}
{
if (lowercaseData == null)
{
- lowercaseData = this.ToLower(str);
+ lowercaseData = ToLower(str);
}
result.Append(lowercaseData, lowercaseStart, count);
}
i = AddNonLetter(ref result, ref str, i, charLen);
}
}
- return (result.ToString());
+ return result.ToString();
}
- private static int AddNonLetter(ref StringBuilder result, ref String input, int inputIndex, int charLen)
+ private static int AddNonLetter(ref StringBuilder result, ref string input, int inputIndex, int charLen)
{
Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddNonLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
if (charLen == 2)
return inputIndex;
}
- private int AddTitlecaseLetter(ref StringBuilder result, ref String input, int inputIndex, int charLen)
+ private int AddTitlecaseLetter(ref StringBuilder result, ref string input, int inputIndex, int charLen)
{
Debug.Assert(charLen == 1 || charLen == 2, "[TextInfo.AddTitlecaseLetter] CharUnicodeInfo.InternalGetUnicodeCategory returned an unexpected charLen!");
//
// Get case-insensitive hash code for the specified string.
//
- internal unsafe int GetCaseInsensitiveHashCode(String str)
+ internal unsafe int GetCaseInsensitiveHashCode(string str)
{
// Validate inputs
if (str == null)
return (int)hash;
}
- private unsafe int GetCaseInsensitiveHashCodeSlow(String str)
+ private unsafe int GetCaseInsensitiveHashCodeSlow(string str)
{
Debug.Assert(str != null);