diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-04-15 09:58:48 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-04-15 09:58:48 +0000 |
commit | 0c6f9521feba68026a227aebef97fbe440c44e80 (patch) | |
tree | b37206b3ac916138e0fc1deb7ddb6aed87cc659c /pjlib/src/pj/string.c | |
parent | 5c2c87c522aae8a66100e0a05a151e2f778061d1 (diff) |
Ticket #223: Added pj_strtoul2()
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1194 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/src/pj/string.c')
-rw-r--r-- | pjlib/src/pj/string.c | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/pjlib/src/pj/string.c b/pjlib/src/pj/string.c index 62da6a0f..9a2ca0f2 100644 --- a/pjlib/src/pj/string.c +++ b/pjlib/src/pj/string.c @@ -17,6 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <pj/string.h> +#include <pj/assert.h> #include <pj/pool.h> #include <pj/ctype.h> #include <pj/rand.h> @@ -83,6 +84,42 @@ PJ_DEF(unsigned long) pj_strtoul(const pj_str_t *str) return value; } +PJ_DEF(unsigned long) pj_strtoul2(const pj_str_t *str, pj_str_t *endptr, + unsigned base) +{ + unsigned long value; + unsigned i; + + PJ_CHECK_STACK(); + + value = 0; + if (base <= 10) { + for (i=0; i<(unsigned)str->slen; ++i) { + unsigned c = (str->ptr[i] - '0'); + if (c >= base) + break; + value = value * base + c; + } + } else if (base == 16) { + for (i=0; i<(unsigned)str->slen; ++i) { + if (!pj_isxdigit(str->ptr[i])) + break; + value = value * 16 + pj_hex_digit_to_val(str->ptr[i]); + } + } else { + pj_assert(!"Unsupported base"); + i = 0; + value = 0xFFFFFFFFUL; + } + + if (endptr) { + endptr->ptr = str->ptr + i; + endptr->slen = str->slen - i; + } + + return value; +} + PJ_DEF(int) pj_utoa(unsigned long val, char *buf) { return pj_utoa_pad(val, buf, 0, 0); |