mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
tokenize: LWS_TOKENIZE_F_NO_INTEGERS
This commit is contained in:
parent
69274487f9
commit
557d51f1f4
3 changed files with 23 additions and 12 deletions
|
@ -36,6 +36,8 @@
|
|||
* This lets you receive dotted-quads like 192.168.0.1 as string tokens, and
|
||||
* avoids illegal float format detection like 1.myserver.com */
|
||||
#define LWS_TOKENIZE_F_NO_FLOATS (1 << 5)
|
||||
/* Instead of LWS_TOKZE_INTEGER, report integers as any other string token */
|
||||
#define LWS_TOKENIZE_F_NO_INTEGERS (1 << 6)
|
||||
|
||||
typedef enum {
|
||||
|
||||
|
|
|
@ -594,7 +594,7 @@ lws_tokenize(struct lws_tokenize *ts)
|
|||
lws_tokenize_state state = LWS_TOKZS_LEADING_WHITESPACE;
|
||||
char c, flo = 0, d_minus = '-', d_dot = '.', s_minus = '\0',
|
||||
s_dot = '\0';
|
||||
signed char num = -1;
|
||||
signed char num = ts->flags & LWS_TOKENIZE_F_NO_INTEGERS ? 0 : -1;
|
||||
int utf8 = 0;
|
||||
|
||||
/* for speed, compute the effect of the flags outside the loop */
|
||||
|
@ -756,21 +756,21 @@ lws_tokenize(struct lws_tokenize *ts)
|
|||
state = LWS_TOKZS_TOKEN;
|
||||
ts->token = ts->start - 1;
|
||||
ts->token_len = 1;
|
||||
if (c < '0' || c > '9')
|
||||
num = 0;
|
||||
else
|
||||
if (num < 0)
|
||||
num = 1;
|
||||
continue;
|
||||
goto checknum;
|
||||
|
||||
case LWS_TOKZS_QUOTED_STRING:
|
||||
case LWS_TOKZS_TOKEN:
|
||||
if (c < '0' || c > '9')
|
||||
num = 0;
|
||||
else
|
||||
if (num < 0)
|
||||
num = 1;
|
||||
ts->token_len++;
|
||||
checknum:
|
||||
if (!(ts->flags & LWS_TOKENIZE_F_NO_INTEGERS)) {
|
||||
if (c < '0' || c > '9')
|
||||
num = 0;
|
||||
else
|
||||
if (num < 0)
|
||||
num = 1;
|
||||
}
|
||||
continue;
|
||||
|
||||
case LWS_TOKZS_TOKEN_POST_TERMINAL:
|
||||
/* report the new token next time */
|
||||
ts->start--;
|
||||
|
|
|
@ -164,6 +164,11 @@ struct expected expected1[] = {
|
|||
{ LWS_TOKZE_DELIMITER, ",", 1 },
|
||||
{ LWS_TOKZE_TOKEN, "Upgrade", 7 },
|
||||
{ LWS_TOKZE_ENDED, "", 0 },
|
||||
},
|
||||
expected16[] = {
|
||||
{ LWS_TOKZE_TOKEN_NAME_EQUALS, "a", 1 },
|
||||
{ LWS_TOKZE_TOKEN, "5", 1 },
|
||||
{ LWS_TOKZE_ENDED, "", 0 },
|
||||
}
|
||||
|
||||
;
|
||||
|
@ -238,6 +243,10 @@ struct tests tests[] = {
|
|||
expected15, LWS_ARRAY_SIZE(expected15),
|
||||
LWS_TOKENIZE_F_COMMA_SEP_LIST
|
||||
},
|
||||
{
|
||||
"a=5", expected16, LWS_ARRAY_SIZE(expected16),
|
||||
LWS_TOKENIZE_F_NO_INTEGERS
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Reference in a new issue