Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
c88987c1
Commit
c88987c1
authored
Jun 04, 2014
by
Chris Angelico
Committed by
Paul Sokolovsky
Jun 27, 2014
Browse files
py: Implement basic unicode functions.
parent
12bc13ee
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/misc.h
View file @
c88987c1
...
...
@@ -100,7 +100,9 @@ bool unichar_isupper(unichar c);
bool
unichar_islower
(
unichar
c
);
unichar
unichar_tolower
(
unichar
c
);
unichar
unichar_toupper
(
unichar
c
);
#define unichar_charlen(s, bytelen) (bytelen)
uint
unichar_charlen
(
const
char
*
str
,
uint
len
);
#define UTF8_IS_NONASCII(ch) ((ch) & 0x80)
#define UTF8_IS_CONT(ch) (((ch) & 0xC0) == 0x80)
/** variable string *********************************************/
...
...
py/unicode.c
View file @
c88987c1
...
...
@@ -65,14 +65,39 @@ STATIC const uint8_t attr[] = {
AT_LO
,
AT_LO
,
AT_LO
,
AT_PR
,
AT_PR
,
AT_PR
,
AT_PR
,
0
};
unichar
utf8_get_char
(
const
byte
*
s
)
{
return
*
s
;
unichar
utf8_get_char
(
const
char
*
s
)
{
unichar
ord
=
*
s
++
;
if
(
!
UTF8_IS_NONASCII
(
ord
))
return
ord
;
ord
&=
0x7F
;
for
(
unichar
mask
=
0x40
;
ord
&
mask
;
mask
>>=
1
)
{
ord
&=
~
mask
;
}
while
(
UTF8_IS_CONT
(
*
s
))
{
ord
=
(
ord
<<
6
)
|
(
*
s
++
&
0x3F
);
}
return
ord
;
}
char
*
utf8_next_char
(
const
char
*
s
)
{
++
s
;
while
(
UTF8_IS_CONT
(
*
s
))
{
++
s
;
}
return
(
char
*
)
s
;
}
const
byte
*
utf8_next_char
(
const
byte
*
s
)
{
return
s
+
1
;
uint
unichar_charlen
(
const
char
*
str
,
uint
len
)
{
uint
charlen
=
0
;
for
(
const
char
*
top
=
str
+
len
;
str
<
top
;
++
str
)
{
if
(
!
UTF8_IS_CONT
(
*
str
))
{
++
charlen
;
}
}
return
charlen
;
}
// Be aware: These unichar_is* functions are actually ASCII-only!
bool
unichar_isspace
(
unichar
c
)
{
return
c
<
128
&&
(
attr
[
c
]
&
FL_SPACE
)
!=
0
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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