diff options
| author | oy <Tom_Adams@web.de> | 2010-10-01 00:55:16 +0200 |
|---|---|---|
| committer | oy <Tom_Adams@web.de> | 2010-10-01 00:55:16 +0200 |
| commit | 67e9f03f23a454f273aeb6f83e338c057c3efb93 (patch) | |
| tree | f6ec82e186ea23861b2eb2c3576e7b38c19dec52 /src/base | |
| parent | 2f388139c1e46d8cde32bd446b880e4225b06b35 (diff) | |
| download | zcatch-67e9f03f23a454f273aeb6f83e338c057c3efb93.tar.gz zcatch-67e9f03f23a454f273aeb6f83e338c057c3efb93.zip | |
when setting a config string variable check if it's a utf8 string and encode it if the check fails. Closes #10
Diffstat (limited to 'src/base')
| -rw-r--r-- | src/base/system.c | 18 | ||||
| -rw-r--r-- | src/base/system.h | 16 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/base/system.c b/src/base/system.c index bf473650..25e89896 100644 --- a/src/base/system.c +++ b/src/base/system.c @@ -1454,6 +1454,24 @@ int str_utf8_decode(const char **ptr) } +int str_utf8_check(const char *str) +{ + while(*str) + { + if((*str&0x80) == 0x0) + str++; + else if((*str&0xE0) == 0xC0 && (*(str+1)&0xC0) == 0x80) + str += 2; + else if((*str&0xF0) == 0xE0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80) + str += 3; + else if((*str&0xF8) == 0xF0 && (*(str+1)&0xC0) == 0x80 && (*(str+2)&0xC0) == 0x80 && (*(str+3)&0xC0) == 0x80) + str += 4; + else + return 0; + } + return 1; +} + unsigned str_quickhash(const char *str) { diff --git a/src/base/system.h b/src/base/system.h index f71a03ec..62fe02e9 100644 --- a/src/base/system.h +++ b/src/base/system.h @@ -1147,6 +1147,22 @@ int str_utf8_decode(const char **ptr); */ int str_utf8_encode(char *ptr, int chr); +/* + Function: str_utf8_check + Checks if a strings contains just valid utf8 characters. + + Parameters: + str - Pointer to a possible utf8 string. + + Returns: + 0 - invalid characters found. + 1 - only valid characters found. + + Remarks: + - The string is treated as zero-terminated utf8 string. +*/ +int str_utf8_check(const char *str); + #ifdef __cplusplus } #endif |