1 #include <unicode/ustring.h>
2 #include <unicode/uchar.h>
4 static inline UChar
*utf8_to_utf16(const char *str
, int32_t *length
)
7 UErrorCode status
= U_ZERO_ERROR
;
9 u_strFromUTF8(NULL
, 0, length
, str
, -1, &status
);
10 status
= U_ZERO_ERROR
;
11 (*length
)++; /* for the NUL char */
12 ustr
= malloc(sizeof(UChar
) * (*length
));
15 u_strFromUTF8(ustr
, *length
, NULL
, str
, -1, &status
);
16 if (U_FAILURE(status
)) {
23 static inline char *utf16_to_utf8(UChar
*ustr
, int32_t *length
)
26 UErrorCode status
= U_ZERO_ERROR
;
28 u_strToUTF8(NULL
, 0, length
, ustr
, -1, &status
);
29 status
= U_ZERO_ERROR
;
30 (*length
)++; /* for the NUL char */
31 str
= malloc(*length
);
34 u_strToUTF8(str
, *length
, NULL
, ustr
, -1, &status
);
35 if (U_FAILURE(status
)) {
42 static inline bool str_contains_upper(const char *s
)
47 UChar
*ustr
= utf8_to_utf16(s
, &length
);
50 for (i
= 0; i
< length
; /* U16_NEXT post-increments */) {
51 U16_NEXT(ustr
, i
, length
, c
);
62 static inline char *str_fold(const char *s
)
67 UErrorCode status
= U_ZERO_ERROR
;
69 ustr
= utf8_to_utf16(s
, &length
);
72 u_strFoldCase(ustr
, length
, ustr
, length
, U_FOLD_CASE_EXCLUDE_SPECIAL_I
, &status
);
73 if (U_FAILURE(status
))
75 str
= utf16_to_utf8(ustr
, &length
);