Skip to content

Commit 913954e

Browse files
author
Nikita Glukhov
committed
Extract lex_peek_value()
1 parent 49207ac commit 913954e

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/common/jsonapi.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ lex_peek(JsonLexContext *lex)
8383
return lex->token_type;
8484
}
8585

86+
static inline char *
87+
lex_peek_value(JsonLexContext *lex)
88+
{
89+
if (lex->token_type == JSON_TOKEN_STRING)
90+
return lex->strval ? pstrdup(lex->strval->data) : NULL;
91+
else
92+
{
93+
int len = (lex->token_terminator - lex->token_start);
94+
char *tokstr = palloc(len + 1);
95+
96+
memcpy(tokstr, lex->token_start, len);
97+
tokstr[len] = '\0';
98+
return tokstr;
99+
}
100+
}
101+
86102
/*
87103
* lex_expect
88104
*

0 commit comments

Comments
 (0)