1 #ifndef _WIMLIB_ENCODING_H
2 #define _WIMLIB_ENCODING_H
6 #include "wimlib/error.h"
7 #include "wimlib/util.h"
8 #include "wimlib/types.h"
11 iconv_global_init(void);
14 iconv_global_cleanup(void);
19 extern bool wimlib_mbs_is_utf8;
21 #define DECLARE_CHAR_CONVERSION_FUNCTIONS(varname1, varname2, \
22 chartype1, chartype2) \
25 varname1##_to_##varname2(const chartype1 *in, size_t in_nbytes, \
26 chartype2 **out_ret, \
27 size_t *out_nbytes_ret); \
30 varname1##_to_##varname2##_nbytes(const chartype1 *in, size_t in_nbytes,\
31 size_t *out_nbytes_ret); \
34 varname1##_to_##varname2##_buf(const chartype1 *in, size_t in_nbytes, \
38 utf16le_dupz(const void *ustr, size_t usize);
41 utf16le_dup(const utf16lechar *ustr);
44 utf16le_len_bytes(const utf16lechar *s);
47 utf16le_len_chars(const utf16lechar *s);
50 DECLARE_CHAR_CONVERSION_FUNCTIONS(utf16le, tstr, utf16lechar, tchar);
51 DECLARE_CHAR_CONVERSION_FUNCTIONS(tstr, utf16le, tchar, utf16lechar);
55 tstr_to_utf16le(const tchar *tstr, size_t tsize,
56 utf16lechar **ustr_ret, size_t *usize_ret)
58 utf16lechar *ustr = utf16le_dupz(tstr, tsize);
60 return WIMLIB_ERR_NOMEM;
66 #define utf16le_to_tstr tstr_to_utf16le
70 DECLARE_CHAR_CONVERSION_FUNCTIONS(utf8, tstr, char, tchar);
71 DECLARE_CHAR_CONVERSION_FUNCTIONS(tstr, utf8, tchar, char);
74 utf8_to_tstr_simple(const char *utf8str, tchar **out);
77 tstr_to_utf8_simple(const tchar *tstr, char **out);
80 cmp_utf16le_strings(const utf16lechar *s1, size_t n1,
81 const utf16lechar *s2, size_t n2,
85 cmp_utf16le_strings_z(const utf16lechar *s1, const utf16lechar *s2,
88 /* Convert a string in the platform-dependent encoding to UTF-16LE, but if both
89 * encodings are UTF-16LE, simply re-use the string. Release with
90 * tstr_put_utf16le() when done. */
92 tstr_get_utf16le_and_len(const tchar *tstr,
93 const utf16lechar **ustr_ret, size_t *usize_ret)
95 size_t tsize = tstrlen(tstr) * sizeof(tchar);
97 /* No conversion or copy needed */
102 return tstr_to_utf16le(tstr, tsize, (utf16lechar **)ustr_ret, usize_ret);
106 /* Convert a string in the platform-dependent encoding to UTF-16LE, but if both
107 * encodings are UTF-16LE, simply re-use the string. Release with
108 * tstr_put_utf16le() when done. */
110 tstr_get_utf16le(const tchar *tstr, const utf16lechar **ustr_ret)
113 /* No conversion or copy needed */
117 size_t tsize = tstrlen(tstr) * sizeof(tchar);
119 return tstr_to_utf16le(tstr, tsize, (utf16lechar **)ustr_ret, &dummy);
123 /* Release a string acquired with tstr_get_utf16le() or
124 * tstr_get_utf16le_and_len(). */
126 tstr_put_utf16le(const utf16lechar *ustr)
128 #if !TCHAR_IS_UTF16LE
133 /* Convert a UTF16-LE string to the platform-dependent encoding, but if both
134 * encodings are UTF-16LE, simply re-use the string. Release with
135 * utf16le_put_tstr() when done. */
137 utf16le_get_tstr(const utf16lechar *ustr, size_t usize,
138 const tchar **tstr_ret, size_t *tsize_ret)
141 /* No conversion or copy needed */
146 return utf16le_to_tstr(ustr, usize, (tchar **)tstr_ret, tsize_ret);
150 /* Release a string acquired with utf16le_get_tstr(). */
152 utf16le_put_tstr(const tchar *tstr)
154 #if !TCHAR_IS_UTF16LE
159 #endif /* _WIMLIB_ENCODING_H */