diff options
author | Petri Lehtinen <petri@digip.org> | 2009-12-05 22:55:30 +0200 |
---|---|---|
committer | Petri Lehtinen <petri@digip.org> | 2009-12-05 22:55:30 +0200 |
commit | 50031440a3b7ab2623e9468bd20e837250250cd9 (patch) | |
tree | 063ac18e20b93b3a96d786ea8e6bd761a2fb978d /src/utf.c | |
parent | d67aeb9739bf3e963ceaa8b622d20cd87a0b65fe (diff) | |
download | jansson-50031440a3b7ab2623e9468bd20e837250250cd9.zip jansson-50031440a3b7ab2623e9468bd20e837250250cd9.tar.gz jansson-50031440a3b7ab2623e9468bd20e837250250cd9.tar.bz2 |
Implement JSON_ENSURE_ASCII encoding flag
With this flag, all Unicode characters outside the ASCII range are
escaped.
Diffstat (limited to 'src/utf.c')
-rw-r--r-- | src/utf.c | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -80,7 +80,7 @@ int utf8_check_first(char byte) } } -int utf8_check_full(const char *buffer, int size) +int utf8_check_full(const char *buffer, int size, int32_t *codepoint) { int i; int32_t value = 0; @@ -130,9 +130,38 @@ int utf8_check_full(const char *buffer, int size) return 0; } + if(codepoint) + *codepoint = value; + return 1; } +const char *utf8_iterate(const char *buffer, int32_t *codepoint) +{ + int count; + int32_t value; + + if(!*buffer) + return buffer; + + count = utf8_check_first(buffer[0]); + if(count <= 0) + return NULL; + + if(count == 1) + value = (unsigned char)buffer[0]; + else + { + if(!utf8_check_full(buffer, count, &value)) + return NULL; + } + + if(codepoint) + *codepoint = value; + + return buffer + count; +} + int utf8_check_string(const char *string, int length) { int i; @@ -150,7 +179,7 @@ int utf8_check_string(const char *string, int length) if(i + count > length) return 0; - if(!utf8_check_full(&string[i], count)) + if(!utf8_check_full(&string[i], count, NULL)) return 0; i += count - 1; |