TextInfo.Windows.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. namespace System.Globalization
  6. {
  7. public partial class TextInfo
  8. {
  9. private unsafe void FinishInitialization()
  10. {
  11. _sortHandle = CompareInfo.GetSortHandle(_textInfoName);
  12. }
  13. private unsafe void ChangeCase(char* pSource, int pSourceLen, char* pResult, int pResultLen, bool toUpper)
  14. {
  15. Debug.Assert(!GlobalizationMode.Invariant);
  16. Debug.Assert(pSource != null);
  17. Debug.Assert(pResult != null);
  18. Debug.Assert(pSourceLen >= 0);
  19. Debug.Assert(pResultLen >= 0);
  20. Debug.Assert(pSourceLen <= pResultLen);
  21. // Check for Invariant to avoid A/V in LCMapStringEx
  22. uint linguisticCasing = IsInvariantLocale(_textInfoName) ? 0 : LCMAP_LINGUISTIC_CASING;
  23. int ret = Interop.Kernel32.LCMapStringEx(_sortHandle != IntPtr.Zero ? null : _textInfoName,
  24. linguisticCasing | (toUpper ? LCMAP_UPPERCASE : LCMAP_LOWERCASE),
  25. pSource,
  26. pSourceLen,
  27. pResult,
  28. pSourceLen,
  29. null,
  30. null,
  31. _sortHandle);
  32. if (ret == 0)
  33. {
  34. throw new InvalidOperationException(SR.InvalidOperation_ReadOnly);
  35. }
  36. Debug.Assert(ret == pSourceLen, "Expected getting the same length of the original string");
  37. }
  38. // PAL Ends here
  39. private IntPtr _sortHandle;
  40. private const uint LCMAP_LINGUISTIC_CASING = 0x01000000;
  41. private const uint LCMAP_LOWERCASE = 0x00000100;
  42. private const uint LCMAP_UPPERCASE = 0x00000200;
  43. private static bool IsInvariantLocale(string localeName) => localeName == "";
  44. }
  45. }