Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

PInt64 PString::AsInt64 ( unsigned  base = 10  )  const [inherited]

Convert the string to an integer value using the specified number base. All characters up to the first illegal character for the number base are converted. Case is not significant for bases greater than 10.

The number base may only be from 2 to 36 and the function will assert if it is not in this range.

This function uses the standard C library strtoq()# or strtoul()# function.

Returns:
integer value for the string.
Parameters:
base  Number base to convert the string in.

Definition at line 388 of file ptlib.cxx.

{
  if (base == 10)
    return _atoi64(theArray);

  PAssert(base >= 2 && base <= 36, PInvalidParameter);

  PInt64 total = 0;
  const char * ptr = theArray;

  while (isspace(*ptr))
    ptr++;

  BOOL negative = *ptr == '-';
  if (*ptr == '-' || *ptr == '+')
    ptr++;

  for (;;) {
    unsigned c = *ptr++;
    if (c < '0')
      break;

    if (c <= '9')
      c -= '0';
    else
      c = toupper(c) - 'A' + 10;

    if (c >= base)
      break;

    total = base * total + c;
  }

  if (negative)
    return -total;
  else
    return total;
}


Generated by  Doxygen 1.6.0   Back to index