ustrcase_locale.cpp 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // © 2016 and later: Unicode, Inc. and others.
  2. // License & terms of use: http://www.unicode.org/copyright.html
  3. /*
  4. *******************************************************************************
  5. * Copyright (C) 2011, International Business Machines
  6. * Corporation and others. All Rights Reserved.
  7. *******************************************************************************
  8. * file name: ustrcase_locale.cpp
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:4
  12. *
  13. * created on: 2011may31
  14. * created by: Markus W. Scherer
  15. *
  16. * Locale-sensitive case mapping functions (ones that call uloc_getDefault())
  17. * were moved here to break dependency cycles among parts of the common library.
  18. */
  19. #include "unicode/utypes.h"
  20. #include "uassert.h"
  21. #include "unicode/brkiter.h"
  22. #include "unicode/casemap.h"
  23. #include "unicode/ucasemap.h"
  24. #include "unicode/uloc.h"
  25. #include "unicode/ustring.h"
  26. #include "ucase.h"
  27. #include "ucasemap_imp.h"
  28. U_CFUNC int32_t
  29. ustrcase_getCaseLocale(const char *locale) {
  30. if (locale == nullptr) {
  31. locale = uloc_getDefault();
  32. }
  33. if (*locale == 0) {
  34. return UCASE_LOC_ROOT;
  35. } else {
  36. return ucase_getCaseLocale(locale);
  37. }
  38. }
  39. /* public API functions */
  40. U_CAPI int32_t U_EXPORT2
  41. u_strToLower(char16_t *dest, int32_t destCapacity,
  42. const char16_t *src, int32_t srcLength,
  43. const char *locale,
  44. UErrorCode *pErrorCode) {
  45. return ustrcase_mapWithOverlap(
  46. ustrcase_getCaseLocale(locale), 0, UCASEMAP_BREAK_ITERATOR_NULL
  47. dest, destCapacity,
  48. src, srcLength,
  49. ustrcase_internalToLower, *pErrorCode);
  50. }
  51. U_CAPI int32_t U_EXPORT2
  52. u_strToUpper(char16_t *dest, int32_t destCapacity,
  53. const char16_t *src, int32_t srcLength,
  54. const char *locale,
  55. UErrorCode *pErrorCode) {
  56. return ustrcase_mapWithOverlap(
  57. ustrcase_getCaseLocale(locale), 0, UCASEMAP_BREAK_ITERATOR_NULL
  58. dest, destCapacity,
  59. src, srcLength,
  60. ustrcase_internalToUpper, *pErrorCode);
  61. }
  62. U_NAMESPACE_BEGIN
  63. int32_t CaseMap::toLower(
  64. const char *locale, uint32_t options,
  65. const char16_t *src, int32_t srcLength,
  66. char16_t *dest, int32_t destCapacity, Edits *edits,
  67. UErrorCode &errorCode) {
  68. return ustrcase_map(
  69. ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
  70. dest, destCapacity,
  71. src, srcLength,
  72. ustrcase_internalToLower, edits, errorCode);
  73. }
  74. int32_t CaseMap::toUpper(
  75. const char *locale, uint32_t options,
  76. const char16_t *src, int32_t srcLength,
  77. char16_t *dest, int32_t destCapacity, Edits *edits,
  78. UErrorCode &errorCode) {
  79. return ustrcase_map(
  80. ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
  81. dest, destCapacity,
  82. src, srcLength,
  83. ustrcase_internalToUpper, edits, errorCode);
  84. }
  85. U_NAMESPACE_END