Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-winehq
Commits
86ff825f
Commit
86ff825f
authored
Feb 15, 2008
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
libwine: Add option for Unicode composition in utf-8 -> wchar conversion.
parent
dbefd038
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
93 additions
and
1 deletion
+93
-1
utf8.c
libs/wine/utf8.c
+92
-0
wctomb.c
libs/wine/wctomb.c
+1
-1
No files found.
libs/wine/utf8.c
View file @
86ff825f
...
...
@@ -22,6 +22,8 @@
#include "wine/unicode.h"
extern
WCHAR
compose
(
const
WCHAR
*
str
);
/* number of following bytes in sequence based on first byte value (for bytes above 0x7f) */
static
const
char
utf8_length
[
128
]
=
{
...
...
@@ -183,6 +185,94 @@ static inline unsigned int decode_utf8_char( unsigned char ch, const char **str,
return
~
0
;
}
/* query necessary dst length for src string with composition */
static
inline
int
get_length_mbs_utf8_compose
(
int
flags
,
const
char
*
src
,
int
srclen
)
{
int
ret
=
0
;
unsigned
int
res
;
WCHAR
composed
[
2
];
const
char
*
srcend
=
src
+
srclen
;
composed
[
0
]
=
0
;
while
(
src
<
srcend
)
{
unsigned
char
ch
=
*
src
++
;
if
(
ch
<
0x80
)
/* special fast case for 7-bit ASCII */
{
composed
[
0
]
=
ch
;
ret
++
;
continue
;
}
if
((
res
=
decode_utf8_char
(
ch
,
&
src
,
srcend
))
<=
0xffff
)
{
if
(
composed
[
0
])
{
composed
[
1
]
=
res
;
if
((
composed
[
0
]
=
compose
(
composed
)))
continue
;
}
composed
[
0
]
=
res
;
ret
++
;
}
else
if
(
res
<=
0x10ffff
)
{
ret
+=
2
;
composed
[
0
]
=
0
;
/* no composition for surrogates */
}
else
if
(
flags
&
MB_ERR_INVALID_CHARS
)
return
-
2
;
/* bad char */
/* otherwise ignore it */
}
return
ret
;
}
/* UTF-8 to wide char string conversion with composition */
/* return -1 on dst buffer overflow, -2 on invalid input char */
static
int
utf8_mbstowcs_compose
(
int
flags
,
const
char
*
src
,
int
srclen
,
WCHAR
*
dst
,
int
dstlen
)
{
unsigned
int
res
;
const
char
*
srcend
=
src
+
srclen
;
WCHAR
composed
[
2
];
WCHAR
*
dstend
=
dst
+
dstlen
;
if
(
!
dstlen
)
return
get_length_mbs_utf8_compose
(
flags
,
src
,
srclen
);
composed
[
0
]
=
0
;
while
(
src
<
srcend
)
{
unsigned
char
ch
=
*
src
++
;
if
(
ch
<
0x80
)
/* special fast case for 7-bit ASCII */
{
if
(
dst
>=
dstend
)
return
-
1
;
/* overflow */
*
dst
++
=
composed
[
0
]
=
ch
;
continue
;
}
if
((
res
=
decode_utf8_char
(
ch
,
&
src
,
srcend
))
<=
0xffff
)
{
if
(
composed
[
0
])
{
composed
[
1
]
=
res
;
if
((
composed
[
0
]
=
compose
(
composed
)))
{
dst
[
-
1
]
=
composed
[
0
];
continue
;
}
}
if
(
dst
>=
dstend
)
return
-
1
;
/* overflow */
*
dst
++
=
composed
[
0
]
=
res
;
}
else
if
(
res
<=
0x10ffff
)
/* we need surrogates */
{
if
(
dst
>=
dstend
-
1
)
return
-
1
;
/* overflow */
res
-=
0x10000
;
*
dst
++
=
0xd800
|
(
res
>>
10
);
*
dst
++
=
0xdc00
|
(
res
&
0x3ff
);
composed
[
0
]
=
0
;
/* no composition for surrogates */
}
else
if
(
flags
&
MB_ERR_INVALID_CHARS
)
return
-
2
;
/* bad char */
/* otherwise ignore it */
}
return
dstlen
-
(
dstend
-
dst
);
}
/* query necessary dst length for src string */
static
inline
int
get_length_mbs_utf8
(
int
flags
,
const
char
*
src
,
int
srclen
)
{
...
...
@@ -217,6 +307,8 @@ int wine_utf8_mbstowcs( int flags, const char *src, int srclen, WCHAR *dst, int
const
char
*
srcend
=
src
+
srclen
;
WCHAR
*
dstend
=
dst
+
dstlen
;
if
(
flags
&
MB_COMPOSITE
)
return
utf8_mbstowcs_compose
(
flags
,
src
,
srclen
,
dst
,
dstlen
);
if
(
!
dstlen
)
return
get_length_mbs_utf8
(
flags
,
src
,
srclen
);
while
((
dst
<
dstend
)
&&
(
src
<
srcend
))
...
...
libs/wine/wctomb.c
View file @
86ff825f
...
...
@@ -45,7 +45,7 @@ static inline int binary_search( WCHAR ch, int low, int high )
}
/* return the result of the composition of two Unicode chars, or 0 if none */
static
WCHAR
compose
(
const
WCHAR
*
str
)
WCHAR
compose
(
const
WCHAR
*
str
)
{
extern
const
WCHAR
unicode_compose_table
[];
extern
const
unsigned
int
unicode_compose_table_size
;
...
...
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