OLD | NEW |
1 /* | 1 /* |
2 ******************************************************************************* | 2 ******************************************************************************* |
3 * | 3 * |
4 * Copyright (C) 2001-2011, International Business Machines | 4 * Copyright (C) 2001-2014, International Business Machines |
5 * Corporation and others. All Rights Reserved. | 5 * Corporation and others. All Rights Reserved. |
6 * | 6 * |
7 ******************************************************************************* | 7 ******************************************************************************* |
8 * file name: ustrcase.cpp | 8 * file name: ustrcase.cpp |
9 * encoding: US-ASCII | 9 * encoding: US-ASCII |
10 * tab size: 8 (not used) | 10 * tab size: 8 (not used) |
11 * indentation:4 | 11 * indentation:4 |
12 * | 12 * |
13 * created on: 2002feb20 | 13 * created on: 2002feb20 |
14 * created by: Markus W. Scherer | 14 * created by: Markus W. Scherer |
15 * | 15 * |
16 * Implementation file for string casing C API functions. | 16 * Implementation file for string casing C API functions. |
17 * Uses functions from uchar.c for basic functionality that requires access | 17 * Uses functions from uchar.c for basic functionality that requires access |
18 * to the Unicode Character Database (uprops.dat). | 18 * to the Unicode Character Database (uprops.dat). |
19 */ | 19 */ |
20 | 20 |
21 #include "unicode/utypes.h" | 21 #include "unicode/utypes.h" |
22 #include "unicode/brkiter.h" | 22 #include "unicode/brkiter.h" |
23 #include "unicode/ustring.h" | 23 #include "unicode/ustring.h" |
24 #include "unicode/ucasemap.h" | 24 #include "unicode/ucasemap.h" |
25 #include "unicode/ubrk.h" | 25 #include "unicode/ubrk.h" |
26 #include "unicode/utf.h" | 26 #include "unicode/utf.h" |
27 #include "unicode/utf16.h" | 27 #include "unicode/utf16.h" |
28 #include "cmemory.h" | 28 #include "cmemory.h" |
29 #include "ucase.h" | 29 #include "ucase.h" |
30 #include "ustr_imp.h" | 30 #include "ustr_imp.h" |
31 | 31 |
32 #define LENGTHOF(array) (int32_t)(sizeof(array)/sizeof((array)[0])) | |
33 | |
34 U_NAMESPACE_USE | 32 U_NAMESPACE_USE |
35 | 33 |
36 /* string casing ------------------------------------------------------------ */ | 34 /* string casing ------------------------------------------------------------ */ |
37 | 35 |
38 /* Appends a full case mapping result, see UCASE_MAX_STRING_LENGTH. */ | 36 /* Appends a full case mapping result, see UCASE_MAX_STRING_LENGTH. */ |
39 static inline int32_t | 37 static inline int32_t |
40 appendResult(UChar *dest, int32_t destIndex, int32_t destCapacity, | 38 appendResult(UChar *dest, int32_t destIndex, int32_t destCapacity, |
41 int32_t result, const UChar *s) { | 39 int32_t result, const UChar *s) { |
42 UChar32 c; | 40 UChar32 c; |
43 int32_t length; | 41 int32_t length; |
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 if(srcLength==-1) { | 390 if(srcLength==-1) { |
393 srcLength=u_strlen(src); | 391 srcLength=u_strlen(src); |
394 } | 392 } |
395 | 393 |
396 /* check for overlapping source and destination */ | 394 /* check for overlapping source and destination */ |
397 if( dest!=NULL && | 395 if( dest!=NULL && |
398 ((src>=dest && src<(dest+destCapacity)) || | 396 ((src>=dest && src<(dest+destCapacity)) || |
399 (dest>=src && dest<(src+srcLength))) | 397 (dest>=src && dest<(src+srcLength))) |
400 ) { | 398 ) { |
401 /* overlap: provide a temporary destination buffer and later copy the re
sult */ | 399 /* overlap: provide a temporary destination buffer and later copy the re
sult */ |
402 if(destCapacity<=LENGTHOF(buffer)) { | 400 if(destCapacity<=UPRV_LENGTHOF(buffer)) { |
403 /* the stack buffer is large enough */ | 401 /* the stack buffer is large enough */ |
404 temp=buffer; | 402 temp=buffer; |
405 } else { | 403 } else { |
406 /* allocate a buffer */ | 404 /* allocate a buffer */ |
407 temp=(UChar *)uprv_malloc(destCapacity*U_SIZEOF_UCHAR); | 405 temp=(UChar *)uprv_malloc(destCapacity*U_SIZEOF_UCHAR); |
408 if(temp==NULL) { | 406 if(temp==NULL) { |
409 *pErrorCode=U_MEMORY_ALLOCATION_ERROR; | 407 *pErrorCode=U_MEMORY_ALLOCATION_ERROR; |
410 return 0; | 408 return 0; |
411 } | 409 } |
412 } | 410 } |
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 &errorCode); | 797 &errorCode); |
800 } | 798 } |
801 | 799 |
802 U_CAPI int32_t U_EXPORT2 | 800 U_CAPI int32_t U_EXPORT2 |
803 u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options) { | 801 u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options) { |
804 UErrorCode errorCode=U_ZERO_ERROR; | 802 UErrorCode errorCode=U_ZERO_ERROR; |
805 return u_strcmpFold(s1, n, s2, n, | 803 return u_strcmpFold(s1, n, s2, n, |
806 options|(U_COMPARE_IGNORE_CASE|_STRNCMP_STYLE), | 804 options|(U_COMPARE_IGNORE_CASE|_STRNCMP_STYLE), |
807 &errorCode); | 805 &errorCode); |
808 } | 806 } |
OLD | NEW |