MCPcopy Create free account
hub / github.com/acl-dev/acl / parse_number

Function parse_number

lib_acl/samples/json/json5/cJSON.cpp:96–115  ·  view source on GitHub ↗

Parse the input text to generate a number, and populate the result into item. */

Source from the content-addressed store, hash-verified

94
95/* Parse the input text to generate a number, and populate the result into item. */
96static const char *parse_number(cJSON *item,const char *num)
97{
98 double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
99
100 if (*num=='-') sign=-1,num++; /* Has sign? */
101 if (*num=='0') num++; /* is zero */
102 if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
103 if (*num=='.' && num[1]>='0' && num[1]<='9') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
104 if (*num=='e' || *num=='E') /* Exponent? */
105 { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
106 while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
107 }
108
109 n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
110
111 item->valuedouble=n;
112 item->valueint=(int)n;
113 item->type=cJSON_Number;
114 return num;
115}
116
117static int pow2gt (int x) { --x; x|=x>>1; x|=x>>2; x|=x>>4; x|=x>>8; x|=x>>16; return x+1; }
118

Callers 1

parse_valueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…