Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-2-2
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc-2-2
Commits
d303d6a8
Commit
d303d6a8
authored
Jul 18, 2010
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Unicode: refactor, no functional changes
parent
9164192f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
50 deletions
+48
-50
src/text/unicode.c
src/text/unicode.c
+48
-50
No files found.
src/text/unicode.c
View file @
d303d6a8
...
@@ -49,20 +49,37 @@
...
@@ -49,20 +49,37 @@
#if defined (ASSUME_UTF8)
#if defined (ASSUME_UTF8)
/* Cool */
/* Cool */
#elif defined (WIN32) || defined (UNDER_CE)
#elif defined (WIN32) || defined (UNDER_CE)
# define USE_MB2MB 1
# define USE_MB2MB 1
#elif defined (HAVE_ICONV)
# define USE_ICONV 1
#else
# error No UTF8 charset conversion implemented on this platform!
#endif
static
char
*
locale_
fast
(
const
char
*
string
,
bool
from
)
static
char
*
locale_
dup
(
const
char
*
string
,
bool
from
)
{
{
if
(
string
==
NULL
)
char
*
out
;
int
len
;
len
=
1
+
MultiByteToWideChar
(
from
?
CP_ACP
:
CP_UTF8
,
0
,
string
,
-
1
,
NULL
,
0
);
wchar_t
*
wide
=
malloc
(
len
*
sizeof
(
wchar_t
));
if
(
wide
==
NULL
)
return
NULL
;
return
NULL
;
#if defined (USE_ICONV)
MultiByteToWideChar
(
from
?
CP_ACP
:
CP_UTF8
,
0
,
string
,
-
1
,
wide
,
len
);
len
=
1
+
WideCharToMultiByte
(
from
?
CP_UTF8
:
CP_ACP
,
0
,
wide
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
out
=
malloc
(
len
);
if
(
out
!=
NULL
)
WideCharToMultiByte
(
from
?
CP_UTF8
:
CP_ACP
,
0
,
wide
,
-
1
,
out
,
len
,
NULL
,
NULL
);
free
(
wide
);
return
out
;
}
#elif defined (HAVE_ICONV)
# define USE_ICONV 1
static
char
*
locale_dup
(
const
char
*
string
,
bool
from
)
{
vlc_iconv_t
hd
=
vlc_iconv_open
(
from
?
"UTF-8"
:
""
,
vlc_iconv_t
hd
=
vlc_iconv_open
(
from
?
"UTF-8"
:
""
,
from
?
""
:
"UTF-8"
);
from
?
""
:
"UTF-8"
);
if
(
hd
==
(
vlc_iconv_t
)(
-
1
))
if
(
hd
==
(
vlc_iconv_t
)(
-
1
))
...
@@ -89,45 +106,12 @@ static char *locale_fast (const char *string, bool from)
...
@@ -89,45 +106,12 @@ static char *locale_fast (const char *string, bool from)
assert
(
*
optr
==
'\0'
);
assert
(
*
optr
==
'\0'
);
assert
(
strlen
(
output
)
==
(
size_t
)(
optr
-
output
));
assert
(
strlen
(
output
)
==
(
size_t
)(
optr
-
output
));
return
strdup
(
output
);
return
strdup
(
output
);
#elif defined (USE_MB2MB)
char
*
out
;
int
len
;
len
=
1
+
MultiByteToWideChar
(
from
?
CP_ACP
:
CP_UTF8
,
0
,
string
,
-
1
,
NULL
,
0
);
wchar_t
*
wide
=
malloc
(
len
*
sizeof
(
wchar_t
));
if
(
wide
==
NULL
)
return
NULL
;
MultiByteToWideChar
(
from
?
CP_ACP
:
CP_UTF8
,
0
,
string
,
-
1
,
wide
,
len
);
len
=
1
+
WideCharToMultiByte
(
from
?
CP_UTF8
:
CP_ACP
,
0
,
wide
,
-
1
,
NULL
,
0
,
NULL
,
NULL
);
out
=
malloc
(
len
);
if
(
out
!=
NULL
)
WideCharToMultiByte
(
from
?
CP_UTF8
:
CP_ACP
,
0
,
wide
,
-
1
,
out
,
len
,
NULL
,
NULL
);
free
(
wide
);
return
out
;
#else
(
void
)
from
;
return
(
char
*
)
string
;
#endif
}
}
static
inline
char
*
locale_dup
(
const
char
*
string
,
bool
from
)
{
assert
(
string
);
#if defined (USE_ICONV)
return
locale_fast
(
string
,
from
);
#elif defined (USE_MB2MB)
return
locale_fast
(
string
,
from
);
#else
#else
(
void
)
from
;
# error No UTF8 charset conversion implemented on this platform!
return
strdup
(
string
);
#endif
#endif
}
/**
/**
* Releases (if needed) a localized or uniformized string.
* Releases (if needed) a localized or uniformized string.
...
@@ -135,12 +119,10 @@ static inline char *locale_dup (const char *string, bool from)
...
@@ -135,12 +119,10 @@ static inline char *locale_dup (const char *string, bool from)
*/
*/
void
LocaleFree
(
const
char
*
str
)
void
LocaleFree
(
const
char
*
str
)
{
{
#if defined (USE_ICONV)
#ifdef ASSUME_UTF8
free
((
char
*
)
str
);
(
void
)
str
;
#elif defined (USE_MB2MB)
free
((
char
*
)
str
);
#else
#else
(
void
)
str
;
free
((
char
*
)
str
)
;
#endif
#endif
}
}
...
@@ -156,7 +138,11 @@ void LocaleFree (const char *str)
...
@@ -156,7 +138,11 @@ void LocaleFree (const char *str)
*/
*/
char
*
FromLocale
(
const
char
*
locale
)
char
*
FromLocale
(
const
char
*
locale
)
{
{
return
locale_fast
(
locale
,
true
);
#ifdef ASSUME_UTF8
return
(
char
*
)
locale
;
#else
return
locale
?
locale_dup
(
locale
,
true
)
:
NULL
;
#endif
}
}
/**
/**
...
@@ -170,7 +156,11 @@ char *FromLocale (const char *locale)
...
@@ -170,7 +156,11 @@ char *FromLocale (const char *locale)
*/
*/
char
*
FromLocaleDup
(
const
char
*
locale
)
char
*
FromLocaleDup
(
const
char
*
locale
)
{
{
#ifdef ASSUME_UTF8
return
strdup
(
locale
);
#else
return
locale_dup
(
locale
,
true
);
return
locale_dup
(
locale
,
true
);
#endif
}
}
...
@@ -185,7 +175,11 @@ char *FromLocaleDup (const char *locale)
...
@@ -185,7 +175,11 @@ char *FromLocaleDup (const char *locale)
*/
*/
char
*
ToLocale
(
const
char
*
utf8
)
char
*
ToLocale
(
const
char
*
utf8
)
{
{
return
locale_fast
(
utf8
,
false
);
#ifdef ASSUME_UTF8
return
(
char
*
)
utf8
;
#else
return
utf8
?
locale_fast
(
utf8
,
false
)
:
NULL
#endif
}
}
...
@@ -200,7 +194,11 @@ char *ToLocale (const char *utf8)
...
@@ -200,7 +194,11 @@ char *ToLocale (const char *utf8)
*/
*/
char
*
ToLocaleDup
(
const
char
*
utf8
)
char
*
ToLocaleDup
(
const
char
*
utf8
)
{
{
#ifdef ASSUME_UTF8
return
strdup
(
utf8
);
#else
return
locale_dup
(
utf8
,
false
);
return
locale_dup
(
utf8
,
false
);
#endif
}
}
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment