pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:877:    while(len && n)    {    s->str[--len]="0123456789abcdef"[n&0xf];    n>>=4;    }    }    RETURN end_shared_string(s);   }       - /*! @decl string string2hex(string data) + /*! @decl string string2hex(string data, void|int uppercase)    *! @appears String.string2hex    *!    *! Convert a string of binary data to a hexadecimal string.    *! -  +  *! @param uppercase +  *! If set, the string will use upper cased characters. +  *!    *! @seealso    *! @[hex2string()]    */      static const char hexchar[] = {    '0','1','2','3','4','5','6','7','8','9',    'a','b','c','d','e','f'   };    -  + static const char HEXCHAR[] = { +  '0','1','2','3','4','5','6','7','8','9', +  'A','B','C','D','E','F' + }; +    static const unsigned char hexdecode[256] =   {    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,       /* '0' - '9' */    0, 1, 2, 3, 4, 5, 6, 7, 8, 9,       16,16,16,16,16,16,16,   
pike.git/src/builtin.cmod:923:    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,    16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,   };      PMOD_EXPORT -  PIKEFUN string(0..255) string2hex(string s) +  PIKEFUN string(48..102) string2hex(string s, void|int uppercase) +  efun;    optflags OPT_TRY_OPTIMIZE;   {    struct pike_string *hex;    unsigned char *p,*st = (unsigned char *)s->str;    int i, l;       if (s->size_shift)    Pike_error("Bad argument 1 to string2hex(), expected 8-bit string.\n");       hex = begin_shared_string(2 * s->len);    p = (unsigned char *)hex->str;    l = s->len;    -  +  if( uppercase && uppercase->u.integer > 0) +  {    for (i=0; i<l; i++) { -  +  *p++ = HEXCHAR[*st>>4]; +  *p++ = HEXCHAR[*st&15]; +  st++; +  } +  } +  else +  { +  for (i=0; i<l; i++) {    *p++ = hexchar[*st>>4];    *p++ = hexchar[*st&15];    st++;    } -  +  }       RETURN end_shared_string(hex);   }      /*! @decl string(8bit) hex2string(string(8bit) hex)    *! @appears String.hex2string    *!    *! Convert a string of hexadecimal digits to binary    *! data. Non-hexadecimal characters will be ignored when between    *! tuples. Eg. "00 00" is ok, but "0 000" isn't.