mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-03-29 07:58:06 -04:00
json-core: use table to classify chars for number check
This commit is contained in:
parent
5c67ab2a7a
commit
8f22785cf0
1 changed files with 11 additions and 5 deletions
|
|
@ -488,14 +488,20 @@ SPA_API_JSON bool spa_json_is_json_number(const char *val, int len)
|
||||||
/* 7 */ { 3, 3, 8, 8, -1, -1, -1 }, /* after 'e'/'E' */
|
/* 7 */ { 3, 3, 8, 8, -1, -1, -1 }, /* after 'e'/'E' */
|
||||||
/* 8 */ { 3, 3, -1, -1, -1, -1, -1 }, /* after exp sign */
|
/* 8 */ { 3, 3, -1, -1, -1, -1, -1 }, /* after exp sign */
|
||||||
};
|
};
|
||||||
|
static const int8_t char_class[128] = {
|
||||||
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, /* 0-15 */
|
||||||
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, /* 16-31 */
|
||||||
|
6,6,6,6,6,6,6,6,6,6,6,3,6,2,4,6, /* 32-47: + - . */
|
||||||
|
1,0,0,0,0,0,0,0,0,0,6,6,6,6,6,6, /* 48-63: 0-9 */
|
||||||
|
6,6,6,6,6,5,6,6,6,6,6,6,6,6,6,6, /* 64-79: E */
|
||||||
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, /* 80-95 */
|
||||||
|
6,6,6,6,6,5,6,6,6,6,6,6,6,6,6,6, /* 96-111: e */
|
||||||
|
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, /* 112-127 */
|
||||||
|
};
|
||||||
int i, state = 4;
|
int i, state = 4;
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
char v = val[i];
|
if ((state = trans[state][char_class[val[i]&0x7f]]) < 0)
|
||||||
int cls = (v >= '1' && v <= '9') ? 0 : v == '0' ? 1 :
|
|
||||||
v == '-' ? 2 : v == '+' ? 3 : v == '.' ? 4 :
|
|
||||||
(v == 'e' || v == 'E') ? 5 : 6;
|
|
||||||
if ((state = trans[state][cls]) < 0)
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return state < 4;
|
return state < 4;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue