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)
128 # include <CoreFoundation/CFString.h>
133 VLC_USED static inline char *FromCFString(
const CFStringRef cfString,
134 const CFStringEncoding cfStringEncoding)
137 const char *tmpBuffer = CFStringGetCStringPtr(cfString, cfStringEncoding);
139 if (tmpBuffer != NULL) {
144 CFIndex length = CFStringGetLength(cfString);
146 CFStringGetMaximumSizeForEncoding(length, cfStringEncoding);
149 if (
unlikely(maxSize == kCFNotFound)) {
156 char *buffer = (
char *)malloc(maxSize);
163 Boolean success = CFStringGetCString(cfString, buffer, maxSize, cfStringEncoding);
173 static inline char *FromWide (
const wchar_t *wide)
175 size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
179 char *out = (
char *)malloc (len);
182 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
187 static inline wchar_t *ToWide (
const char *utf8)
189 int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
193 wchar_t *out = (
wchar_t *)malloc (len *
sizeof (
wchar_t));
196 MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len);
201 static inline char *ToCodePage (
unsigned cp,
const char *utf8)
203 wchar_t *wide = ToWide (utf8);
207 size_t len = WideCharToMultiByte (cp, 0, wide, -1, NULL, 0, NULL, NULL);
213 char *out = (
char *)malloc (len);
215 WideCharToMultiByte (cp, 0, wide, -1, out, len, NULL, NULL);
221 static inline char *FromCodePage (
unsigned cp,
const char *mb)
223 int len = MultiByteToWideChar (cp, 0, mb, -1, NULL, 0);
227 wchar_t *wide = (
wchar_t *)malloc (len *
sizeof (
wchar_t));
230 MultiByteToWideChar (cp, 0, mb, -1, wide, len);
232 char *utf8 = FromWide (wide);
238 static inline char *FromANSI (
const char *ansi)
240 return FromCodePage (GetACP (), ansi);
244 static inline char *ToANSI (
const char *utf8)
246 return ToCodePage (GetACP (), utf8);
250 # define FromT FromWide
253 # define FromT FromANSI
256 # define FromLocale FromANSI
257 # define ToLocale ToANSI
258 # define LocaleFree(s) free((char *)(s))
259 # define FromLocaleDup FromANSI
260 # define ToLocaleDup ToANSI
262 #elif defined(__OS2__)
266 return locale ?
FromCharset ((
char *)
"", locale, strlen(locale)) : NULL;
272 return utf8 ? (
char *)
ToCharset (
"", utf8, &outsize) : NULL;
288 return (
char *)
ToCharset (
"", utf8, &outsize);
293 # define FromLocale(l) (l)
294 # define ToLocale(u) (u)
295 # define LocaleFree(s) ((void)(s))
296 # define FromLocaleDup strdup
297 # define ToLocaleDup strdup
305 char *str = (
char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
311 while ((c = *(latin++)) !=
'\0')
315 *(utf8++) = 0xC0 | (c >> 6);
316 *(utf8++) = 0x80 | (c & 0x3F);
323 utf8 = (
char *)realloc (str, utf8 - str);
324 return utf8 ? utf8 : str;
#define LocaleFree(s)
Definition: vlc_charset.h:295
#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:296
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:293
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:303
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:297
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 FREENULL(a)
Definition: vlc_common.h:770
char * strdup(const char *)
#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:294