reformatting: cJSONUtils_Pstrcasecmp

This commit is contained in:
Max Bruckner 2016-10-13 23:40:02 +07:00
parent cb6445f47b
commit 2f002879c0

View File

@ -26,14 +26,38 @@ static int cJSONUtils_strcasecmp(const char *s1, const char *s2)
} }
/* JSON Pointer implementation: */ /* JSON Pointer implementation: */
static int cJSONUtils_Pstrcasecmp(const char *a,const char *e) static int cJSONUtils_Pstrcasecmp(const char *a, const char *e)
{ {
if (!a || !e) return (a==e)?0:1; if (!a || !e)
for (;*a && *e && *e!='/';a++,e++) { {
if (*e=='~') {if (!(e[1]=='0' && *a=='~') && !(e[1]=='1' && *a=='/')) return 1; else e++;} return (a == e) ? 0 : 1; /* both NULL? */
else if (tolower(*a)!=tolower(*e)) return 1;
} }
if ((*e!=0 && *e!='/') != (*a!=0)) return 1; for (; *a && *e && (*e != '/'); a++, e++) /* compare until next '/' */
{
if (*e == '~')
{
/* check for escaped '~' (~0) and '/' (~1) */
if (!((e[1] == '0') && (*a == '~')) && !((e[1] == '1') && (*a == '/')))
{
/* invalid escape sequence or wrong character in *a */
return 1;
}
else
{
e++;
}
}
else if (tolower(*a) != tolower(*e))
{
return 1;
}
}
if (((*e != 0) && (*e != '/')) != (*a != 0))
{
/* one string has ended, the other not */
return 1;
}
return 0; return 0;
} }