MCPcopy Create free account
hub / github.com/PointCloudLibrary/pcl / parse_number

Function parse_number

outofcore/src/cJSON.cpp:105–125  ·  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

103
104/* Parse the input text to generate a number, and populate the result into item. */
105static const char *parse_number(cJSON *item,const char *num)
106{
107 double n=0,sign=1,scale=0;int subscale=0,signsubscale=1;
108
109 /* Could use sscanf for this? */
110 if (*num=='-') sign=-1,num++; /* Has sign? */
111 if (*num=='0') num++; /* is zero */
112 if (*num>='1' && *num<='9') do n=(n*10.0)+(*num++ -'0'); while (*num>='0' && *num<='9'); /* Number? */
113 if (*num=='.') {num++; do n=(n*10.0)+(*num++ -'0'),scale--; while (*num>='0' && *num<='9');} /* Fractional part? */
114 if (*num=='e' || *num=='E') /* Exponent? */
115 { num++;if (*num=='+') num++; else if (*num=='-') signsubscale=-1,num++; /* With sign? */
116 while (*num>='0' && *num<='9') subscale=(subscale*10)+(*num++ - '0'); /* Number? */
117 }
118
119 n=sign*n*pow(10.0,(scale+subscale*signsubscale)); /* number = +/- number.fraction * 10^+/- exponent */
120
121 item->valuedouble=n;
122 item->valueint=static_cast<int> (n);
123 item->type=cJSON_Number;
124 return num;
125}
126
127/* Render the number nicely from the given item into a string. */
128static char *print_number(cJSON *item)

Callers 1

parse_valueFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected