Home | History | Annotate | Download | only in common
      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 
     20 #include "unicode/utypes.h"
     21 #include "uassert.h"
     22 #include "unicode/brkiter.h"
     23 #include "unicode/casemap.h"
     24 #include "unicode/ucasemap.h"
     25 #include "unicode/uloc.h"
     26 #include "unicode/ustring.h"
     27 #include "ucase.h"
     28 #include "ucasemap_imp.h"
     29 
     30 U_CFUNC int32_t
     31 ustrcase_getCaseLocale(const char *locale) {
     32     if (locale == NULL) {
     33         locale = uloc_getDefault();
     34     }
     35     if (*locale == 0) {
     36         return UCASE_LOC_ROOT;
     37     } else {
     38         return ucase_getCaseLocale(locale);
     39     }
     40 }
     41 
     42 /* public API functions */
     43 
     44 U_CAPI int32_t U_EXPORT2
     45 u_strToLower(UChar *dest, int32_t destCapacity,
     46              const UChar *src, int32_t srcLength,
     47              const char *locale,
     48              UErrorCode *pErrorCode) {
     49     return ustrcase_mapWithOverlap(
     50         ustrcase_getCaseLocale(locale), 0, UCASEMAP_BREAK_ITERATOR_NULL
     51         dest, destCapacity,
     52         src, srcLength,
     53         ustrcase_internalToLower, *pErrorCode);
     54 }
     55 
     56 U_CAPI int32_t U_EXPORT2
     57 u_strToUpper(UChar *dest, int32_t destCapacity,
     58              const UChar *src, int32_t srcLength,
     59              const char *locale,
     60              UErrorCode *pErrorCode) {
     61     return ustrcase_mapWithOverlap(
     62         ustrcase_getCaseLocale(locale), 0, UCASEMAP_BREAK_ITERATOR_NULL
     63         dest, destCapacity,
     64         src, srcLength,
     65         ustrcase_internalToUpper, *pErrorCode);
     66 }
     67 
     68 U_NAMESPACE_BEGIN
     69 
     70 int32_t CaseMap::toLower(
     71         const char *locale, uint32_t options,
     72         const UChar *src, int32_t srcLength,
     73         UChar *dest, int32_t destCapacity, Edits *edits,
     74         UErrorCode &errorCode) {
     75     return ustrcase_map(
     76         ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
     77         dest, destCapacity,
     78         src, srcLength,
     79         ustrcase_internalToLower, edits, errorCode);
     80 }
     81 
     82 int32_t CaseMap::toUpper(
     83         const char *locale, uint32_t options,
     84         const UChar *src, int32_t srcLength,
     85         UChar *dest, int32_t destCapacity, Edits *edits,
     86         UErrorCode &errorCode) {
     87     return ustrcase_map(
     88         ustrcase_getCaseLocale(locale), options, UCASEMAP_BREAK_ITERATOR_NULL
     89         dest, destCapacity,
     90         src, srcLength,
     91         ustrcase_internalToUpper, edits, errorCode);
     92 }
     93 
     94 U_NAMESPACE_END
     95