src/lib/edit.c
uint64_t str_to_uint64(char *str)
{
   char *p = str;
   uint64_t value = 0;

   if (!p) {
      return 0;
   }
   while (B_ISSPACE(*p)) {
      p++;
   }
   if (*p == '+') {
      p++;
   }
   if (*p == '0' && *(p+1) == 'x') {
      p = p + 2; /* skip 0x */

      while (B_ISXDIGIT(*p)) {
         if (B_ISDIGIT(*p)) {
            value = (value<<4) + (*p - '0');

         } else {
            value = (value<<4) + (tolower(*p) - 'a' + 10);
         }
         p++;
      }
   } else {
      while (B_ISDIGIT(*p)) {
         value = B_TIMES10(value) + *p - '0';
         p++;
      }
   }
   return value;
}
/* We assume ASCII input and don't worry about overflow */
We assume ASCII input and don't worry about overflow
We assume ASCII input and don ' t worry about overflow
uint64_t str_to_uint64(char *str)
{
   char *p = str;
   uint64_t value = 0;
   if (!p) {
      return 0;
   }
   while (B_ISSPACE(*p)) {
      p++;
   }
   if (*p == '+') {
      p++;
   }
   if (*p == '0' && *(p+1) == 'x') {
      p = p + 2; 
      while (B_ISXDIGIT(*p)) {
         if (B_ISDIGIT(*p)) {
            value = (value<<4) + (*p - '0');
         } else {
            value = (value<<4) + (tolower(*p) - 'a' + 10);
         }
         p++;
      }
   } else {
      while (B_ISDIGIT(*p)) {
         value = B_TIMES10(value) + *p - '0';
         p++;
      }
   }
   return value;
}
uint64_t str_to_uint64 ( char * str ) { char * p = str ; uint64_t value = 0 ; if ( ! p ) { return 0 ; } while ( B_ISSPACE ( * p ) ) { p ++ ; } if ( * p == ' ' ) { p ++ ; } if ( * p == ' ' && * ( p + 1 ) == ' ' ) { p = p + 2 ; while ( B_ISXDIGIT ( * p ) ) { if ( B_ISDIGIT ( * p ) ) { value = ( value << 4 ) + ( * p - ' ' ) ; } else { value = ( value << 4 ) + ( tolower ( * p ) - ' ' + 10 ) ; } p ++ ; } } else { while ( B_ISDIGIT ( * p ) ) { value = B_TIMES10 ( value ) + * p - ' ' ; p ++ ; } } return value ; }
We assume ASCII input and don't worry about overflow
We assume ASCII input and don ' t worry about overflow
/* skip 0x */