Commit b0bb4588 authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

unicode: String API is const byte*.

We still have that char vs byte dichotomy, but majority of string operations
now use byte.
parent 2ec38a17
...@@ -83,8 +83,8 @@ bool str_strn_equal(const char *str, const char *strn, int len) { ...@@ -83,8 +83,8 @@ bool str_strn_equal(const char *str, const char *strn, int len) {
void mp_token_show(const mp_token_t *tok) { void mp_token_show(const mp_token_t *tok) {
printf("(%d:%d) kind:%d str:%p len:%d", tok->src_line, tok->src_column, tok->kind, tok->str, tok->len); printf("(%d:%d) kind:%d str:%p len:%d", tok->src_line, tok->src_column, tok->kind, tok->str, tok->len);
if (tok->str != NULL && tok->len > 0) { if (tok->str != NULL && tok->len > 0) {
const char *i = tok->str; const byte *i = (const byte *)tok->str;
const char *j = i + tok->len; const byte *j = (const byte *)i + tok->len;
printf(" "); printf(" ");
while (i < j) { while (i < j) {
unichar c = utf8_get_char(i); unichar c = utf8_get_char(i);
......
...@@ -88,8 +88,8 @@ int m_get_peak_bytes_allocated(void); ...@@ -88,8 +88,8 @@ int m_get_peak_bytes_allocated(void);
typedef int unichar; // TODO typedef int unichar; // TODO
unichar utf8_get_char(const char *s); unichar utf8_get_char(const byte *s);
char *utf8_next_char(const char *s); const byte *utf8_next_char(const byte *s);
bool unichar_isspace(unichar c); bool unichar_isspace(unichar c);
bool unichar_isalpha(unichar c); bool unichar_isalpha(unichar c);
......
...@@ -65,12 +65,12 @@ STATIC const uint8_t attr[] = { ...@@ -65,12 +65,12 @@ STATIC const uint8_t attr[] = {
AT_LO, AT_LO, AT_LO, AT_PR, AT_PR, AT_PR, AT_PR, 0 AT_LO, AT_LO, AT_LO, AT_PR, AT_PR, AT_PR, AT_PR, 0
}; };
unichar utf8_get_char(const char *s) { unichar utf8_get_char(const byte *s) {
return *s; return *s;
} }
char *utf8_next_char(const char *s) { const byte *utf8_next_char(const byte *s) {
return (char*)(s + 1); return s + 1;
} }
bool unichar_isspace(unichar c) { bool unichar_isspace(unichar c) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment