MCPcopy Create free account
hub / github.com/apache/cloudberry / nodeTokenType

Function nodeTokenType

src/backend/nodes/read.c:272–321  ·  view source on GitHub ↗

* nodeTokenType - * returns the type of the node token contained in token. * It returns one of the following valid NodeTags: * T_Integer, T_Float, T_String, T_BitString * and some of its own: * RIGHT_PAREN, LEFT_PAREN, LEFT_BRACE, OTHER_TOKEN * * Assumption: the ascii representation is legal */

Source from the content-addressed store, hash-verified

270 * Assumption: the ascii representation is legal
271 */
272static NodeTag
273nodeTokenType(const char *token, int length)
274{
275 NodeTag retval;
276 const char *numptr;
277 int numlen;
278
279 /*
280 * Check if the token is a number
281 */
282 numptr = token;
283 numlen = length;
284 if (*numptr == '+' || *numptr == '-')
285 numptr++, numlen--;
286 if ((numlen > 0 && isdigit((unsigned char) *numptr)) ||
287 (numlen > 1 && *numptr == '.' && isdigit((unsigned char) numptr[1])))
288 {
289 /*
290 * Yes. Figure out whether it is integral or float; this requires
291 * both a syntax check and a range check. strtoint() can do both for
292 * us. We know the token will end at a character that strtoint will
293 * stop at, so we do not need to modify the string.
294 */
295 char *endptr;
296
297 errno = 0;
298 (void) strtoint(token, &endptr, 10);
299 if (endptr != token + length || errno == ERANGE)
300 return T_Float;
301 return T_Integer;
302 }
303
304 /*
305 * these three cases do not need length checks, since pg_strtok() will
306 * always treat them as single-byte tokens
307 */
308 else if (*token == '(')
309 retval = LEFT_PAREN;
310 else if (*token == ')')
311 retval = RIGHT_PAREN;
312 else if (*token == '{')
313 retval = LEFT_BRACE;
314 else if (*token == '"' && length > 1 && token[length - 1] == '"')
315 retval = T_String;
316 else if (*token == 'b')
317 retval = T_BitString;
318 else
319 retval = OTHER_TOKEN;
320 return retval;
321}
322
323/*
324 * nodeRead -

Callers 1

nodeReadFunction · 0.85

Calls 1

strtointFunction · 0.85

Tested by

no test coverage detected