ICU 62.1 62.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
34#endif
35
92U_STABLE int32_t U_EXPORT2
93u_strlen(const UChar *s);
109U_STABLE int32_t U_EXPORT2
110u_countChar32(const UChar *s, int32_t length);
111
130U_STABLE UBool U_EXPORT2
131u_strHasMoreChar32Than(const UChar *s, int32_t length, int32_t number);
132
143U_STABLE UChar* U_EXPORT2
145 const UChar *src);
146
161U_STABLE UChar* U_EXPORT2
163 const UChar *src,
164 int32_t n);
165
186U_STABLE UChar * U_EXPORT2
187u_strstr(const UChar *s, const UChar *substring);
188
210U_STABLE UChar * U_EXPORT2
211u_strFindFirst(const UChar *s, int32_t length, const UChar *substring, int32_t subLength);
212
230U_STABLE UChar * U_EXPORT2
231u_strchr(const UChar *s, UChar c);
232
250U_STABLE UChar * U_EXPORT2
252
273U_STABLE UChar * U_EXPORT2
274u_strrstr(const UChar *s, const UChar *substring);
275
297U_STABLE UChar * U_EXPORT2
298u_strFindLast(const UChar *s, int32_t length, const UChar *substring, int32_t subLength);
299
317U_STABLE UChar * U_EXPORT2
318u_strrchr(const UChar *s, UChar c);
319
337U_STABLE UChar * U_EXPORT2
339
352U_STABLE UChar * U_EXPORT2
353u_strpbrk(const UChar *string, const UChar *matchSet);
354
368U_STABLE int32_t U_EXPORT2
369u_strcspn(const UChar *string, const UChar *matchSet);
370
384U_STABLE int32_t U_EXPORT2
385u_strspn(const UChar *string, const UChar *matchSet);
386
412U_STABLE UChar * U_EXPORT2
414 const UChar *delim,
415 UChar **saveState);
416
427U_STABLE int32_t U_EXPORT2
428u_strcmp(const UChar *s1,
429 const UChar *s2);
430
442U_STABLE int32_t U_EXPORT2
443u_strcmpCodePointOrder(const UChar *s1, const UChar *s2);
444
472U_STABLE int32_t U_EXPORT2
473u_strCompare(const UChar *s1, int32_t length1,
474 const UChar *s2, int32_t length2,
475 UBool codePointOrder);
476
497U_STABLE int32_t U_EXPORT2
498u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder);
499
540U_STABLE int32_t U_EXPORT2
541u_strCaseCompare(const UChar *s1, int32_t length1,
542 const UChar *s2, int32_t length2,
543 uint32_t options,
544 UErrorCode *pErrorCode);
545
558U_STABLE int32_t U_EXPORT2
559u_strncmp(const UChar *ucs1,
560 const UChar *ucs2,
561 int32_t n);
562
576U_STABLE int32_t U_EXPORT2
577u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n);
578
598U_STABLE int32_t U_EXPORT2
599u_strcasecmp(const UChar *s1, const UChar *s2, uint32_t options);
600
622U_STABLE int32_t U_EXPORT2
623u_strncasecmp(const UChar *s1, const UChar *s2, int32_t n, uint32_t options);
624
646U_STABLE int32_t U_EXPORT2
647u_memcasecmp(const UChar *s1, const UChar *s2, int32_t length, uint32_t options);
648
657U_STABLE UChar* U_EXPORT2
659 const UChar *src);
660
672U_STABLE UChar* U_EXPORT2
674 const UChar *src,
675 int32_t n);
676
677#if !UCONFIG_NO_CONVERSION
678
690 const char *src );
691
705 const char *src,
706 int32_t n);
707
718U_STABLE char* U_EXPORT2 u_austrcpy(char *dst,
719 const UChar *src );
720
733U_STABLE char* U_EXPORT2 u_austrncpy(char *dst,
734 const UChar *src,
735 int32_t n );
736
737#endif
738
747U_STABLE UChar* U_EXPORT2
748u_memcpy(UChar *dest, const UChar *src, int32_t count);
749
758U_STABLE UChar* U_EXPORT2
759u_memmove(UChar *dest, const UChar *src, int32_t count);
760
770U_STABLE UChar* U_EXPORT2
771u_memset(UChar *dest, UChar c, int32_t count);
772
784U_STABLE int32_t U_EXPORT2
785u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count);
786
800U_STABLE int32_t U_EXPORT2
801u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count);
802
820U_STABLE UChar* U_EXPORT2
821u_memchr(const UChar *s, UChar c, int32_t count);
822
840U_STABLE UChar* U_EXPORT2
841u_memchr32(const UChar *s, UChar32 c, int32_t count);
842
860U_STABLE UChar* U_EXPORT2
861u_memrchr(const UChar *s, UChar c, int32_t count);
862
880U_STABLE UChar* U_EXPORT2
881u_memrchr32(const UChar *s, UChar32 c, int32_t count);
882
933#if defined(U_DECLARE_UTF16)
934# define U_STRING_DECL(var, cs, length) static const UChar *var=(const UChar *)U_DECLARE_UTF16(cs)
936# define U_STRING_INIT(var, cs, length)
937#elif U_SIZEOF_WCHAR_T==U_SIZEOF_UCHAR && (U_CHARSET_FAMILY==U_ASCII_FAMILY || (U_SIZEOF_UCHAR == 2 && defined(U_WCHAR_IS_UTF16)))
938# define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=L ## cs
940# define U_STRING_INIT(var, cs, length)
941#elif U_SIZEOF_UCHAR==1 && U_CHARSET_FAMILY==U_ASCII_FAMILY
942# define U_STRING_DECL(var, cs, length) static const UChar var[(length)+1]=cs
944# define U_STRING_INIT(var, cs, length)
945#else
946# define U_STRING_DECL(var, cs, length) static UChar var[(length)+1]
948# define U_STRING_INIT(var, cs, length) u_charsToUChars(cs, var, length+1)
949#endif
950
998U_STABLE int32_t U_EXPORT2
999u_unescape(const char *src,
1000 UChar *dest, int32_t destCapacity);
1001
1015typedef UChar (U_CALLCONV *UNESCAPE_CHAR_AT)(int32_t offset, void *context);
1017
1046U_STABLE UChar32 U_EXPORT2
1048 int32_t *offset,
1049 int32_t length,
1050 void *context);
1051
1072U_STABLE int32_t U_EXPORT2
1073u_strToUpper(UChar *dest, int32_t destCapacity,
1074 const UChar *src, int32_t srcLength,
1075 const char *locale,
1076 UErrorCode *pErrorCode);
1077
1098U_STABLE int32_t U_EXPORT2
1099u_strToLower(UChar *dest, int32_t destCapacity,
1100 const UChar *src, int32_t srcLength,
1101 const char *locale,
1102 UErrorCode *pErrorCode);
1103
1104#if !UCONFIG_NO_BREAK_ITERATION
1105
1144U_STABLE int32_t U_EXPORT2
1145u_strToTitle(UChar *dest, int32_t destCapacity,
1146 const UChar *src, int32_t srcLength,
1147 UBreakIterator *titleIter,
1148 const char *locale,
1149 UErrorCode *pErrorCode);
1150
1151#endif
1152
1177U_STABLE int32_t U_EXPORT2
1178u_strFoldCase(UChar *dest, int32_t destCapacity,
1179 const UChar *src, int32_t srcLength,
1180 uint32_t options,
1181 UErrorCode *pErrorCode);
1182
1183#if defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION
1206U_STABLE wchar_t* U_EXPORT2
1207u_strToWCS(wchar_t *dest,
1208 int32_t destCapacity,
1209 int32_t *pDestLength,
1210 const UChar *src,
1211 int32_t srcLength,
1212 UErrorCode *pErrorCode);
1235U_STABLE UChar* U_EXPORT2
1237 int32_t destCapacity,
1238 int32_t *pDestLength,
1239 const wchar_t *src,
1240 int32_t srcLength,
1241 UErrorCode *pErrorCode);
1242#endif /* defined(U_WCHAR_IS_UTF16) || defined(U_WCHAR_IS_UTF32) || !UCONFIG_NO_CONVERSION */
1243
1266U_STABLE char* U_EXPORT2
1267u_strToUTF8(char *dest,
1268 int32_t destCapacity,
1269 int32_t *pDestLength,
1270 const UChar *src,
1271 int32_t srcLength,
1272 UErrorCode *pErrorCode);
1273
1296U_STABLE UChar* U_EXPORT2
1298 int32_t destCapacity,
1299 int32_t *pDestLength,
1300 const char *src,
1301 int32_t srcLength,
1302 UErrorCode *pErrorCode);
1303
1339U_STABLE char* U_EXPORT2
1341 int32_t destCapacity,
1342 int32_t *pDestLength,
1343 const UChar *src,
1344 int32_t srcLength,
1345 UChar32 subchar, int32_t *pNumSubstitutions,
1346 UErrorCode *pErrorCode);
1347
1384U_STABLE UChar* U_EXPORT2
1386 int32_t destCapacity,
1387 int32_t *pDestLength,
1388 const char *src,
1389 int32_t srcLength,
1390 UChar32 subchar, int32_t *pNumSubstitutions,
1391 UErrorCode *pErrorCode);
1392
1444U_STABLE UChar * U_EXPORT2
1446 int32_t destCapacity,
1447 int32_t *pDestLength,
1448 const char *src,
1449 int32_t srcLength,
1450 UErrorCode *pErrorCode);
1451
1474U_STABLE UChar32* U_EXPORT2
1476 int32_t destCapacity,
1477 int32_t *pDestLength,
1478 const UChar *src,
1479 int32_t srcLength,
1480 UErrorCode *pErrorCode);
1481
1504U_STABLE UChar* U_EXPORT2
1506 int32_t destCapacity,
1507 int32_t *pDestLength,
1508 const UChar32 *src,
1509 int32_t srcLength,
1510 UErrorCode *pErrorCode);
1511
1547U_STABLE UChar32* U_EXPORT2
1549 int32_t destCapacity,
1550 int32_t *pDestLength,
1551 const UChar *src,
1552 int32_t srcLength,
1553 UChar32 subchar, int32_t *pNumSubstitutions,
1554 UErrorCode *pErrorCode);
1555
1591U_STABLE UChar* U_EXPORT2
1593 int32_t destCapacity,
1594 int32_t *pDestLength,
1595 const UChar32 *src,
1596 int32_t srcLength,
1597 UChar32 subchar, int32_t *pNumSubstitutions,
1598 UErrorCode *pErrorCode);
1599
1632U_STABLE char* U_EXPORT2
1634 char *dest,
1635 int32_t destCapacity,
1636 int32_t *pDestLength,
1637 const UChar *src,
1638 int32_t srcLength,
1639 UErrorCode *pErrorCode);
1640
1682U_STABLE UChar* U_EXPORT2
1684 UChar *dest,
1685 int32_t destCapacity,
1686 int32_t *pDestLength,
1687 const char *src,
1688 int32_t srcLength,
1689 UChar32 subchar, int32_t *pNumSubstitutions,
1690 UErrorCode *pErrorCode);
1691
1692#endif
#define U_CALLCONV
Similar to U_CDECL_BEGIN/U_CDECL_END, this qualifier is necessary in callback function typedefs to ma...
Definition platform.h:835
C API: Platform Utilities.
C API for code unit iteration.
Definition uiter.h:341
struct UBreakIterator UBreakIterator
Opaque type representing an ICU Break iterator object.
Definition ubrk.h:28
C API: Unicode Character Iteration.
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
Definition umachine.h:400
#define U_CDECL_END
This is used to end a declaration of a library private ICU C API.
Definition umachine.h:85
int8_t UBool
The ICU boolean type.
Definition umachine.h:236
uint16_t UChar
The base type for UTF-16 code units and pointers.
Definition umachine.h:353
#define U_CDECL_BEGIN
This is used to begin a declaration of a library private ICU C API.
Definition umachine.h:84
#define U_STABLE
This is used to declare a function as a stable public ICU C API.
Definition umachine.h:111
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.
char * u_austrncpy(char *dst, const UChar *src, int32_t n)
Copy ustring to a byte string encoded in the default codepage.
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.
char * u_austrcpy(char *dst, const UChar *src)
Copy ustring to a byte string encoded in the default codepage.
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.
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.
UChar * u_memrchr32(const UChar *s, UChar32 c, int32_t count)
Find the last occurrence of a code point in a string.
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_strncpy(UChar *dst, const UChar *src, int32_t n)
Copy a ustring.
UChar * u_memmove(UChar *dest, const UChar *src, int32_t count)
Synonym for memmove(), but with UChars only.
UChar * u_strrchr32(const UChar *s, UChar32 c)
Find the last occurrence of a code point in a string.
UChar * u_strncat(UChar *dst, const UChar *src, int32_t n)
Concatenate two ustrings.
UChar * u_strstr(const UChar *s, const UChar *substring)
Find the first occurrence of a substring in a string.
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...
UChar * u_memchr(const UChar *s, UChar c, int32_t count)
Find the first occurrence of a BMP code point in a string.
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.
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(* 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:1015
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_uastrncpy(UChar *dst, const char *src, int32_t n)
Copy a byte string encoded in the default codepage to a ustring.
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.
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.
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.
int32_t u_memcmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t count)
Compare two Unicode strings in code point order.
int32_t u_strncmp(const UChar *ucs1, const UChar *ucs2, int32_t n)
Compare two ustrings for bitwise equality.
UChar * u_strrchr(const UChar *s, UChar c)
Find the last occurrence of a BMP code point in a string.
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.
UChar * u_memcpy(UChar *dest, const UChar *src, int32_t count)
Synonym for memcpy(), 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.
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_memset(UChar *dest, UChar c, int32_t count)
Initialize count characters of dest to c.
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.
UChar * u_strrstr(const UChar *s, const UChar *substring)
Find the last occurrence of a substring in a string.
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 * 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.
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.
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.
int32_t u_memcmp(const UChar *buf1, const UChar *buf2, int32_t count)
Compare the first count UChars of each buffer.
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_strcmpCodePointOrder(const UChar *s1, const UChar *s2)
Compare two Unicode strings in code point order.
UChar * u_strcpy(UChar *dst, const UChar *src)
Copy a ustring.
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_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_unescapeAt(UNESCAPE_CHAR_AT charAt, int32_t *offset, int32_t length, void *context)
Unescape a single sequence.
UChar * u_strchr(const UChar *s, UChar c)
Find the first occurrence of a BMP code point in a string.
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.
UChar * u_memchr32(const UChar *s, UChar32 c, int32_t count)
Find the first occurrence of a code point in a string.
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...
int32_t u_strcmp(const UChar *s1, const UChar *s2)
Compare two Unicode strings for bitwise equality (code unit order).
int32_t u_strlen(const UChar *s)
Determine the length of an array of UChar.
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.
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.
UChar * u_uastrcpy(UChar *dst, const char *src)
Copy a byte string encoded in the default codepage to a ustring.
int32_t u_strncmpCodePointOrder(const UChar *s1, const UChar *s2, int32_t n)
Compare two Unicode strings in code point order.
UChar * u_strcat(UChar *dst, const UChar *src)
Concatenate two ustrings.
UChar * u_strtok_r(UChar *src, const UChar *delim, UChar **saveState)
The string tokenizer API allows an application to break a string into tokens.
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_countChar32(const UChar *s, int32_t length)
Count Unicode code points in the length UChar code units of the string.
int32_t u_strCompareIter(UCharIterator *iter1, UCharIterator *iter2, UBool codePointOrder)
Compare two Unicode strings (binary order) as presented by UCharIterator objects.
UChar * u_strchr32(const UChar *s, UChar32 c)
Find the first occurrence of a 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.
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.
Basic definitions for ICU, for both C and C++ APIs.
UErrorCode
Error code to replace exception handling, so that the code is compatible with all C++ compilers,...
Definition utypes.h:396