Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Chris Müller
cherry
Commits
e605af77
Commit
e605af77
authored
Jul 09, 2013
by
Chris Müller
Browse files
add unicode->utf8 converter
parent
a26613c2
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/cherry/unicode.h
View file @
e605af77
...
...
@@ -33,6 +33,8 @@ int org_cherry_unicode_isgraph(cy_unicode_t ch);
int
org_cherry_unicode_ispunct
(
cy_unicode_t
ch
);
int
org_cherry_unicode_iscntrl
(
cy_unicode_t
ch
);
int
org_cherry_unicode_to_utf8
(
cy_byte_t
*
out
,
cy_unicode_t
ch
);
int
org_cherry_utf8_validate
(
const
cy_byte_t
*
str
);
int
org_cherry_utf8_compare
(
const
cy_byte_t
*
str1
,
const
cy_byte_t
*
str2
);
...
...
source/unicode.c
View file @
e605af77
...
...
@@ -447,3 +447,43 @@ org_cherry_utf8_validate(const cy_byte_t* str)
return
(
trails
==
0
);
}
int
org_cherry_unicode_to_utf8
(
cy_byte_t
*
out
,
cy_unicode_t
ch
)
{
size_t
length
=
0
;
cy_byte_t
first
;
int
i
;
if
(
ch
<
0x80
)
{
first
=
0x00
;
length
=
1
;
}
else
if
(
ch
<
0x800
)
{
first
=
0xC0
;
length
=
2
;
}
else
if
(
ch
<
0x10000
)
{
first
=
0xE0
;
length
=
3
;
}
else
if
(
ch
<
0x200000
)
{
first
=
0xF0
;
length
=
4
;
}
else
if
(
ch
<
0x4000000
)
{
first
=
0xF8
;
length
=
5
;
}
else
{
first
=
0xFC
;
length
=
6
;
}
if
(
out
)
{
for
(
i
=
length
-
1
;
i
>
0
;
--
i
)
{
out
[
i
]
=
(
ch
&
0x3F
)
|
0x80
;
ch
>>=
6
;
}
out
[
0
]
=
ch
|
first
;
}
return
length
;
}
Write
Preview
Supports
Markdown
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