- Timestamp:
- Nov 6, 2013 7:41:40 AM (11 years ago)
- Location:
- pjproject/branches/projects/pjsua2/pjlib
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/branches/projects/pjsua2/pjlib/include/pj/string.h
r4440 r4642 576 576 577 577 /** 578 * Convert string to float. 579 * 580 * @param str the string. 581 * 582 * @return the value. 583 */ 584 PJ_DECL(float) pj_strtof(const pj_str_t *str); 585 586 /** 578 587 * Utility to convert unsigned integer to string. Note that the 579 588 * string will be NULL terminated. -
pjproject/branches/projects/pjsua2/pjlib/src/pj/string.c
r4537 r4642 176 176 } 177 177 178 PJ_DEF(float) pj_strtof(const pj_str_t *str) 179 { 180 pj_str_t part; 181 char *pdot; 182 float val; 183 184 if (str->slen == 0) 185 return 0; 186 187 pdot = (char*)pj_memchr(str->ptr, '.', str->slen); 188 part.ptr = str->ptr; 189 part.slen = pdot ? pdot - str->ptr : str->slen; 190 191 if (part.slen) 192 val = pj_strtol(&part); 193 else 194 val = 0; 195 196 if (pdot) { 197 part.ptr = pdot + 1; 198 part.slen = (str->ptr + str->slen - pdot - 1); 199 if (part.slen) { 200 pj_str_t endptr; 201 float fpart, fdiv; 202 unsigned i; 203 fpart = pj_strtoul2(&part, &endptr, 10); 204 fdiv = 1.0; 205 for (i=0; i<(part.slen - endptr.slen); ++i) 206 fdiv = fdiv * 10; 207 if (val >= 0) 208 val += (fpart / fdiv); 209 else 210 val -= (fpart / fdiv); 211 } 212 } 213 return val; 214 } 215 178 216 PJ_DEF(int) pj_utoa(unsigned long val, char *buf) 179 217 {
Note: See TracChangeset
for help on using the changeset viewer.