]>
Commit | Line | Data |
---|---|---|
b75a7d8f A |
1 | /* |
2 | ****************************************************************************** | |
3 | * | |
51004dcb | 4 | * Copyright (C) 1997-2012, International Business Machines |
b75a7d8f A |
5 | * Corporation and others. All Rights Reserved. |
6 | * | |
7 | ****************************************************************************** | |
8 | * | |
9 | * File CSTRING.H | |
10 | * | |
11 | * Contains CString interface | |
12 | * | |
13 | * @author Helena Shih | |
14 | * | |
15 | * Modification History: | |
16 | * | |
17 | * Date Name Description | |
18 | * 6/17/98 hshih Created. | |
19 | * 05/03/99 stephen Changed from functions to macros. | |
20 | * 06/14/99 stephen Added icu_strncat, icu_strncmp, icu_tolower | |
21 | * | |
22 | ****************************************************************************** | |
23 | */ | |
24 | ||
25 | #ifndef CSTRING_H | |
26 | #define CSTRING_H 1 | |
27 | ||
28 | #include "unicode/utypes.h" | |
51004dcb | 29 | #include "cmemory.h" |
b75a7d8f A |
30 | #include <string.h> |
31 | #include <stdlib.h> | |
32 | #include <ctype.h> | |
33 | ||
34 | #define uprv_strcpy(dst, src) U_STANDARD_CPP_NAMESPACE strcpy(dst, src) | |
b75a7d8f A |
35 | #define uprv_strlen(str) U_STANDARD_CPP_NAMESPACE strlen(str) |
36 | #define uprv_strcmp(s1, s2) U_STANDARD_CPP_NAMESPACE strcmp(s1, s2) | |
b75a7d8f | 37 | #define uprv_strcat(dst, src) U_STANDARD_CPP_NAMESPACE strcat(dst, src) |
b75a7d8f A |
38 | #define uprv_strchr(s, c) U_STANDARD_CPP_NAMESPACE strchr(s, c) |
39 | #define uprv_strstr(s, c) U_STANDARD_CPP_NAMESPACE strstr(s, c) | |
40 | #define uprv_strrchr(s, c) U_STANDARD_CPP_NAMESPACE strrchr(s, c) | |
41 | ||
51004dcb A |
42 | #if U_DEBUG |
43 | ||
44 | #define uprv_strncpy(dst, src, size) ( \ | |
45 | uprv_checkValidMemory(src, 1), \ | |
46 | U_STANDARD_CPP_NAMESPACE strncpy(dst, src, size)) | |
47 | #define uprv_strncmp(s1, s2, n) ( \ | |
48 | uprv_checkValidMemory(s1, 1), \ | |
49 | uprv_checkValidMemory(s2, 1), \ | |
50 | U_STANDARD_CPP_NAMESPACE strncmp(s1, s2, n)) | |
51 | #define uprv_strncat(dst, src, n) ( \ | |
52 | uprv_checkValidMemory(src, 1), \ | |
53 | U_STANDARD_CPP_NAMESPACE strncat(dst, src, n)) | |
54 | ||
55 | #else | |
56 | ||
57 | #define uprv_strncpy(dst, src, size) U_STANDARD_CPP_NAMESPACE strncpy(dst, src, size) | |
58 | #define uprv_strncmp(s1, s2, n) U_STANDARD_CPP_NAMESPACE strncmp(s1, s2, n) | |
59 | #define uprv_strncat(dst, src, n) U_STANDARD_CPP_NAMESPACE strncat(dst, src, n) | |
60 | ||
61 | #endif /* U_DEBUG */ | |
62 | ||
4388f060 A |
63 | /** |
64 | * Is c an ASCII-repertoire letter a-z or A-Z? | |
65 | * Note: The implementation is specific to whether ICU is compiled for | |
66 | * an ASCII-based or EBCDIC-based machine. There just does not seem to be a better name for this. | |
67 | */ | |
68 | U_CAPI UBool U_EXPORT2 | |
69 | uprv_isASCIILetter(char c); | |
70 | ||
b75a7d8f A |
71 | U_CAPI char U_EXPORT2 |
72 | uprv_toupper(char c); | |
73 | ||
374ca955 A |
74 | |
75 | U_CAPI char U_EXPORT2 | |
76 | uprv_asciitolower(char c); | |
77 | ||
b75a7d8f | 78 | U_CAPI char U_EXPORT2 |
374ca955 A |
79 | uprv_ebcdictolower(char c); |
80 | ||
81 | #if U_CHARSET_FAMILY==U_ASCII_FAMILY | |
82 | # define uprv_tolower uprv_asciitolower | |
83 | #elif U_CHARSET_FAMILY==U_EBCDIC_FAMILY | |
84 | # define uprv_tolower uprv_ebcdictolower | |
85 | #else | |
86 | # error U_CHARSET_FAMILY is not valid | |
87 | #endif | |
b75a7d8f | 88 | |
374ca955 | 89 | #define uprv_strtod(source, end) U_STANDARD_CPP_NAMESPACE strtod(source, end) |
b75a7d8f A |
90 | #define uprv_strtoul(str, end, base) U_STANDARD_CPP_NAMESPACE strtoul(str, end, base) |
91 | #define uprv_strtol(str, end, base) U_STANDARD_CPP_NAMESPACE strtol(str, end, base) | |
b75a7d8f A |
92 | |
93 | /* Conversion from a digit to the character with radix base from 2-19 */ | |
94 | /* May need to use U_UPPER_ORDINAL*/ | |
95 | #define T_CString_itosOffset(a) ((a)<=9?('0'+(a)):('A'+(a)-10)) | |
96 | ||
97 | U_CAPI char* U_EXPORT2 | |
98 | uprv_strdup(const char *src); | |
99 | ||
374ca955 A |
100 | /** |
101 | * uprv_malloc n+1 bytes, and copy n bytes from src into the new string. | |
102 | * Terminate with a null at offset n. If n is -1, works like uprv_strdup | |
103 | * @param src | |
104 | * @param n length of the input string, not including null. | |
105 | * @return new string (owned by caller, use uprv_free to free). | |
106 | * @internal | |
107 | */ | |
108 | U_CAPI char* U_EXPORT2 | |
109 | uprv_strndup(const char *src, int32_t n); | |
110 | ||
b75a7d8f A |
111 | U_CAPI char* U_EXPORT2 |
112 | T_CString_toLowerCase(char* str); | |
113 | ||
114 | U_CAPI char* U_EXPORT2 | |
115 | T_CString_toUpperCase(char* str); | |
116 | ||
117 | U_CAPI int32_t U_EXPORT2 | |
118 | T_CString_integerToString(char *buffer, int32_t n, int32_t radix); | |
119 | ||
374ca955 A |
120 | U_CAPI int32_t U_EXPORT2 |
121 | T_CString_int64ToString(char *buffer, int64_t n, uint32_t radix); | |
122 | ||
b75a7d8f A |
123 | U_CAPI int32_t U_EXPORT2 |
124 | T_CString_stringToInteger(const char *integerString, int32_t radix); | |
125 | ||
4388f060 A |
126 | /** |
127 | * Case-insensitive, language-independent string comparison | |
128 | * limited to the ASCII character repertoire. | |
129 | */ | |
b75a7d8f | 130 | U_CAPI int U_EXPORT2 |
4388f060 | 131 | uprv_stricmp(const char *str1, const char *str2); |
b75a7d8f | 132 | |
4388f060 A |
133 | /** |
134 | * Case-insensitive, language-independent string comparison | |
135 | * limited to the ASCII character repertoire. | |
136 | */ | |
b75a7d8f | 137 | U_CAPI int U_EXPORT2 |
4388f060 | 138 | uprv_strnicmp(const char *str1, const char *str2, uint32_t n); |
b75a7d8f A |
139 | |
140 | #endif /* ! CSTRING_H */ |