Changeset 3210


Ignore:
Timestamp:
Jun 18, 2010 3:37:28 PM (10 years ago)
Author:
ming
Message:

Implemented ticket #1099: Conversion of pj_str_t to signed long

Location:
pjproject/branches/projects/cli/pjlib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • pjproject/branches/projects/cli/pjlib/include/pj/string.h

    r2394 r3210  
    537537 
    538538/** 
     539 * Convert string to signed integer. The conversion will stop as 
     540 * soon as non-digit character is found or all the characters have 
     541 * been processed. 
     542 * 
     543 * @param str   the string. 
     544 * 
     545 * @return the integer. 
     546 */ 
     547PJ_DECL(long) pj_strtol(const pj_str_t *str); 
     548 
     549/** 
    539550 * Convert string to unsigned integer. The conversion will stop as 
    540551 * soon as non-digit character is found or all the characters have 
  • pjproject/branches/projects/cli/pjlib/src/pj/string.c

    r3207 r3210  
    7070PJ_DEF(pj_str_t*) pj_strltrim( pj_str_t *str ) 
    7171{ 
    72     char *end = str->ptr + str->slen; 
    7372    register char *p = str->ptr; 
    74     while (p < end && pj_isspace(*p)) 
     73    while (pj_isspace(*p)) 
    7574        ++p; 
    7675    str->slen -= (p - str->ptr); 
     
    110109} 
    111110 
     111PJ_DEF(long) pj_strtol(const pj_str_t *str) 
     112{ 
     113    PJ_CHECK_STACK(); 
     114 
     115    if (str->slen > 0 && (str->ptr[0] == '+' || str->ptr[0] == '-')) { 
     116        pj_str_t s; 
     117         
     118        s.ptr = str->ptr + 1; 
     119        s.slen = str->slen - 1; 
     120        return (str->ptr[0] == '-'? -(long)pj_strtoul(&s) : pj_strtoul(&s)); 
     121    } else 
     122        return pj_strtoul(str); 
     123} 
    112124 
    113125PJ_DEF(unsigned long) pj_strtoul(const pj_str_t *str) 
Note: See TracChangeset for help on using the changeset viewer.