TextInfo.Unix.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. using System.Diagnostics;
  5. using System.Runtime.InteropServices;
  6. using System.Security;
  7. using System.Text;
  8. namespace System.Globalization
  9. {
  10. public partial class TextInfo
  11. {
  12. private Tristate _needsTurkishCasing = Tristate.NotInitialized;
  13. private void FinishInitialization() { }
  14. // -----------------------------
  15. // ---- PAL layer ends here ----
  16. // -----------------------------
  17. private bool NeedsTurkishCasing(string localeName)
  18. {
  19. Debug.Assert(localeName != null);
  20. return CultureInfo.GetCultureInfo(localeName).CompareInfo.Compare("\u0131", "I", CompareOptions.IgnoreCase) == 0;
  21. }
  22. private bool IsInvariant { get { return _cultureName.Length == 0; } }
  23. internal unsafe void ChangeCase(char* src, int srcLen, char* dstBuffer, int dstBufferCapacity, bool bToUpper)
  24. {
  25. Debug.Assert(!GlobalizationMode.Invariant);
  26. if (IsInvariant)
  27. {
  28. Interop.Globalization.ChangeCaseInvariant(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
  29. }
  30. else
  31. {
  32. if (_needsTurkishCasing == Tristate.NotInitialized)
  33. {
  34. _needsTurkishCasing = NeedsTurkishCasing(_textInfoName) ? Tristate.True : Tristate.False;
  35. }
  36. if (_needsTurkishCasing == Tristate.True)
  37. {
  38. Interop.Globalization.ChangeCaseTurkish(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
  39. }
  40. else
  41. {
  42. Interop.Globalization.ChangeCase(src, srcLen, dstBuffer, dstBufferCapacity, bToUpper);
  43. }
  44. }
  45. }
  46. }
  47. }