unistr_titlecase_brkiter.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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: unistr_titlecase_brkiter.cpp
  9. * encoding: UTF-8
  10. * tab size: 8 (not used)
  11. * indentation:2
  12. *
  13. * created on: 2011may30
  14. * created by: Markus W. Scherer
  15. *
  16. * Titlecasing functions that are based on BreakIterator
  17. * were moved here to break dependency cycles among parts of the common library.
  18. */
  19. #include "unicode/utypes.h"
  20. #if !UCONFIG_NO_BREAK_ITERATION
  21. #include "unicode/brkiter.h"
  22. #include "unicode/locid.h"
  23. #include "unicode/ucasemap.h"
  24. #include "unicode/unistr.h"
  25. #include "ucasemap_imp.h"
  26. U_NAMESPACE_BEGIN
  27. UnicodeString &
  28. UnicodeString::toTitle(BreakIterator *iter) {
  29. return toTitle(iter, Locale::getDefault(), 0);
  30. }
  31. UnicodeString &
  32. UnicodeString::toTitle(BreakIterator *iter, const Locale &locale) {
  33. return toTitle(iter, locale, 0);
  34. }
  35. UnicodeString &
  36. UnicodeString::toTitle(BreakIterator *iter, const Locale &locale, uint32_t options) {
  37. LocalPointer<BreakIterator> ownedIter;
  38. UErrorCode errorCode = U_ZERO_ERROR;
  39. iter = ustrcase_getTitleBreakIterator(&locale, "", options, iter, ownedIter, errorCode);
  40. if (iter == nullptr) {
  41. setToBogus();
  42. return *this;
  43. }
  44. caseMap(ustrcase_getCaseLocale(locale.getBaseName()), options, iter, ustrcase_internalToTitle);
  45. return *this;
  46. }
  47. U_NAMESPACE_END
  48. #endif // !UCONFIG_NO_BREAK_ITERATION