diff options
Diffstat (limited to '')
-rw-r--r-- | libraries/eina/src/include/eina_unicode.h | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/libraries/eina/src/include/eina_unicode.h b/libraries/eina/src/include/eina_unicode.h new file mode 100644 index 0000000..aed59af --- /dev/null +++ b/libraries/eina/src/include/eina_unicode.h | |||
@@ -0,0 +1,177 @@ | |||
1 | #ifndef EINA_UNICODE_H | ||
2 | #define EINA_UNICODE_H | ||
3 | |||
4 | #include <stdlib.h> | ||
5 | |||
6 | #include "eina_config.h" | ||
7 | #include "eina_types.h" | ||
8 | |||
9 | /** | ||
10 | * @addtogroup Eina_Data_Types_Group Data Types | ||
11 | * | ||
12 | * @{ | ||
13 | */ | ||
14 | /** | ||
15 | * @addtogroup Eina_Unicode_String Unicode String | ||
16 | * | ||
17 | * @brief These functions provide basic unicode string handling | ||
18 | * | ||
19 | * Eina_Unicode is a type that holds unicode codepoints. | ||
20 | * | ||
21 | * @{ | ||
22 | */ | ||
23 | |||
24 | /** | ||
25 | * @typedef Eina_Unicode | ||
26 | * A type that holds Unicode codepoints. | ||
27 | */ | ||
28 | #if EINA_SIZEOF_WCHAR_T >= 4 | ||
29 | # include <wchar.h> | ||
30 | typedef wchar_t Eina_Unicode; | ||
31 | #elif defined(EINA_HAVE_INTTYPES_H) | ||
32 | # include <inttypes.h> | ||
33 | typedef uint32_t Eina_Unicode; | ||
34 | #elif defined(EINA_HAVE_STDINT_H) | ||
35 | # include <stdint.h> | ||
36 | typedef uint32_t Eina_Unicode; | ||
37 | #else | ||
38 | /* Hope that int is big enough */ | ||
39 | typedef unsigned int Eina_Unicode; | ||
40 | #endif | ||
41 | |||
42 | |||
43 | /** | ||
44 | * @brief Same as the standard strlen just with Eina_Unicode instead of char. | ||
45 | */ | ||
46 | EAPI extern const Eina_Unicode *EINA_UNICODE_EMPTY_STRING; | ||
47 | |||
48 | EAPI size_t eina_unicode_strlen(const Eina_Unicode *ustr) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
49 | |||
50 | /** | ||
51 | * @brief Returns the length of a Eina_Unicode string, up to a limit. | ||
52 | * | ||
53 | * This function returns the number of characters in string, up to a maximum | ||
54 | * of n. If the terminating character is not found in the string, it returns | ||
55 | * n. | ||
56 | * | ||
57 | * @param ustr String to search | ||
58 | * @param n Max length to search | ||
59 | * @return Number of characters or n. | ||
60 | */ | ||
61 | EAPI size_t eina_unicode_strnlen(const Eina_Unicode *ustr, int n) EINA_ARG_NONNULL(1) EINA_WARN_UNUSED_RESULT EINA_PURE; | ||
62 | |||
63 | |||
64 | /** | ||
65 | * @brief Same as the standard strdup just with Eina_Unicode instead of char. | ||
66 | */ | ||
67 | EAPI Eina_Unicode *eina_unicode_strdup(const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; | ||
68 | |||
69 | |||
70 | /** | ||
71 | * @brief Same as strdup but cuts on n. Assumes n < len | ||
72 | * @since 1.1.0 | ||
73 | */ | ||
74 | EAPI Eina_Unicode *eina_unicode_strndup(const Eina_Unicode *text, size_t n) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; | ||
75 | |||
76 | |||
77 | /** | ||
78 | * @brief Same as the standard strcmp just with Eina_Unicode instead of char. | ||
79 | */ | ||
80 | EAPI int eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE; | ||
81 | |||
82 | |||
83 | /** | ||
84 | * @brief Same as the standard strcpy just with Eina_Unicode instead of char. | ||
85 | */ | ||
86 | EAPI Eina_Unicode *eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) EINA_ARG_NONNULL(1, 2); | ||
87 | |||
88 | |||
89 | /** | ||
90 | * @brief Same as the standard strstr just with Eina_Unicode instead of char. | ||
91 | */ | ||
92 | EAPI Eina_Unicode *eina_unicode_strstr(const Eina_Unicode *haystack, const Eina_Unicode *needle) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE; | ||
93 | |||
94 | |||
95 | /** | ||
96 | * @brief Same as the standard strncpy just with Eina_Unicode instead of char. | ||
97 | */ | ||
98 | EAPI Eina_Unicode *eina_unicode_strncpy(Eina_Unicode *dest, const Eina_Unicode *source, size_t n) EINA_ARG_NONNULL(1, 2); | ||
99 | |||
100 | |||
101 | /** | ||
102 | * @see eina_str_escape() | ||
103 | */ | ||
104 | EAPI Eina_Unicode *eina_unicode_escape(const Eina_Unicode *str) EINA_ARG_NONNULL(1) EINA_MALLOC EINA_WARN_UNUSED_RESULT; | ||
105 | |||
106 | /* UTF-8 Handling */ | ||
107 | |||
108 | |||
109 | /** | ||
110 | * Reads UTF8 bytes from @buf, starting at *@index and returns | ||
111 | * the decoded code point at iindex offset, and advances iindex | ||
112 | * to the next code point after this. iindex is always advanced, | ||
113 | * unless if the advancement is after the NULL. | ||
114 | * On error: return a codepoint between DC80 to DCFF where the low 8 bits | ||
115 | * are the byte's value. | ||
116 | * | ||
117 | * @param buf the string | ||
118 | * @param iindex the index to look at and return by. | ||
119 | * @return the codepoint found. | ||
120 | * @since 1.1.0 | ||
121 | */ | ||
122 | EAPI Eina_Unicode eina_unicode_utf8_get_next(const char *buf, int *iindex) EINA_ARG_NONNULL(1, 2); | ||
123 | |||
124 | /** | ||
125 | * Reads UTF8 bytes from @buf, starting at *@iindex and returns | ||
126 | * the decoded code point at iindex offset, and moves iindex | ||
127 | * to the previous code point. iindex is always moved, as long | ||
128 | * as it's not past the start of the string. | ||
129 | * On error: return a codepoint between DC80 to DCFF where the low 8 bits | ||
130 | * are the byte's value. | ||
131 | * | ||
132 | * @param buf the string | ||
133 | * @param iindex the index to look at and return by. | ||
134 | * @return the codepoint found. | ||
135 | * @since 1.1.0 | ||
136 | */ | ||
137 | EAPI Eina_Unicode eina_unicode_utf8_get_prev(const char *buf, int *iindex) EINA_ARG_NONNULL(1, 2); | ||
138 | |||
139 | /** | ||
140 | * Returns the number of unicode characters in the string. That is, | ||
141 | * the number of Eina_Unicodes it'll take to store this string in | ||
142 | * an Eina_Unicode string. | ||
143 | * | ||
144 | * @param buf the string | ||
145 | * @return the number of unicode characters (not bytes) in the string | ||
146 | * @since 1.1.0 | ||
147 | */ | ||
148 | EAPI int eina_unicode_utf8_get_len(const char *buf) EINA_ARG_NONNULL(1); | ||
149 | |||
150 | /** | ||
151 | * Converts a utf-8 string to a newly allocated Eina_Unicode string. | ||
152 | * | ||
153 | * @param utf the string in utf-8 | ||
154 | * @param _len the length of the returned Eina_Unicode string. | ||
155 | * @return the newly allocated Eina_Unicode string. | ||
156 | * @since 1.1.0 | ||
157 | */ | ||
158 | EAPI Eina_Unicode *eina_unicode_utf8_to_unicode(const char *utf, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; | ||
159 | |||
160 | /** | ||
161 | * Converts an Eina_Unicode string to a newly allocated utf-8 string. | ||
162 | * | ||
163 | * @param uni the Eina_Unicode string | ||
164 | * @param _len the length byte length of the return utf8 string. | ||
165 | * @return the newly allocated utf-8 string. | ||
166 | * @since 1.1.0 | ||
167 | */ | ||
168 | EAPI char * eina_unicode_unicode_to_utf8(const Eina_Unicode *uni, int *_len) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC; | ||
169 | |||
170 | /** | ||
171 | * @} | ||
172 | */ | ||
173 | /** | ||
174 | * @} | ||
175 | */ | ||
176 | |||
177 | #endif | ||