Skip to content

Commit 1e844b3

Browse files
author
Nikita Glukhov
committed
Extract lex_peek_value()
1 parent 4c51772 commit 1e844b3

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

src/backend/utils/adt/json.c

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ lex_peek(JsonLexContext *lex)
125125
return lex->token_type;
126126
}
127127

128+
static inline char *
129+
lex_peek_value(JsonLexContext *lex)
130+
{
131+
if (lex->token_type == JSON_TOKEN_STRING)
132+
return lex->strval ? pstrdup(lex->strval->data) : NULL;
133+
else
134+
{
135+
int len = (lex->token_terminator - lex->token_start);
136+
char *tokstr = palloc(len + 1);
137+
138+
memcpy(tokstr, lex->token_start, len);
139+
tokstr[len] = '\0';
140+
return tokstr;
141+
}
142+
}
143+
128144
/*
129145
* lex_accept
130146
*
@@ -140,22 +156,8 @@ lex_accept(JsonLexContext *lex, JsonTokenType token, char **lexeme)
140156
if (lex->token_type == token)
141157
{
142158
if (lexeme != NULL)
143-
{
144-
if (lex->token_type == JSON_TOKEN_STRING)
145-
{
146-
if (lex->strval != NULL)
147-
*lexeme = pstrdup(lex->strval->data);
148-
}
149-
else
150-
{
151-
int len = (lex->token_terminator - lex->token_start);
152-
char *tokstr = palloc(len + 1);
159+
*lexeme = lex_peek_value(lex);
153160

154-
memcpy(tokstr, lex->token_start, len);
155-
tokstr[len] = '\0';
156-
*lexeme = tokstr;
157-
}
158-
}
159161
json_lex(lex);
160162
return true;
161163
}

0 commit comments

Comments
 (0)