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
8a37450d
Commit
8a37450d
authored
Apr 11, 2002
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
'used' should be set even if we are only computing the necessary
buffer size.
parent
f25efa06
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
25 deletions
+55
-25
wctomb.c
unicode/wctomb.c
+55
-25
No files found.
unicode/wctomb.c
View file @
8a37450d
...
...
@@ -76,33 +76,53 @@ static inline int is_valid_sbcs_mapping( const struct sbcs_table *table, int fla
}
/* query necessary dst length for src string */
static
in
line
in
t
get_length_sbcs
(
const
struct
sbcs_table
*
table
,
int
flags
,
const
WCHAR
*
src
,
unsigned
int
srclen
)
static
int
get_length_sbcs
(
const
struct
sbcs_table
*
table
,
int
flags
,
const
WCHAR
*
src
,
unsigned
int
srclen
,
int
*
used
)
{
unsigned
int
ret
=
srclen
;
const
unsigned
char
*
const
uni2cp_low
=
table
->
uni2cp_low
;
const
unsigned
short
*
const
uni2cp_high
=
table
->
uni2cp_high
;
int
ret
,
tmp
;
WCHAR
composed
;
if
(
!
used
)
used
=
&
tmp
;
/* avoid checking on every char */
*
used
=
0
;
if
(
flags
&
WC_COMPOSITECHECK
)
for
(
ret
=
0
;
srclen
;
ret
++
,
src
++
,
srclen
--
)
{
const
unsigned
char
*
const
uni2cp_low
=
table
->
uni2cp_low
;
const
unsigned
short
*
const
uni2cp_high
=
table
->
uni2cp_high
;
WCHAR
composed
;
WCHAR
wch
=
*
src
;
unsigned
char
ch
;
for
(
ret
=
0
;
srclen
>
1
;
ret
++
,
srclen
--
,
src
++
)
if
((
flags
&
WC_COMPOSITECHECK
)
&&
(
srclen
>
1
)
&&
(
composed
=
compose
(
src
))
)
{
if
(
!
(
composed
=
compose
(
src
)))
continue
;
/* check if we should skip the next char */
/* in WC_DEFAULTCHAR and WC_DISCARDNS mode, we always skip */
/* the next char no matter if the composition is valid or not */
if
(
!
(
flags
&
(
WC_DEFAULTCHAR
|
WC_DISCARDNS
)))
/* now check if we can use the composed char */
ch
=
uni2cp_low
[
uni2cp_high
[
composed
>>
8
]
+
(
composed
&
0xff
)];
if
(
is_valid_sbcs_mapping
(
table
,
flags
,
composed
,
ch
))
{
/* we have a good mapping, use it */
src
++
;
srclen
--
;
continue
;
}
/* no mapping for the composed char, check the other flags */
if
(
flags
&
WC_DEFAULTCHAR
)
/* use the default char instead */
{
*
used
=
1
;
src
++
;
/* skip the non-spacing char */
srclen
--
;
continue
;
}
if
(
flags
&
WC_DISCARDNS
)
/* skip the second char of the composition */
{
unsigned
char
ch
=
uni2cp_low
[
uni2cp_high
[
composed
>>
8
]
+
(
composed
&
0xff
)]
;
if
(
!
is_valid_sbcs_mapping
(
table
,
flags
,
composed
,
ch
))
continue
;
src
++
;
srclen
--
;
}
src
++
;
srclen
--
;
/* WC_SEPCHARS is the default */
}
if
(
!*
used
)
{
ch
=
uni2cp_low
[
uni2cp_high
[
wch
>>
8
]
+
(
wch
&
0xff
)];
*
used
=
!
is_valid_sbcs_mapping
(
table
,
flags
,
wch
,
ch
);
}
if
(
srclen
)
ret
++
;
/* last char */
}
return
ret
;
}
...
...
@@ -238,15 +258,15 @@ static inline int is_valid_dbcs_mapping( const struct dbcs_table *table, int fla
/* query necessary dst length for src string */
static
int
get_length_dbcs
(
const
struct
dbcs_table
*
table
,
int
flags
,
const
WCHAR
*
src
,
unsigned
int
srclen
,
const
char
*
defchar
)
const
char
*
defchar
,
int
*
used
)
{
const
unsigned
short
*
const
uni2cp_low
=
table
->
uni2cp_low
;
const
unsigned
short
*
const
uni2cp_high
=
table
->
uni2cp_high
;
WCHAR
defchar_value
=
table
->
info
.
def_char
;
WCHAR
composed
;
int
len
;
int
len
,
tmp
;
if
(
!
defchar
&&
!
(
flags
&
WC_COMPOSITECHECK
))
if
(
!
defchar
&&
!
used
&&
!
(
flags
&
WC_COMPOSITECHECK
))
{
for
(
len
=
0
;
srclen
;
srclen
--
,
src
++
,
len
++
)
{
...
...
@@ -256,6 +276,8 @@ static int get_length_dbcs( const struct dbcs_table *table, int flags,
}
if
(
defchar
)
defchar_value
=
defchar
[
1
]
?
((
defchar
[
0
]
<<
8
)
|
defchar
[
1
])
:
defchar
[
0
];
if
(
!
used
)
used
=
&
tmp
;
/* avoid checking on every char */
*
used
=
0
;
for
(
len
=
0
;
srclen
;
len
++
,
srclen
--
,
src
++
)
{
unsigned
short
res
;
...
...
@@ -278,6 +300,7 @@ static int get_length_dbcs( const struct dbcs_table *table, int flags,
if
(
flags
&
WC_DEFAULTCHAR
)
/* use the default char instead */
{
if
(
defchar_value
&
0xff00
)
len
++
;
*
used
=
1
;
src
++
;
/* skip the non-spacing char */
srclen
--
;
continue
;
...
...
@@ -291,7 +314,11 @@ static int get_length_dbcs( const struct dbcs_table *table, int flags,
}
res
=
uni2cp_low
[
uni2cp_high
[
wch
>>
8
]
+
(
wch
&
0xff
)];
if
(
!
is_valid_dbcs_mapping
(
table
,
flags
,
wch
,
res
))
res
=
defchar_value
;
if
(
!
is_valid_dbcs_mapping
(
table
,
flags
,
wch
,
res
))
{
res
=
defchar_value
;
*
used
=
1
;
}
if
(
res
&
0xff00
)
len
++
;
}
return
len
;
...
...
@@ -399,15 +426,18 @@ int cp_wcstombs( const union cptable *table, int flags,
{
if
(
table
->
info
.
char_size
==
1
)
{
if
(
!
dstlen
)
return
get_length_sbcs
(
&
table
->
sbcs
,
flags
,
src
,
srclen
);
if
(
flags
||
defchar
||
used
)
{
if
(
!
dstlen
)
return
get_length_sbcs
(
&
table
->
sbcs
,
flags
,
src
,
srclen
,
used
);
return
wcstombs_sbcs_slow
(
&
table
->
sbcs
,
flags
,
src
,
srclen
,
dst
,
dstlen
,
defchar
,
used
);
}
if
(
!
dstlen
)
return
srclen
;
return
wcstombs_sbcs
(
&
table
->
sbcs
,
src
,
srclen
,
dst
,
dstlen
);
}
else
/* mbcs */
{
if
(
!
dstlen
)
return
get_length_dbcs
(
&
table
->
dbcs
,
flags
,
src
,
srclen
,
defchar
);
if
(
!
dstlen
)
return
get_length_dbcs
(
&
table
->
dbcs
,
flags
,
src
,
srclen
,
defchar
,
used
);
if
(
flags
||
defchar
||
used
)
return
wcstombs_dbcs_slow
(
&
table
->
dbcs
,
flags
,
src
,
srclen
,
dst
,
dstlen
,
defchar
,
used
);
...
...
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