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

Function json_lex_number

src/common/jsonapi.c:915–1008  ·  view source on GitHub ↗

* The next token in the input stream is known to be a number; lex it. * * In JSON, a number consists of four parts: * * (1) An optional minus sign ('-'). * * (2) Either a single '0', or a string of one or more digits that does not * begin with a '0'. * * (3) An optional decimal part, consisting of a period ('.') followed by * one or more digits. (Note: While this part can be omitt

Source from the content-addressed store, hash-verified

913 * the distance from lex->input to the token end+1 is returned to *total_len.
914 */
915static inline JsonParseErrorType
916json_lex_number(JsonLexContext *lex, char *s,
917 bool *num_err, int *total_len)
918{
919 bool error = false;
920 int len = s - lex->input;
921
922 /* Part (1): leading sign indicator. */
923 /* Caller already did this for us; so do nothing. */
924
925 /* Part (2): parse main digit string. */
926 if (len < lex->input_length && *s == '0')
927 {
928 s++;
929 len++;
930 }
931 else if (len < lex->input_length && *s >= '1' && *s <= '9')
932 {
933 do
934 {
935 s++;
936 len++;
937 } while (len < lex->input_length && *s >= '0' && *s <= '9');
938 }
939 else
940 error = true;
941
942 /* Part (3): parse optional decimal portion. */
943 if (len < lex->input_length && *s == '.')
944 {
945 s++;
946 len++;
947 if (len == lex->input_length || *s < '0' || *s > '9')
948 error = true;
949 else
950 {
951 do
952 {
953 s++;
954 len++;
955 } while (len < lex->input_length && *s >= '0' && *s <= '9');
956 }
957 }
958
959 /* Part (4): parse optional exponent. */
960 if (len < lex->input_length && (*s == 'e' || *s == 'E'))
961 {
962 s++;
963 len++;
964 if (len < lex->input_length && (*s == '+' || *s == '-'))
965 {
966 s++;
967 len++;
968 }
969 if (len == lex->input_length || *s < '0' || *s > '9')
970 error = true;
971 else
972 {

Callers 2

IsValidJsonNumberFunction · 0.85
json_lexFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected