ICU 59.1  59.1
ustring.h
Go to the documentation of this file.
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4 **********************************************************************
5 * Copyright (C) 1998-2014, International Business Machines
6 * Corporation and others. All Rights Reserved.
7 **********************************************************************
8 *
9 * File ustring.h
10 *
11 * Modification History:
12 *
13 * Date Name Description
14 * 12/07/98 bertrand Creation.
15 ******************************************************************************
16 */
17 
18 #ifndef USTRING_H
19 #define USTRING_H
20 
21 #include "unicode/utypes.h"
22 #include "unicode/putil.h"
23 #include "unicode/uiter.h"
24 
30 #ifndef UBRK_TYPEDEF_UBREAK_ITERATOR
31 # define UBRK_TYPEDEF_UBREAK_ITERATOR
32 
34 #endif
35 
92 U_STABLE int32_t U_EXPORT2
93 u_strlen(const UChar *s);
109 U_STABLE int32_t U_EXPORT2
110 u_countChar32(const UChar *s, int32_t length);
111 
130 U_STABLE UBool U_EXPORT2
131 u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number);
132 
143 U_STABLE UChar* U_EXPORT2
144 u_strcat(UChar *dst,
145  const UChar *src);
146 
161 U_STABLE UChar* U_EXPORT2
162 u_strncat(UChar *dst,
163  const UChar *src,
164  int32_t n);
165 
186 U_STABLE UChar * U_EXPORT2
187 u_strstr(const UChar *s, const UChar *substring);
188 
210 U_STABLE UChar * U_EXPORT2
211 u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength);
212 
230 U_STABLE UChar * U_EXPORT2
231 u_strchr(const UChar *s, UChar c);
232 
250 U_STABLE UChar * U_EXPORT2
251 u_strchr32(const UChar *s, UChar32 c);
252 
273 U_STABLE UChar * U_EXPORT2
274 u_strrstr(const UChar *s, const UChar *substring);
275 
297 U_STABLE UChar * U_EXPORT2
298 u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength);
299 
317 U_STABLE UChar * U_EXPORT2
318 u_strrchr(const UChar *s, UChar c);
319 
337 U_STABLE UChar * U_EXPORT2
338 u_strrchr32(const UChar *s, UChar32 c);
339 
352 U_STABLE UChar * U_EXPORT2
353 u_strpbrk(const UChar *string, const UChar *matchSet);
354 
368 U_STABLE int32_t U_EXPORT2
369 u_strcspn(const UChar *string, const UChar *matchSet);
370 
384 U_STABLE int32_t U_EXPORT2
385 u_strspn(const UChar *string, const UChar *matchSet);
386 
412 U_STABLE UChar * U_EXPORT2
413 u_strtok_r(UChar *src,
414  const UChar *delim,
415  UChar **saveState);
416 
427 U_STABLE int32_t U_EXPORT2
428 u_strcmp(const UChar *s1,
429  const UChar *s2);
430 
442 U_STABLE int32_t U_EXPORT2
443 u_strcmpCodePointOrder(const UChar *s1, const UChar *s2);
444 
472 U_STABLE int32_t U_EXPORT2
473 u_strCompare(const UChar *s1, int32_t length1,
474  const UChar *s2, int32_t length2,
475  UBool codePointOrder);
476 
497 U_STABLE int32_t U_EXPORT2
498 u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder);
499 
500 #ifndef U_COMPARE_CODE_POINT_ORDER
501 /* see also unistr.h and unorm.h */
507 #define U_COMPARE_CODE_POINT_ORDER 0x8000
508 #endif
509 
550 U_STABLE int32_t U_EXPORT2
551 u_strCaseCompare(const UChar *s1, int32_t length1,
552  const UChar *s2, int32_t length2,
553  uint32_t options,
554  UErrorCode *pErrorCode);
555 
568 U_STABLE int32_t U_EXPORT2
569 u_strncmp(const UChar *ucs1,
570  const UChar *ucs2,
571  int32_t n);
572 
586 U_STABLE int32_t U_EXPORT2
587 u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n);
588 
608 U_STABLE int32_t U_EXPORT2
609 u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options);
610 
632 U_STABLE int32_t U_EXPORT2
633 u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options);
634 
656 U_STABLE int32_t U_EXPORT2
657 u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options);
658 
667 U_STABLE UChar* U_EXPORT2
668 u_strcpy(UChar *dst,
669  const UChar *src);
670 
682 U_STABLE UChar* U_EXPORT2
683 u_strncpy(UChar *dst,
684  const UChar *src,
685  int32_t n);
686 
687 #if !UCONFIG_NO_CONVERSION
688 
699 U_STABLE UChar* U_EXPORT2 u_uastrcpy(UChar *dst,
700  const char *src );
701 
714 U_STABLE UChar* U_EXPORT2 u_uastrncpy(UChar *dst,
715  const char *src,
716  int32_t n);
717 
728 U_STABLE char* U_EXPORT2 u_austrcpy(char *dst,
729  const UChar *src );
730 
743 U_STABLE char* U_EXPORT2 u_austrncpy(char *dst,
744  const UChar *src,
745  int32_t n );
746 
747 #endif
748 
757 U_STABLE UChar* U_EXPORT2
758 u_memcpy(UChar *dest, const UChar *src, int32_t count);
759 
768 U_STABLE UChar* U_EXPORT2
769 u_memmove(UChar *dest, const UChar *src, int32_t count);
770 
780 U_STABLE UChar* U_EXPORT2
781 u_memset(UChar *dest, UChar c, int32_t count);
782 
794 U_STABLE int32_t U_EXPORT2
795 u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count);
796 
810 U_STABLE int32_t U_EXPORT2
811 u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count);
812 
830 U_STABLE UChar* U_EXPORT2
831 u_memchr(const UChar *s, UChar c, int32_t count);
832 
850 U_STABLE UChar* U_EXPORT2
851 u_memchr32(const UChar *s, UChar32 c, int32_t count);
852 
870 U_STABLE UChar* U_EXPORT2
871 u_memrchr(const UChar *s, UChar c, int32_t count);
872 
890 U_STABLE UChar* U_EXPORT2
891 u_memrchr32(const UChar *s, UChar32 c, int32_t count);
892 
943 #if defined(U_DECLARE_UTF16)
944 # define U_STRING_DECL(var, cs, length) static const UChar *var=(const UChar *)U_DECLARE_UTF16(cs)
945 
946 # define U_STRING_INIT(var, cs, length)
947 #elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
948 # define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=L ## cs
949 
950 # define U_STRING_INIT(var, cs, length)
951 #elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
952 # define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=cs
953 
954 # define U_STRING_INIT(var, cs, length)
955 #else
956 # define U_STRING_DECL(var, cs, length) static UChar var[(length)+1]
957 
958 # define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1)
959 #endif
960 
1008 U_STABLE int32_t U_EXPORT2
1009 u_unescape(const char *src,
1010  UChar *dest, int32_t destCapacity);
1011 
1025 typedef UChar (U_CALLCONV *UNESCAPE_CHAR_AT)(int32_t offset, void *context);
1027 
1056 U_STABLE UChar32 U_EXPORT2
1058  int32_t *offset,
1059  int32_t length,
1060  void *context);
1061 
1082 U_STABLE int32_t U_EXPORT2
1083 u_strToUpper(UChar *dest, int32_t destCapacity,
1084  const UChar *src, int32_t srcLength,
1085  const char *locale,
1086  UErrorCode *pErrorCode);
1087 
1108 U_STABLE int32_t U_EXPORT2
1109 u_strToLower(UChar *dest, int32_t destCapacity,
1110  const UChar *src, int32_t srcLength,
1111  const char *locale,
1112  UErrorCode *pErrorCode);
1113 
1114 #if !UCONFIG_NO_BREAK_ITERATION
1115 
1154 U_STABLE int32_t U_EXPORT2
1155 u_strToTitle(UChar *dest, int32_t destCapacity,
1156  const UChar *src, int32_t srcLength,
1157  UBreakIterator *titleIter,
1158  const char *locale,
1159  UErrorCode *pErrorCode);
1160 
1161 #endif
1162 
1187 U_STABLE int32_t U_EXPORT2
1188 u_strFoldCase(UChar *dest, int32_t destCapacity,
1189  const UChar *src, int32_t srcLength,
1190  uint32_t options,
1191  UErrorCode *pErrorCode);
1192 
1193 #if defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION
1194 
1216 U_STABLE wchar_t* U_EXPORT2
1217 u_strToWCS(wchar_t *dest,
1218  int32_t destCapacity,
1219  int32_t *pDestLength,
1220  const UChar *src,
1221  int32_t srcLength,
1222  UErrorCode *pErrorCode);
1245 U_STABLE UChar* U_EXPORT2
1246 u_strFromWCS(UChar *dest,
1247  int32_t destCapacity,
1248  int32_t *pDestLength,
1249  const wchar_t *src,
1250  int32_t srcLength,
1251  UErrorCode *pErrorCode);
1252 #endif /* defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION */
1253 
1276 U_STABLE char* U_EXPORT2
1277 u_strToUTF8(char *dest,
1278  int32_t destCapacity,
1279  int32_t *pDestLength,
1280  const UChar *src,
1281  int32_t srcLength,
1282  UErrorCode *pErrorCode);
1283 
1306 U_STABLE UChar* U_EXPORT2
1307 u_strFromUTF8(UChar *dest,
1308  int32_t destCapacity,
1309  int32_t *pDestLength,
1310  const char *src,
1311  int32_t srcLength,
1312  UErrorCode *pErrorCode);
1313 
1349 U_STABLE char* U_EXPORT2
1350 u_strToUTF8WithSub(char *dest,
1351  int32_t destCapacity,
1352  int32_t *pDestLength,
1353  const UChar *src,
1354  int32_t srcLength,
1355  UChar32 subchar, int32_t *pNumSubstitutions,
1356  UErrorCode *pErrorCode);
1357 
1394 U_STABLE UChar* U_EXPORT2
1396  int32_t destCapacity,
1397  int32_t *pDestLength,
1398  const char *src,
1399  int32_t srcLength,
1400  UChar32 subchar, int32_t *pNumSubstitutions,
1401  UErrorCode *pErrorCode);
1402 
1454 U_STABLE UChar * U_EXPORT2
1456  int32_t destCapacity,
1457  int32_t *pDestLength,
1458  const char *src,
1459  int32_t srcLength,
1460  UErrorCode *pErrorCode);
1461 
1484 U_STABLE UChar32* U_EXPORT2
1485 u_strToUTF32(UChar32 *dest,
1486  int32_t destCapacity,
1487  int32_t *pDestLength,
1488  const UChar *src,
1489  int32_t srcLength,
1490  UErrorCode *pErrorCode);
1491 
1514 U_STABLE UChar* U_EXPORT2
1515 u_strFromUTF32(UChar *dest,
1516  int32_t destCapacity,
1517  int32_t *pDestLength,
1518  const UChar32 *src,
1519  int32_t srcLength,
1520  UErrorCode *pErrorCode);
1521 
1557 U_STABLE UChar32* U_EXPORT2
1559  int32_t destCapacity,
1560  int32_t *pDestLength,
1561  const UChar *src,
1562  int32_t srcLength,
1563  UChar32 subchar, int32_t *pNumSubstitutions,
1564  UErrorCode *pErrorCode);
1565 
1601 U_STABLE UChar* U_EXPORT2
1603  int32_t destCapacity,
1604  int32_t *pDestLength,
1605  const UChar32 *src,
1606  int32_t srcLength,
1607  UChar32 subchar, int32_t *pNumSubstitutions,
1608  UErrorCode *pErrorCode);
1609 
1642 U_STABLE char* U_EXPORT2
1644  char *dest,
1645  int32_t destCapacity,
1646  int32_t *pDestLength,
1647  const UChar *src,
1648  int32_t srcLength,
1649  UErrorCode *pErrorCode);
1650 
1692 U_STABLE UChar* U_EXPORT2
1694  UChar *dest,
1695  int32_t destCapacity,
1696  int32_t *pDestLength,
1697  const char *src,
1698  int32_t srcLength,
1699  UChar32 subchar, int32_t *pNumSubstitutions,
1700  UErrorCode *pErrorCode);
1701 
1702 #endif
UChar * u_strtok_r(UChar *src, const UChar *delim, UChar **saveState)
The string tokenizer API allows an application to break a string into tokens.
struct UBreakIterator UBreakIterator
Opaque type representing an ICU Break iterator object.
Definition: ubrk.h:28
UChar * u_strFromJavaModifiedUTF8WithSub(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const char *src, int32_t srcLength, UChar32 subchar, int32_t *pNumSubstitutions, UErrorCode *pErrorCode)
Convert a Java Modified UTF-8 string to a 16-bit Unicode string.
UChar * u_memchr(const UChar *s, UChar c, int32_t count)
Find the first occurrence of a BMP code point in a string.
int32_t u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n)
Compare two Unicode strings in code point order.
UChar * u_strFromWCS(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const wchar_t *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a wchar_t string to UTF-16.
UChar * u_strFromUTF8Lenient(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const char *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a UTF-8 string to UTF-16.
UChar * u_strFromUTF32WithSub(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const UChar32 *src, int32_t srcLength, UChar32 subchar, int32_t *pNumSubstitutions, UErrorCode *pErrorCode)
Convert a UTF-32 string to UTF-16.
UChar * u_strrchr(const UChar *s, UChar c)
Find the last occurrence of a BMP code point in a string.
UChar32 * u_strToUTF32(UChar32 *dest, int32_t destCapacity, int32_t *pDestLength, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a UTF-16 string to UTF-32.
int32_t u_strToTitle(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, UBreakIterator *titleIter, const char *locale, UErrorCode *pErrorCode)
Titlecase a string.
UChar(* UNESCAPE_CHAR_AT)(int32_t offset, void *context)
Callback function for u_unescapeAt() that returns a character of the source text given an offset and ...
Definition: ustring.h:1025
UChar * u_strncpy(UChar *dst, const UChar *src, int32_t n)
Copy a ustring.
int32_t u_countChar32(const UChar *s, int32_t length)
Count Unicode code points in the length UChar code units of the string.
UChar * u_memcpy(UChar *dest, const UChar *src, int32_t count)
Synonym for memcpy(), but with UChars only.
char * u_strToUTF8(char *dest, int32_t destCapacity, int32_t *pDestLength, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a UTF-16 string to UTF-8.
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition: platform.h:871
int32_t u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count)
Compare two Unicode strings in code point order.
int32_t u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options)
Compare two strings case-insensitively using full case folding.
C API for code unit iteration.
Definition: uiter.h:341
int32_t u_strcmpCodePointOrder(const UChar *s1, const UChar *s2)
Compare two Unicode strings in code point order.
UChar * u_strchr32(const UChar *s, UChar32 c)
Find the first occurrence of a code point in a string.
int32_t u_strFoldCase(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, uint32_t options, UErrorCode *pErrorCode)
Case-folds the characters in a string.
UChar32 * u_strToUTF32WithSub(UChar32 *dest, int32_t destCapacity, int32_t *pDestLength, const UChar *src, int32_t srcLength, UChar32 subchar, int32_t *pNumSubstitutions, UErrorCode *pErrorCode)
Convert a UTF-16 string to UTF-32.
UBool u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number)
Check if the string contains more Unicode code points than a certain number.
int32_t u_strcspn(const UChar *string, const UChar *matchSet)
Returns the number of consecutive characters in string, beginning with the first, that do not occur s...
char * u_austrncpy(char *dst, const UChar *src, int32_t n)
Copy ustring to a byte string encoded in the default codepage.
wchar_t * u_strToWCS(wchar_t *dest, int32_t destCapacity, int32_t *pDestLength, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a UTF-16 string to a wchar_t string.
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition: umachine.h:84
int32_t u_strCaseCompare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, uint32_t options, UErrorCode *pErrorCode)
Compare two strings case-insensitively using full case folding.
UChar * u_memset(UChar *dest, UChar c, int32_t count)
Initialize count characters of dest to c.
UChar * u_uastrcpy(UChar *dst, const char *src)
Copy a byte string encoded in the default codepage to a ustring.
int32_t u_strcmp(const UChar *s1, const UChar *s2)
Compare two Unicode strings for bitwise equality (code unit order).
int32_t u_strCompare(const UChar *s1, int32_t length1, const UChar *s2, int32_t length2, UBool codePointOrder)
Compare two Unicode strings (binary order).
UChar * u_strncat(UChar *dst, const UChar *src, int32_t n)
Concatenate two ustrings.
char * u_strToUTF8WithSub(char *dest, int32_t destCapacity, int32_t *pDestLength, const UChar *src, int32_t srcLength, UChar32 subchar, int32_t *pNumSubstitutions, UErrorCode *pErrorCode)
Convert a UTF-16 string to UTF-8.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition: umachine.h:396
UChar * u_strchr(const UChar *s, UChar c)
Find the first occurrence of a BMP code point in a string.
UChar * u_memrchr(const UChar *s, UChar c, int32_t count)
Find the last occurrence of a BMP code point in a string.
C API: Platform Utilities.
int32_t u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count)
Compare the first count UChars of each buffer.
UChar * u_strrchr32(const UChar *s, UChar32 c)
Find the last occurrence of a code point in a string.
UChar * u_strcpy(UChar *dst, const UChar *src)
Copy a ustring.
C API: Unicode Character Iteration.
UChar * u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength)
Find the last occurrence of a substring in a string.
UChar * u_memmove(UChar *dest, const UChar *src, int32_t count)
Synonym for memmove(), but with UChars only.
int32_t u_unescape(const char *src, UChar *dest, int32_t destCapacity)
Unescape a string of characters and write the resulting Unicode characters to the destination buffer...
int32_t u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder)
Compare two Unicode strings (binary order) as presented by UCharIterator objects. ...
int32_t u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options)
Compare two strings case-insensitively using full case folding.
UChar * u_strpbrk(const UChar *string, const UChar *matchSet)
Locates the first occurrence in the string string of any of the characters in the string matchSet...
UChar * u_strcat(UChar *dst, const UChar *src)
Concatenate two ustrings.
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition: umachine.h:349
UChar * u_strstr(const UChar *s, const UChar *substring)
Find the first occurrence of a substring in a string.
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition: umachine.h:85
int32_t u_strToLower(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, UErrorCode *pErrorCode)
Lowercase the characters in a string.
int32_t u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options)
Compare two strings case-insensitively using full case folding.
int32_t u_strncmp(const UChar *ucs1, const UChar *ucs2, int32_t n)
Compare two ustrings for bitwise equality.
UChar * u_strFromUTF32(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const UChar32 *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a UTF-32 string to UTF-16.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers...
Definition: utypes.h:396
char * u_strToJavaModifiedUTF8(char *dest, int32_t destCapacity, int32_t *pDestLength, const UChar *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a 16-bit Unicode string to Java Modified UTF-8.
char * u_austrcpy(char *dst, const UChar *src)
Copy ustring to a byte string encoded in the default codepage.
UChar32 u_unescapeAt(UNESCAPE_CHAR_AT charAt, int32_t *offset, int32_t length, void *context)
Unescape a single sequence.
int32_t u_strspn(const UChar *string, const UChar *matchSet)
Returns the number of consecutive characters in string, beginning with the first, that occur somewher...
UChar * u_strFromUTF8(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const char *src, int32_t srcLength, UErrorCode *pErrorCode)
Convert a UTF-8 string to UTF-16.
Basic definitions for ICU, for both C and C++ APIs.
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
UChar * u_memchr32(const UChar *s, UChar32 c, int32_t count)
Find the first occurrence of a code point in a string.
UChar * u_memrchr32(const UChar *s, UChar32 c, int32_t count)
Find the last occurrence of a code point in a string.
UChar * u_strrstr(const UChar *s, const UChar *substring)
Find the last occurrence of a substring in a string.
UChar * u_uastrncpy(UChar *dst, const char *src, int32_t n)
Copy a byte string encoded in the default codepage to a ustring.
UChar * u_strFromUTF8WithSub(UChar *dest, int32_t destCapacity, int32_t *pDestLength, const char *src, int32_t srcLength, UChar32 subchar, int32_t *pNumSubstitutions, UErrorCode *pErrorCode)
Convert a UTF-8 string to UTF-16.
int32_t u_strToUpper(UChar *dest, int32_t destCapacity, const UChar *src, int32_t srcLength, const char *locale, UErrorCode *pErrorCode)
Uppercase the characters in a string.
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition: umachine.h:111
int8_t UBool
The ICU boolean type.
Definition: umachine.h:236
UChar * u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength)
Find the first occurrence of a substring in a string.