25#define VLC_CHARSET_H 1
67 while ((n =
vlc_towc(str, &cp)) != 0)
90 for (
const char *
p = str; (c = *
p) !=
'\0';
p++)
120 while ((n =
vlc_towc(str, &cp)) != 0)
138#define VLC_ICONV_ERR ((size_t) -1)
156# include <CoreFoundation/CoreFoundation.h>
161VLC_USED static inline char *FromCFString(
const CFStringRef cfString,
162 const CFStringEncoding cfStringEncoding)
165 const char *tmpBuffer = CFStringGetCStringPtr(cfString, cfStringEncoding);
167 if (tmpBuffer != NULL) {
172 CFIndex length = CFStringGetLength(cfString);
174 CFStringGetMaximumSizeForEncoding(length, cfStringEncoding);
177 if (
unlikely(maxSize == kCFNotFound)) {
184 char *buffer = (
char *)malloc(maxSize);
191 Boolean success = CFStringGetCString(cfString, buffer, maxSize, cfStringEncoding);
203static inline char *FromWide (
const wchar_t *wide)
205 size_t len = WideCharToMultiByte (CP_UTF8, 0, wide, -1, NULL, 0, NULL, NULL);
209 char *out = (
char *)malloc (len);
212 WideCharToMultiByte (CP_UTF8, 0, wide, -1, out, len, NULL, NULL);
217static inline wchar_t *ToWide (
const char *utf8)
219 int len = MultiByteToWideChar (CP_UTF8, 0, utf8, -1, NULL, 0);
223 wchar_t *out = (
wchar_t *)malloc (len *
sizeof (
wchar_t));
226 MultiByteToWideChar (CP_UTF8, 0, utf8, -1, out, len);
231static inline char *ToCodePage (
unsigned cp,
const char *utf8)
233 wchar_t *wide = ToWide (utf8);
237 size_t len = WideCharToMultiByte (cp, 0, wide, -1, NULL, 0, NULL, NULL);
243 char *out = (
char *)malloc (len);
245 WideCharToMultiByte (cp, 0, wide, -1, out, len, NULL, NULL);
251static inline char *FromCodePage (
unsigned cp,
const char *mb)
253 int len = MultiByteToWideChar (cp, 0, mb, -1, NULL, 0);
257 wchar_t *wide = (
wchar_t *)malloc (len *
sizeof (
wchar_t));
260 MultiByteToWideChar (cp, 0, mb, -1, wide, len);
262 char *utf8 = FromWide (wide);
268static inline char *FromANSI (
const char *ansi)
270 return FromCodePage (GetACP (), ansi);
274static inline char *ToANSI (
const char *utf8)
276 return ToCodePage (GetACP (), utf8);
279# define FromLocale FromANSI
280# define ToLocale ToANSI
281# define LocaleFree(s) free((char *)(s))
282# define FromLocaleDup FromANSI
283# define ToLocaleDup ToANSI
285#elif defined(__OS2__)
289 return locale ?
FromCharset ((
char *)
"", locale, strlen(locale)) : NULL;
295 return utf8 ? (
char *)
ToCharset (
"", utf8, &outsize) : NULL;
311 return (
char *)
ToCharset (
"", utf8, &outsize);
316# define FromLocale(l) (l)
317# define ToLocale(u) (u)
318# define LocaleFree(s) ((void)(s))
319# define FromLocaleDup strdup
320# define ToLocaleDup strdup
326static inline char *
FromLatin1 (
const char *latin)
328 char *str = (
char *)malloc (2 * strlen (latin) + 1), *utf8 = str;
334 while ((c = *(latin++)) !=
'\0')
338 *(utf8++) = 0xC0 | (c >> 6);
339 *(utf8++) = 0x80 | (c & 0x3F);
346 utf8 = (
char *)realloc (str, utf8 - str);
347 return utf8 ? utf8 : str;
467__attribute__((format(scanf, 2, 3)))
#define VLC_USED
Definition fourcc_gen.c:32
#define VLC_API
Definition fourcc_gen.c:31
double vlc_strtod_c(const char *restrict str, char **restrict end)
Parses a double in C locale.
Definition charset.c:46
static double vlc_atof_c(const char *str)
Parses a double in C locale.
Definition vlc_charset.h:399
int vlc_sscanf_c(const char *, const char *,...)
int vlc_asprintf_c(char **p, const char *fmt,...)
Formats a string using the C locale.
int vlc_fprintf_c(FILE *f, const char *fmt,...)
Write a string to the output using the C locale.
int vlc_vasprintf_c(char **restrict p, const char *restrict fmt, va_list ap)
Formats a string using the C locale.
Definition charset.c:74
float vlc_strtof_c(const char *restrict str, char **restrict end)
Parses a float in C locale.
Definition charset.c:60
int vlc_vfprintf_c(FILE *f, const char *fmt, va_list ap)
Write a string to the output using the C locale.
Definition charset.c:103
int vlc_vsscanf_c(const char *, const char *, va_list)
#define unlikely(p)
Predicted false condition.
Definition vlc_common.h:246
#define VLC_MALLOC
Definition vlc_common.h:157
#define likely(p)
Predicted true condition.
Definition vlc_common.h:237
#define VLC_FORMAT(x, y)
String format function annotation.
Definition vlc_common.h:193
char * vlc_strcasestr(const char *, const char *)
Look for an UTF-8 string within another one in a case-insensitive fashion.
Definition unicode.c:191
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:274
static char * EnsureUTF8(char *str)
Removes non-UTF-8 sequences.
Definition vlc_charset.h:115
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:232
static const char * IsUTF8(const char *str)
Checks UTF-8 validity.
Definition vlc_charset.h:63
#define ToLocaleDup
Definition vlc_charset.h:321
#define ToLocale(u)
Definition vlc_charset.h:318
#define LocaleFree(s)
Definition vlc_charset.h:319
ssize_t vlc_towc(const char *str, uint32_t *restrict pwc)
Decodes a code point from UTF-8.
Definition unicode.c:115
static char * FromLatin1(const char *latin)
Converts a nul-terminated string from ISO-8859-1 to UTF-8.
Definition vlc_charset.h:327
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:52
#define FromLocaleDup
Definition vlc_charset.h:320
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:104
static const char * IsASCII(const char *str)
Checks ASCII validity.
Definition vlc_charset.h:87
#define FromLocale(l)
Definition vlc_charset.h:317
void * vlc_iconv_t
Definition vlc_charset.h:140
size_t vlc_iconv(vlc_iconv_t, const char **, size_t *, char **, size_t *)
int vlc_iconv_close(vlc_iconv_t)
vlc_iconv_t vlc_iconv_open(const char *, const char *)
This file is a collection of common definitions and types.
#define FREENULL(a)
Definition vlc_common.h:901
char * strdup(const char *)