]>
git.saurik.com Git - apple/icu.git/blob - icuSources/common/ustr_imp.h
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
4 **********************************************************************
5 * Copyright (C) 1999-2015, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 * file name: ustr_imp.h
10 * tab size: 8 (not used)
13 * created on: 2001jan30
14 * created by: Markus W. Scherer
17 #ifndef __USTR_IMP_H__
18 #define __USTR_IMP_H__
20 #include "unicode/utypes.h"
21 #include "unicode/utf8.h"
24 * Internal option for unorm_cmpEquivFold() for strncmp style.
25 * If set, checks for both string length and terminating NUL.
27 #define _STRNCMP_STYLE 0x1000
30 * Compare two strings in code point order or code unit order.
31 * Works in strcmp style (both lengths -1),
32 * strncmp style (lengths equal and >=0, flag TRUE),
33 * and memcmp/UnicodeString style (at least one length >=0).
35 U_CFUNC
int32_t U_EXPORT2
36 uprv_strCompare(const UChar
*s1
, int32_t length1
,
37 const UChar
*s2
, int32_t length2
,
38 UBool strncmpStyle
, UBool codePointOrder
);
40 U_CAPI
int32_t U_EXPORT2
41 ustr_hashUCharsN(const UChar
*str
, int32_t length
);
43 U_CAPI
int32_t U_EXPORT2
44 ustr_hashCharsN(const char *str
, int32_t length
);
46 U_CAPI
int32_t U_EXPORT2
47 ustr_hashICharsN(const char *str
, int32_t length
);
50 * NUL-terminate a UChar * string if possible.
51 * If length < destCapacity then NUL-terminate.
52 * If length == destCapacity then do not terminate but set U_STRING_NOT_TERMINATED_WARNING.
53 * If length > destCapacity then do not terminate but set U_BUFFER_OVERFLOW_ERROR.
55 * @param dest Destination buffer, can be NULL if destCapacity==0.
56 * @param destCapacity Number of UChars available at dest.
57 * @param length Number of UChars that were (to be) written to dest.
58 * @param pErrorCode ICU error code.
61 U_CAPI
int32_t U_EXPORT2
62 u_terminateUChars(UChar
*dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
65 * NUL-terminate a char * string if possible.
66 * Same as u_terminateUChars() but for a different string type.
68 U_CAPI
int32_t U_EXPORT2
69 u_terminateChars(char *dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
72 * NUL-terminate a UChar32 * string if possible.
73 * Same as u_terminateUChars() but for a different string type.
75 U_CAPI
int32_t U_EXPORT2
76 u_terminateUChar32s(UChar32
*dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
79 * NUL-terminate a wchar_t * string if possible.
80 * Same as u_terminateUChars() but for a different string type.
82 U_CAPI
int32_t U_EXPORT2
83 u_terminateWChars(wchar_t *dest
, int32_t destCapacity
, int32_t length
, UErrorCode
*pErrorCode
);
86 * Counts the bytes of any whole valid sequence for a UTF-8 lead byte.
87 * Returns 1 for ASCII 0..0x7f.
88 * Returns 0 for 0x80..0xc1 as well as for 0xf5..0xff.
89 * leadByte might be evaluated multiple times.
91 * @param leadByte The first byte of a UTF-8 sequence. Must be 0..0xff.
94 #define U8_COUNT_BYTES(leadByte) \
95 (U8_IS_SINGLE(leadByte) ? 1 : U8_COUNT_BYTES_NON_ASCII(leadByte))
98 * Counts the bytes of any whole valid sequence for a UTF-8 lead byte.
99 * Returns 0 for 0x00..0xc1 as well as for 0xf5..0xff.
100 * leadByte might be evaluated multiple times.
102 * @param leadByte The first byte of a UTF-8 sequence. Must be 0..0xff.
105 #define U8_COUNT_BYTES_NON_ASCII(leadByte) \
106 (U8_IS_LEAD(leadByte) ? ((uint8_t)(leadByte)>=0xe0)+((uint8_t)(leadByte)>=0xf0)+2 : 0)
114 UTF8() = delete; // all static
117 * Is t a valid UTF-8 trail byte?
119 * @param prev Must be the preceding lead byte if i==1 and length>=3;
121 * @param t The i-th byte following the lead byte.
122 * @param i The index (1..3) of byte t in the byte sequence. 0<i<length
123 * @param length The length (2..4) of the byte sequence according to the lead byte.
124 * @return TRUE if t is a valid trail byte in this context.
126 static inline UBool
isValidTrail(int32_t prev
, uint8_t t
, int32_t i
, int32_t length
) {
127 // The first trail byte after a 3- or 4-byte lead byte
128 // needs to be validated together with its lead byte.
129 if (length
<= 2 || i
> 1) {
130 return U8_IS_TRAIL(t
);
131 } else if (length
== 3) {
132 return U8_IS_VALID_LEAD3_AND_T1(prev
, t
);
133 } else { // length == 4
134 return U8_IS_VALID_LEAD4_AND_T1(prev
, t
);
141 #endif // __cplusplus
144 * Check whether a code point has the emoji property.
145 * (implemented in uchar.cpp as reduced version of u_hasBinaryProperty)
147 * @param c Code point to test.
148 * @return TRUE or FALSE according to whether c has the emoji property.
150 * @internal Apple only
152 U_CAPI UBool U_EXPORT2
153 u_isEmoji(UChar32 c
);