Inital coommit.

FossilOrigin-Name: f18b93961c5e1823d6e522469a16595c8917a615b066fa09a0d860adac2e4d92
This commit is contained in:
7u83@mail.ru 2015-04-17 06:02:52 +00:00
parent 4b05bc97a7
commit 2ab5da0a89
1 changed files with 36 additions and 0 deletions

36
src/capwap/utf8.c Normal file
View File

@ -0,0 +1,36 @@
#include "capwap.h"
int cw_is_utf8(unsigned char *str, size_t len)
{
size_t i = 0;
size_t j = 0;
size_t bytes = 0;
while (i < len) {
j = i;
if (str[i] < 0x20) {
return 0;
}
if (str[i] <= 0x7F)
bytes = 0;
else if (str[i] >= 0xC0 /*11000000 */ && str[i] <= 0xDF /*11011111 */ )
bytes = 1;
else if (str[i] >= 0xE0 /*11100000 */ && str[i] <= 0xEF /*11101111 */ )
bytes = 2;
else if (str[i] >= 0xF0 /*11110000 */
&& str[i] <= 0xF4 /* Cause of RFC 3629 */ )
bytes = 3;
else {
return 0;
}
i += 1;
while (i < len && bytes > 0 && str[i] >= 0x80 && str[i] <= 0xBF) {
i += 1;
bytes -= 1;
}
if (bytes != 0) {
return 0;
}
}
return 1;
}