X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=src%2Futf.c;h=92484d025da1658320da8a13d68f9f23b5fd038c;hb=145032a57f7844c29f2c40415b46338ac3445207;hp=2efcb68b43a5a2eea633a54cf827065f2fa1f569;hpb=d67aeb9739bf3e963ceaa8b622d20cd87a0b65fe;p=jansson.git diff --git a/src/utf.c b/src/utf.c index 2efcb68..92484d0 100644 --- a/src/utf.c +++ b/src/utf.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 2009 Petri Lehtinen + * Copyright (c) 2009, 2010 Petri Lehtinen * * Jansson is free software; you can redistribute it and/or modify * it under the terms of the MIT license. See LICENSE for details. */ #include -#include +#include "utf.h" int utf8_encode(int32_t codepoint, char *buffer, int *size) { @@ -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;