diff options
author | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:14:03 +0900 |
---|---|---|
committer | DongHun Kwak <dh0128.kwak@samsung.com> | 2021-10-08 09:14:03 +0900 |
commit | d140263a497b4a86818ab5e2017a66df43eb83fb (patch) | |
tree | 4acfe8c906ce669c5fc92689df2c3c83a32d881c /Source/cm_utf8.c | |
parent | e1763ae434c946bd1c1e9a7cc66a905ebe027bbd (diff) | |
download | cmake-d140263a497b4a86818ab5e2017a66df43eb83fb.tar.gz cmake-d140263a497b4a86818ab5e2017a66df43eb83fb.tar.bz2 cmake-d140263a497b4a86818ab5e2017a66df43eb83fb.zip |
Imported Upstream version 3.15.0upstream/3.15.0
Diffstat (limited to 'Source/cm_utf8.c')
-rw-r--r-- | Source/cm_utf8.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/Source/cm_utf8.c b/Source/cm_utf8.c index 52af4a6f4..62e7e8c8c 100644 --- a/Source/cm_utf8.c +++ b/Source/cm_utf8.c @@ -2,6 +2,8 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cm_utf8.h" +#include <string.h> + /* RFC 3629 07-bit: 0xxxxxxx @@ -71,7 +73,34 @@ const char* cm_utf8_decode_character(const char* first, const char* last, return 0; } + /* UTF-16 surrogate halves. */ + if (0xD800 <= uc && uc <= 0xDFFF) { + return 0; + } + + /* Invalid codepoints. */ + if (0x10FFFF < uc) { + return 0; + } + *pc = uc; return first; } } + +int cm_utf8_is_valid(const char* s) +{ + if (!s) { + return 0; + } + + const char* last = s + strlen(s); + const char* pos = s; + unsigned int pc; + + while (pos != last && (pos = cm_utf8_decode_character(pos, last, &pc))) { + /* Nothing to do. */ + } + + return pos == last; +} |