Go to the documentation of this file.
26 #define VLC_CHARSET_H 1
68 while ((n =
vlc_towc(str, &cp)) != 0)
69 if (
likely(n != (
size_t)-1))
100 while ((n =
vlc_towc(str, &cp)) != 0)
101 if (
likely(n != (
size_t)-1))
112 #define VLC_ICONV_ERR ((size_t) -1)
129 static inline char *FromWide (
const wchar_t *wide)
131 size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
135 char *out = (
char *)malloc (len);
138 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
143 static inline wchar_t *ToWide (
const char *utf8)
145 int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
149 wchar_t *out = (
wchar_t *)malloc (len *
sizeof (
wchar_t));
152 MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len);
157 static inline char *ToCodePage (
unsigned cp,
const char *utf8)
159 wchar_t *wide = ToWide (utf8);
163 size_t len = WideCharToMultiByte (cp, 0, wide, -1, NULL, 0, NULL, NULL);
169 char *out = (
char *)malloc (len);
171 WideCharToMultiByte (cp, 0, wide, -1, out, len, NULL, NULL);
177 static inline char *FromCodePage (
unsigned cp,
const char *mb)
179 int len = MultiByteToWideChar (cp, 0, mb, -1, NULL, 0);
183 wchar_t *wide = (
wchar_t *)malloc (len *
sizeof (
wchar_t));
186 MultiByteToWideChar (cp, 0, mb, -1, wide, len);
188 char *utf8 = FromWide (wide);
194 static inline char *FromANSI (
const char *ansi)
196 return FromCodePage (GetACP (), ansi);
200 static inline char *ToANSI (
const char *utf8)
202 return ToCodePage (GetACP (), utf8);
206 # define FromT FromWide
209 # define FromT FromANSI
212 # define FromLocale FromANSI
213 # define ToLocale ToANSI
214 # define LocaleFree(s) free((char *)(s))
215 # define FromLocaleDup FromANSI
216 # define ToLocaleDup ToANSI
218 #elif defined(__OS2__)
222 return locale ?
FromCharset ((
char *)
"", locale, strlen(locale)) : NULL;
228 return utf8 ? (
char *)
ToCharset (
"", utf8, &outsize) : NULL;
244 return (
char *)
ToCharset (
"", utf8, &outsize);
249 # define FromLocale(l) (l)
250 # define ToLocale(u) (u)
251 # define LocaleFree(s) ((void)(s))
252 # define FromLocaleDup strdup
253 # define ToLocaleDup strdup
261 char *str = (
char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
267 while ((c = *(latin++)) !=
'\0')
271 *(utf8++) = 0xC0 | (c >> 6);
272 *(utf8++) = 0x80 | (c & 0x3F);
279 utf8 = (
char *)realloc (str, utf8 - str);
280 return utf8 ? utf8 : str;
#define LocaleFree(s)
Definition: vlc_charset.h:251
#define VLC_FORMAT(x, y)
Definition: vlc_common.h:100
#define VLC_API
Definition: fourcc_gen.c:30
size_t vlc_iconv(vlc_iconv_t, const char **, size_t *, char **, size_t *)
double us_atof(const char *)
us_atof() has the same prototype as ANSI C atof() but it expects a dot as decimal separator,...
Definition: charset.c:87
#define FromLocaleDup
Definition: vlc_charset.h:252
char * vlc_strcasestr(const char *, const char *)
Look for an UTF-8 string within another one in a case-insensitive fashion.
Definition: unicode.c:196
int us_vasprintf(char **, const char *, va_list)
us_vasprintf() has the same prototype as vasprintf(), but doesn't use the system locale.
Definition: charset.c:97
#define FromLocale(l)
Definition: vlc_charset.h:249
int us_asprintf(char **, const char *,...)
us_asprintf() has the same prototype as asprintf(), but doesn't use the system locale.
Definition: charset.c:118
char * FromCharset(const char *charset, const void *data, size_t data_size)
Converts a string from the given character encoding to utf-8.
Definition: unicode.c:235
void * vlc_iconv_t
Definition: vlc_charset.h:113
static char * FromLatin1(const char *latin)
Converts a nul-terminated string from ISO-8859-1 to UTF-8.
Definition: vlc_charset.h:259
float us_strtof(const char *, char **)
us_strtof() has the same prototype as ANSI C strtof() but it uses the POSIX/C decimal format,...
Definition: charset.c:68
void * ToCharset(const char *charset, const char *in, size_t *outsize)
Converts a nul-terminated UTF-8 string to a given character encoding.
Definition: unicode.c:277
#define ToLocaleDup
Definition: vlc_charset.h:253
vlc_iconv_t vlc_iconv_open(const char *, const char *)
int utf8_vfprintf(FILE *stream, const char *fmt, va_list ap)
Formats an UTF-8 string as vfprintf(), then print it, with appropriate conversion to local encoding.
Definition: unicode.c:50
int utf8_fprintf(FILE *, const char *,...)
Formats an UTF-8 string as fprintf(), then print it, with appropriate conversion to local encoding.
Definition: unicode.c:100
double us_strtod(const char *, char **)
us_strtod() has the same prototype as ANSI C strtod() but it uses the POSIX/C decimal format,...
Definition: charset.c:49
size_t vlc_towc(const char *str, uint32_t *restrict pwc)
Decodes a code point from UTF-8.
Definition: unicode.c:111
#define likely(p)
Definition: vlc_common.h:113
static char * EnsureUTF8(char *str)
Removes non-UTF-8 sequences.
Definition: vlc_charset.h:94
#define VLC_USED
Definition: fourcc_gen.c:31
int vlc_iconv_close(vlc_iconv_t)
#define VLC_MALLOC
Definition: vlc_common.h:102
#define unlikely(p)
Definition: vlc_common.h:114
static const char * IsUTF8(const char *str)
Checks UTF-8 validity.
Definition: vlc_charset.h:63
#define ToLocale(u)
Definition: vlc_charset.h:250