| 1 |
/* |
| 2 |
* Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/> |
| 3 |
* (C) 2020 Vladimir Sadovnikov <[email protected]> |
| 4 |
* |
| 5 |
* This file is part of lsp-runtime-lib |
| 6 |
* Created on: 18 июн. 2018 г. |
| 7 |
* |
| 8 |
* lsp-runtime-lib is free software: you can redistribute it and/or modify |
| 9 |
* it under the terms of the GNU Lesser General Public License as published by |
| 10 |
* the Free Software Foundation, either version 3 of the License, or |
| 11 |
* any later version. |
| 12 |
* |
| 13 |
* lsp-runtime-lib is distributed in the hope that it will be useful, |
| 14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
* GNU Lesser General Public License for more details. |
| 17 |
* |
| 18 |
* You should have received a copy of the GNU Lesser General Public License |
| 19 |
* along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>. |
| 20 |
*/ |
| 21 |
|
| 22 |
#ifndef LSP_PLUG_IN_IO_CHARSET_H_ |
| 23 |
#define LSP_PLUG_IN_IO_CHARSET_H_ |
| 24 |
|
| 25 |
#include <lsp-plug.in/runtime/version.h> |
| 26 |
#include <lsp-plug.in/common/types.h> |
| 27 |
#include <lsp-plug.in/stdlib/string.h> |
| 28 |
|
| 29 |
#if defined(PLATFORM_WINDOWS) |
| 30 |
#else |
| 31 |
#include <iconv.h> |
| 32 |
#include <locale.h> |
| 33 |
#endif /* PLATFORM_WINDOWS */ |
| 34 |
|
| 35 |
#define LSP_UTF32_EOF lsp_utf32_t(-1) |
| 36 |
|
| 37 |
namespace lsp |
| 38 |
{ |
| 39 |
#if defined(PLATFORM_WINDOWS) |
| 40 |
typedef uint32_t LCID; |
| 41 |
|
| 42 |
ssize_t get_codepage(LCID locale, bool ansi = true); |
| 43 |
|
| 44 |
ssize_t codepage_from_name(const char *charset); |
| 45 |
|
| 46 |
/** |
| 47 |
* This is a MultiByteToWideChar wrapping function that handles additional cases |
| 48 |
* for non-MBCS encodings |
| 49 |
* |
| 50 |
* @param cp code page |
| 51 |
* @param src source buffer |
| 52 |
* @param nsrc number of bytes available in source buffer (will be updated on exit) |
| 53 |
* @param dst destination buffer (can be NULL for just estimating the length) |
| 54 |
* @param ndst number of characters in destination buffer (will be updated on exit, |
| 55 |
* can be NULL or point to zero value for just estimating the length) |
| 56 |
* @return number of UTF-16 characters written to destination buffer or negative error code |
| 57 |
*/ |
| 58 |
ssize_t multibyte_to_widechar(size_t cp, const char *src, size_t *nsrc, lsp_utf16_t *dst, size_t *ndst); |
| 59 |
|
| 60 |
/** |
| 61 |
* This is a WideCharToMultiByte wrapping function that handles additional cases |
| 62 |
* for non-MBCS encodings |
| 63 |
* |
| 64 |
* @param cp code page |
| 65 |
* @param src source wide string to perform encoding |
| 66 |
* @param nsrc number of characters available in source wide string (will be updated on exit) |
| 67 |
* @param dst target string to perform encoding (can be NULL for just estimating the length) |
| 68 |
* @param ndst number of bytes in destination buffer (will be updated on exit, |
| 69 |
* can be NULL or point to zero value for just estimating the length) |
| 70 |
* @return number of bytes written to destination buffer or negative error code |
| 71 |
*/ |
| 72 |
ssize_t widechar_to_multibyte(size_t cp, const lsp_utf16_t *src, size_t *nsrc, char *dst, size_t *ndst); |
| 73 |
#else |
| 74 |
|
| 75 |
iconv_t init_iconv_to_wchar_t(const char *charset); |
| 76 |
|
| 77 |
iconv_t init_iconv_from_wchar_t(const char *charset); |
| 78 |
|
| 79 |
#endif /* PLATFORM_WINDOWS */ |
| 80 |
|
| 81 |
/** |
| 82 |
* Read UTF-16 codepoint from the NULL-terminated UTF-16 string, replace invalid |
| 83 |
* code sequence by 0xfffd code point |
| 84 |
* @param str pointer to the NULL-terminated UTF-16 string |
| 85 |
* @return code point |
| 86 |
*/ |
| 87 |
lsp_utf32_t read_utf16le_codepoint(const lsp_utf16_t **str); |
| 88 |
lsp_utf32_t read_utf16be_codepoint(const lsp_utf16_t **str); |
| 89 |
inline lsp_utf32_t read_utf16_codepoint(const lsp_utf16_t **str) { return __IF_LEBE(read_utf16le_codepoint, read_utf16be_codepoint)(str); }; |
| 90 |
|
| 91 |
/** |
| 92 |
* Read UTF-16 codepoint from the NULL-terminated UTF-16 string in streaming mode, |
| 93 |
* replace invalid code sequence by 0xfffd code point |
| 94 |
* @param str pointer to the pointer to the NULL-terminated UTF-16 string |
| 95 |
* @param nsrc counter containing number of unread array elements |
| 96 |
* @param force process data as there will be no future data on the input |
| 97 |
* @return parsed code point or LSP_UTF32_EOF as end of sequence |
| 98 |
*/ |
| 99 |
lsp_utf32_t read_utf16le_streaming(const lsp_utf16_t **str, size_t *nsrc, bool force); |
| 100 |
lsp_utf32_t read_utf16be_streaming(const lsp_utf16_t **str, size_t *nsrc, bool force); |
| 101 |
inline lsp_utf32_t read_utf16_streaming(const lsp_utf16_t **str, size_t *nsrc, bool force) { return __IF_LEBE(read_utf16le_streaming, read_utf16be_streaming)(str, nsrc, force); } |
| 102 |
|
| 103 |
/** |
| 104 |
* Read UTF-16 codepoint from the NULL-terminated UTF-8 string, replace invalid |
| 105 |
* code sequence by 0xfffd code point |
| 106 |
* @param str pointer to the NULL-terminated UTF-8 string |
| 107 |
* @return code point |
| 108 |
*/ |
| 109 |
lsp_utf32_t read_utf8_codepoint(const char **str); |
| 110 |
|
| 111 |
/** |
| 112 |
* Read UTF-8 codepoint from the NULL-terminated UTF-8 string in streaming mode, |
| 113 |
* replace invalid code sequence by 0xfffd code point |
| 114 |
* @param str pointer to the pointer to the NULL-terminated UTF-8 string |
| 115 |
* @param nsrc counter containing number of unread array elements |
| 116 |
* @param force process data as there will be no future data on the input |
| 117 |
* @return parsed code point or LSP_UTF32_EOF as end of sequence |
| 118 |
*/ |
| 119 |
lsp_utf32_t read_utf8_streaming(const char **str, size_t *nsrc, bool force); |
| 120 |
|
| 121 |
/** |
| 122 |
* Write UTF-8 code point to buffer, buffer should be of enough size |
| 123 |
* @param str pointer to target buffer |
| 124 |
* @param cp code point to write |
| 125 |
*/ |
| 126 |
void write_utf8_codepoint(char **str, lsp_utf32_t cp); |
| 127 |
|
| 128 |
/** |
| 129 |
* Write UTF-16 code point to buffer, buffer should be of enough size |
| 130 |
* @param str pointer to target buffer |
| 131 |
* @param cp code point to write |
| 132 |
*/ |
| 133 |
void write_utf16le_codepoint(lsp_utf16_t **str, lsp_utf32_t cp); |
| 134 |
void write_utf16be_codepoint(lsp_utf16_t **str, lsp_utf32_t cp); |
| 135 |
inline void write_utf16_codepoint(lsp_utf16_t **str, lsp_utf32_t cp) { return __IF_LEBE(write_utf16le_codepoint, write_utf16be_codepoint)(str, cp); } |
| 136 |
|
| 137 |
/** |
| 138 |
* Encode NULL-terminated UTF-8 string to NULL-terminated UTF-16 string |
| 139 |
* @param str string to encode |
| 140 |
* @return pointer to allocated UTF-16 string that should be free()'d after use |
| 141 |
*/ |
| 142 |
lsp_utf16_t *utf8_to_utf16le(const char *str); |
| 143 |
lsp_utf16_t *utf8_to_utf16be(const char *str); |
| 144 |
inline lsp_utf16_t *utf8_to_utf16(const char *str) { return __IF_LEBE(utf8_to_utf16le, utf8_to_utf16be)(str); } |
| 145 |
|
| 146 |
/** |
| 147 |
* Encode NULL-terminated UTF-8 string to NULL-terminated UTF-16 string |
| 148 |
* @param dst destination buffer to store data |
| 149 |
* @param src string to encode |
| 150 |
* @param count number of elements available in destination buffer |
| 151 |
* @return number of elements produced (including zero-terminating character) or zero if there is not enough space |
| 152 |
*/ |
| 153 |
size_t utf8_to_utf16le(lsp_utf16_t *dst, const char *src, size_t count); |
| 154 |
size_t utf8_to_utf16be(lsp_utf16_t *dst, const char *src, size_t count); |
| 155 |
inline size_t utf8_to_utf16(lsp_utf16_t *dst, const char *src, size_t count) { return __IF_LEBE(utf8_to_utf16le, utf8_to_utf16be)(dst, src, count); } |
| 156 |
|
| 157 |
/** |
| 158 |
* Encode sequence of UTF-8 characters into sequence of UTF-16 characters |
| 159 |
* @param dst target buffer to store characters |
| 160 |
* @param ndst number of elements available in target buffer |
| 161 |
* @param src source buffer to read characters |
| 162 |
* @param nsrc number of elements available in source buffer |
| 163 |
* @param force force flag that treats the input block as last in the character sequence |
| 164 |
* @return number of processed code points |
| 165 |
*/ |
| 166 |
size_t utf8_to_utf16le(lsp_utf16_t *dst, size_t *ndst, const char *src, size_t *nsrc, bool force); |
| 167 |
size_t utf8_to_utf16be(lsp_utf16_t *dst, size_t *ndst, const char *src, size_t *nsrc, bool force); |
| 168 |
inline size_t utf8_to_utf16(lsp_utf16_t *dst, size_t *ndst, const char *src, size_t *nsrc, bool force) { return __IF_LEBE(utf8_to_utf16le, utf8_to_utf16be)(dst, ndst, src, nsrc, force); } |
| 169 |
|
| 170 |
/** |
| 171 |
* Encode NULL-terminated UTF-8 string to NULL-terminated UTF-32 string |
| 172 |
* @param str string to encode |
| 173 |
* @return pointer to allocated UTF-32 string that should be free()'d after use |
| 174 |
*/ |
| 175 |
lsp_utf32_t *utf8_to_utf32le(const char *str); |
| 176 |
lsp_utf32_t *utf8_to_utf32be(const char *str); |
| 177 |
inline lsp_utf32_t *utf8_to_utf32(const char *str) { return __IF_LEBE(utf8_to_utf32le, utf8_to_utf32be)(str); }; |
| 178 |
|
| 179 |
/** |
| 180 |
* Encode NULL-terminated UTF-8 string to NULL-terminated UTF-32 string |
| 181 |
* @param dst destination buffer to store data |
| 182 |
* @param src string to encode |
| 183 |
* @param count number of elements available in destination buffer |
| 184 |
* @return number of elements produced (including zero-terminating character) or negative value if there is not enough space |
| 185 |
*/ |
| 186 |
size_t utf8_to_utf32le(lsp_utf32_t *dst, const char *src, size_t count); |
| 187 |
size_t utf8_to_utf32be(lsp_utf32_t *dst, const char *src, size_t count); |
| 188 |
inline size_t utf8_to_utf32(lsp_utf32_t *dst, const char *src, size_t count) { return __IF_LEBE(utf8_to_utf32le, utf8_to_utf32be)(dst, src, count); } |
| 189 |
|
| 190 |
/** |
| 191 |
* Encode sequence of UTF-8 characters into sequence of UTF-32 characters |
| 192 |
* @param dst target buffer to store characters |
| 193 |
* @param ndst number of elements available in target buffer |
| 194 |
* @param src source buffer to read characters |
| 195 |
* @param nsrc number of elements available in source buffer |
| 196 |
* @param force force flag that treats the input block as last in the character sequence |
| 197 |
* @return number of processed code points |
| 198 |
*/ |
| 199 |
size_t utf8_to_utf32le(lsp_utf32_t *dst, size_t *ndst, const char *src, size_t *nsrc, bool force); |
| 200 |
size_t utf8_to_utf32be(lsp_utf32_t *dst, size_t *ndst, const char *src, size_t *nsrc, bool force); |
| 201 |
inline size_t utf8_to_utf32(lsp_utf32_t *dst, size_t *ndst, const char *src, size_t *nsrc, bool force) { return __IF_LEBE(utf8_to_utf32le, utf8_to_utf32be)(dst, ndst, src, nsrc, force); }; |
| 202 |
|
| 203 |
/** |
| 204 |
* Encode NULL-terminated UTF-16 string to NULL-terminated UTF-8 string |
| 205 |
* @param str string to encode |
| 206 |
* @return pointer to allocated UTF-8 string that should be free()'d after use |
| 207 |
*/ |
| 208 |
char *utf16le_to_utf8(const lsp_utf16_t *str); |
| 209 |
char *utf16be_to_utf8(const lsp_utf16_t *str); |
| 210 |
inline char *utf16_to_utf8(const lsp_utf16_t *str) { return __IF_LEBE(utf16le_to_utf8, utf16be_to_utf8)(str); }; |
| 211 |
|
| 212 |
/** |
| 213 |
* Encode NULL-terminated UTF-16 string to NULL-terminated UTF-8 string |
| 214 |
* @param dst destination buffer to store data |
| 215 |
* @param src string to encode |
| 216 |
* @param count number of elements available in destination buffer |
| 217 |
* @return number of elements produced (including zero-terminating character) or negative value if there is not enough space |
| 218 |
*/ |
| 219 |
size_t utf16le_to_utf8(char *dst, const lsp_utf16_t *src, size_t count); |
| 220 |
size_t utf16be_to_utf8(char *dst, const lsp_utf16_t *src, size_t count); |
| 221 |
inline size_t utf16_to_utf8(char *dst, const lsp_utf16_t *src, size_t count) { return __IF_LEBE(utf16le_to_utf8, utf16be_to_utf8)(dst, src, count); } |
| 222 |
|
| 223 |
/** |
| 224 |
* Encode sequence of UTF-16 characters into sequence of UTF-16 characters |
| 225 |
* @param dst target buffer to store characters |
| 226 |
* @param ndst number of elements available in target buffer |
| 227 |
* @param src source buffer to read characters |
| 228 |
* @param nsrc number of elements available in source buffer |
| 229 |
* @param force force flag that treats the input block as last in the character sequence |
| 230 |
* @return number of processed code points |
| 231 |
*/ |
| 232 |
size_t utf16le_to_utf8(char *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force); |
| 233 |
size_t utf16be_to_utf8(char *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force); |
| 234 |
inline size_t utf16_to_utf8(char *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf16le_to_utf8, utf16be_to_utf8)(dst, ndst, src, nsrc, force); }; |
| 235 |
|
| 236 |
/** |
| 237 |
* Encode NULL-terminated UTF-16 string to NULL-terminated UTF-32 string |
| 238 |
* @param str string to encode |
| 239 |
* @return pointer to allocated UTF-32 string that should be free()'d after use |
| 240 |
*/ |
| 241 |
lsp_utf32_t *utf16le_to_utf32le(const lsp_utf16_t *str); |
| 242 |
lsp_utf32_t *utf16le_to_utf32be(const lsp_utf16_t *str); |
| 243 |
lsp_utf32_t *utf16be_to_utf32le(const lsp_utf16_t *str); |
| 244 |
lsp_utf32_t *utf16be_to_utf32be(const lsp_utf16_t *str); |
| 245 |
|
| 246 |
inline lsp_utf32_t *utf16le_to_utf32(const lsp_utf16_t *str) { return __IF_LEBE(utf16le_to_utf32le, utf16le_to_utf32be)(str); } |
| 247 |
inline lsp_utf32_t *utf16be_to_utf32(const lsp_utf16_t *str) { return __IF_LEBE(utf16be_to_utf32le, utf16be_to_utf32be)(str); } |
| 248 |
inline lsp_utf32_t *utf16_to_utf32le(const lsp_utf16_t *str) { return __IF_LEBE(utf16le_to_utf32le, utf16be_to_utf32le)(str); } |
| 249 |
inline lsp_utf32_t *utf16_to_utf32be(const lsp_utf16_t *str) { return __IF_LEBE(utf16le_to_utf32be, utf16be_to_utf32be)(str); } |
| 250 |
inline lsp_utf32_t *utf16_to_utf32(const lsp_utf16_t *str) { return __IF_LEBE(utf16le_to_utf32le, utf16be_to_utf32be)(str); } |
| 251 |
|
| 252 |
/** |
| 253 |
* Encode NULL-terminated UTF-16 string to NULL-terminated UTF-32 string |
| 254 |
* @param dst destination buffer to store data |
| 255 |
* @param src string to encode |
| 256 |
* @param count number of elements available in destination buffer |
| 257 |
* @return number of elements produced (including zero-terminating character) or negative value if there is not enough space |
| 258 |
*/ |
| 259 |
size_t utf16le_to_utf32le(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count); |
| 260 |
size_t utf16le_to_utf32be(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count); |
| 261 |
size_t utf16be_to_utf32le(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count); |
| 262 |
size_t utf16be_to_utf32be(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count); |
| 263 |
|
| 264 |
inline size_t utf16le_to_utf32(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count) { return __IF_LEBE(utf16le_to_utf32le, utf16le_to_utf32be)(dst, src, count); } |
| 265 |
inline size_t utf16be_to_utf32(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count) { return __IF_LEBE(utf16be_to_utf32le, utf16be_to_utf32be)(dst, src, count); } |
| 266 |
inline size_t utf16_to_utf32le(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count) { return __IF_LEBE(utf16le_to_utf32le, utf16be_to_utf32le)(dst, src, count); } |
| 267 |
inline size_t utf16_to_utf32be(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count) { return __IF_LEBE(utf16le_to_utf32be, utf16be_to_utf32be)(dst, src, count); } |
| 268 |
inline size_t utf16_to_utf32(lsp_utf32_t *dst, const lsp_utf16_t *src, size_t count) { return __IF_LEBE(utf16le_to_utf32le, utf16be_to_utf32be)(dst, src, count); } |
| 269 |
|
| 270 |
/** |
| 271 |
* Encode sequence of UTF-16 characters into sequence of UTF-32 characters |
| 272 |
* @param dst target buffer to store characters |
| 273 |
* @param ndst number of elements available in target buffer |
| 274 |
* @param src source buffer to read characters |
| 275 |
* @param nsrc number of elements available in source buffer |
| 276 |
* @param force force flag that treats the input block as last in the character sequence |
| 277 |
* @return number of processed code points |
| 278 |
*/ |
| 279 |
size_t utf16le_to_utf32le(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force); |
| 280 |
size_t utf16le_to_utf32be(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force); |
| 281 |
size_t utf16be_to_utf32le(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force); |
| 282 |
size_t utf16be_to_utf32be(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force); |
| 283 |
|
| 284 |
inline size_t utf16le_to_utf32(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf16le_to_utf32le, utf16le_to_utf32be)(dst, ndst, src, nsrc, force); } |
| 285 |
inline size_t utf16be_to_utf32(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf16be_to_utf32le, utf16be_to_utf32be)(dst, ndst, src, nsrc, force); } |
| 286 |
inline size_t utf16_to_utf32le(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf16le_to_utf32le, utf16be_to_utf32le)(dst, ndst, src, nsrc, force); } |
| 287 |
inline size_t utf16_to_utf32be(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf16le_to_utf32be, utf16be_to_utf32be)(dst, ndst, src, nsrc, force); } |
| 288 |
inline size_t utf16_to_utf32(lsp_utf32_t *dst, size_t *ndst, const lsp_utf16_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf16le_to_utf32le, utf16be_to_utf32be)(dst, ndst, src, nsrc, force); } |
| 289 |
|
| 290 |
/** |
| 291 |
* Encode NULL-terminated UTF-32 string to NULL-terminated UTF-8 string |
| 292 |
* @param str string to encode |
| 293 |
* @return pointer to allocated UTF-16 string that should be free()'d after use |
| 294 |
*/ |
| 295 |
char *utf32le_to_utf8(const lsp_utf32_t *str); |
| 296 |
char *utf32be_to_utf8(const lsp_utf32_t *str); |
| 297 |
inline char *utf32_to_utf8(const lsp_utf32_t *str) { return __IF_LEBE(utf32le_to_utf8, utf32be_to_utf8)(str); }; |
| 298 |
|
| 299 |
/** |
| 300 |
* Encode NULL-terminated UTF-32 string to NULL-terminated UTF-8 string |
| 301 |
* @param dst destination buffer to store data |
| 302 |
* @param src string to encode |
| 303 |
* @param count number of elements available in destination buffer |
| 304 |
* @return number of elements produced (including zero-terminating character) or negative value if there is not enough space |
| 305 |
*/ |
| 306 |
size_t utf32le_to_utf8(char *dst, const lsp_utf32_t *src, size_t count); |
| 307 |
size_t utf32be_to_utf8(char *dst, const lsp_utf32_t *src, size_t count); |
| 308 |
inline size_t utf32_to_utf8(char *dst, const lsp_utf32_t *src, size_t count) { return __IF_LEBE(utf32le_to_utf8, utf32be_to_utf8)(dst, src, count); }; |
| 309 |
|
| 310 |
/** |
| 311 |
* Encode sequence of UTF-8 characters into sequence of UTF-16 characters |
| 312 |
* @param dst target buffer to store characters |
| 313 |
* @param ndst number of elements available in target buffer |
| 314 |
* @param src source buffer to read characters |
| 315 |
* @param nsrc number of elements available in source buffer |
| 316 |
* @param force force flag that treats the input block as last in the character sequence |
| 317 |
* @return number of processed code points |
| 318 |
*/ |
| 319 |
size_t utf32le_to_utf8(char *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force); |
| 320 |
size_t utf32be_to_utf8(char *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force); |
| 321 |
inline size_t utf32_to_utf8(char *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf32le_to_utf8, utf32be_to_utf8)(dst, ndst, src, nsrc, force); } |
| 322 |
|
| 323 |
/** |
| 324 |
* Encode NULL-terminated UTF-32 string to NULL-terminated UTF-16 string |
| 325 |
* @param str string to encode |
| 326 |
* @return pointer to allocated UTF-16 string that should be free()'d after use |
| 327 |
*/ |
| 328 |
lsp_utf16_t *utf32le_to_utf16le(const lsp_utf32_t *str); |
| 329 |
lsp_utf16_t *utf32le_to_utf16be(const lsp_utf32_t *str); |
| 330 |
lsp_utf16_t *utf32be_to_utf16le(const lsp_utf32_t *str); |
| 331 |
lsp_utf16_t *utf32be_to_utf16be(const lsp_utf32_t *str); |
| 332 |
|
| 333 |
inline lsp_utf16_t *utf32le_to_utf16(const lsp_utf32_t *str) { return __IF_LEBE(utf32le_to_utf16le, utf32le_to_utf16be)(str); } |
| 334 |
inline lsp_utf16_t *utf32be_to_utf16(const lsp_utf32_t *str) { return __IF_LEBE(utf32be_to_utf16le, utf32be_to_utf16be)(str); } |
| 335 |
inline lsp_utf16_t *utf32_to_utf16le(const lsp_utf32_t *str) { return __IF_LEBE(utf32le_to_utf16le, utf32be_to_utf16le)(str); } |
| 336 |
inline lsp_utf16_t *utf32_to_utf16be(const lsp_utf32_t *str) { return __IF_LEBE(utf32le_to_utf16be, utf32be_to_utf16be)(str); } |
| 337 |
inline lsp_utf16_t *utf32_to_utf16(const lsp_utf32_t *str) { return __IF_LEBE(utf32le_to_utf16le, utf32be_to_utf16be)(str); } |
| 338 |
|
| 339 |
/** |
| 340 |
* Encode NULL-terminated UTF-32 string to NULL-terminated UTF-16 string |
| 341 |
* @param dst destination buffer to store data |
| 342 |
* @param src string to encode |
| 343 |
* @param count number of elements available in destination buffer |
| 344 |
* @return number of elements produced (including zero-terminating character) or negative value if there is not enough space |
| 345 |
*/ |
| 346 |
size_t utf32le_to_utf16le(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count); |
| 347 |
size_t utf32le_to_utf16be(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count); |
| 348 |
size_t utf32be_to_utf16le(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count); |
| 349 |
size_t utf32be_to_utf16be(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count); |
| 350 |
|
| 351 |
inline size_t utf32le_to_utf16(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count) { return __IF_LEBE(utf32le_to_utf16le, utf32le_to_utf16be)(dst, src, count); } |
| 352 |
inline size_t utf32be_to_utf16(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count) { return __IF_LEBE(utf32be_to_utf16le, utf32be_to_utf16be)(dst, src, count); } |
| 353 |
inline size_t utf32_to_utf16le(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count) { return __IF_LEBE(utf32le_to_utf16le, utf32be_to_utf16le)(dst, src, count); } |
| 354 |
inline size_t utf32_to_utf16be(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count) { return __IF_LEBE(utf32le_to_utf16be, utf32be_to_utf16be)(dst, src, count); } |
| 355 |
inline size_t utf32_to_utf16(lsp_utf16_t *dst, const lsp_utf32_t *src, size_t count) { return __IF_LEBE(utf32le_to_utf16le, utf32be_to_utf16be)(dst, src, count); } |
| 356 |
|
| 357 |
/** |
| 358 |
* Encode sequence of UTF-8 characters into sequence of UTF-16 characters |
| 359 |
* @param dst target buffer to store characters |
| 360 |
* @param ndst number of elements available in target buffer |
| 361 |
* @param src source buffer to read characters |
| 362 |
* @param nsrc number of elements available in source buffer |
| 363 |
* @param force force flag that treats the input block as last in the character sequence |
| 364 |
* @return number of processed code points |
| 365 |
*/ |
| 366 |
size_t utf32le_to_utf16le(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force); |
| 367 |
size_t utf32le_to_utf16be(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force); |
| 368 |
size_t utf32be_to_utf16le(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force); |
| 369 |
size_t utf32be_to_utf16be(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force); |
| 370 |
|
| 371 |
inline size_t utf32_to_utf16le(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf32le_to_utf16le, utf32be_to_utf16le)(dst, ndst, src, nsrc, force); } |
| 372 |
inline size_t utf32_to_utf16be(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf32le_to_utf16be, utf32be_to_utf16be)(dst, ndst, src, nsrc, force); } |
| 373 |
inline size_t utf32le_to_utf16(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf32le_to_utf16le, utf32le_to_utf16be)(dst, ndst, src, nsrc, force); } |
| 374 |
inline size_t utf32be_to_utf16(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf32be_to_utf16le, utf32be_to_utf16be)(dst, ndst, src, nsrc, force); } |
| 375 |
inline size_t utf32_to_utf16(lsp_utf16_t *dst, size_t *ndst, const lsp_utf32_t *src, size_t *nsrc, bool force) { return __IF_LEBE(utf32le_to_utf16le, utf32be_to_utf16be)(dst, ndst, src, nsrc, force); } |
| 376 |
|
| 377 |
/** |
| 378 |
* Compare two character sequences. |
| 379 |
* @param s1 character sequence 1 |
| 380 |
* @param s2 character sequence 2 |
| 381 |
* @param count number of characters to compare, you must be sure that both sequences have at least count characters |
| 382 |
* @return comparison result |
| 383 |
*/ |
| 384 |
#ifdef ARCH_LE |
| 385 |
inline int wchar_cmp(const lsp_wchar_t *s1, const lsp_wchar_t *s2, size_t count) { return ::memcmp(s1, s2, count * sizeof(lsp_wchar_t)); } |
| 386 |
#else |
| 387 |
int wchar_cmp(const lsp_wchar_t *s1, const lsp_wchar_t *s2, size_t count); |
| 388 |
#endif |
| 389 |
|
| 390 |
int wchar_casecmp(const lsp_wchar_t *s1, const lsp_wchar_t *s2, size_t count); |
| 391 |
|
| 392 |
/** |
| 393 |
* Convert character to lower case |
| 394 |
* @param c character to convert |
| 395 |
* @return converted character |
| 396 |
*/ |
| 397 |
lsp_wchar_t to_lower(lsp_wchar_t c); |
| 398 |
|
| 399 |
/** |
| 400 |
* Convert character to upper case |
| 401 |
* @param c character to convert |
| 402 |
* @return converted character |
| 403 |
*/ |
| 404 |
lsp_wchar_t to_upper(lsp_wchar_t c); |
| 405 |
|
| 406 |
} /* namespace lsp */ |
| 407 |
|
| 408 |
#endif /* LSP_PLUG_IN_IO_CHARSET_H_ */ |