pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.c:1962:    *! @[unicode_to_string()], @[utf8_to_string()]    */   PMOD_EXPORT void f_string_to_utf8(INT32 args)   {    ptrdiff_t len;    struct pike_string *in;    struct pike_string *out;    ptrdiff_t i,j;    INT_TYPE extended = 0;    PCHARP src; +  INT32 min, max;       get_all_args("string_to_utf8", args, "%W.%i", &in, &extended);       len = in->len;    -  +  check_string_range(in, 1, &min, &max); +  +  if (min >= 0 && max <= 0x7f) { +  /* 7bit string -- already valid utf8. */ +  pop_n_elems(args - 1); +  return; +  } +     for(i=0,src=MKPCHARP_STR(in); i < in->len; INC_PCHARP(src,1),i++) {    unsigned INT32 c = EXTRACT_PCHARP(src);    if (c & ~0x7f) {    /* 8bit or more. */    len++;    if (c & ~0x7ff) {    /* 12bit or more. */    len++;    if (c & ~0xffff) {    /* 17bit or more. */
pike.git/src/builtin_functions.c:2108:    *! @[unicode_to_string()]    */   PMOD_EXPORT void f_utf8_to_string(INT32 args)   {    struct pike_string *in;    struct pike_string *out;    ptrdiff_t len = 0;    int shift = 0;    ptrdiff_t i,j=0;    INT_TYPE extended = 0; +  INT32 min, max;       get_all_args("utf8_to_string", args, "%S.%i", &in, &extended);    -  +  check_string_range(in, 1, &min, &max); +  +  if (min >= 0 && max <= 0x7f) { +  /* 7bit string -- already valid utf8. */ +  pop_n_elems(args - 1); +  return; +  } +     for(i=0; i < in->len; i++) {    unsigned int c = STR0(in)[i];    len++;    if (c & 0x80) {    int cont = 0;       /* From table 3-6 in the Unicode standard 4.0: Well-Formed UTF-8    * Byte Sequences    *    * Code Points 1st Byte 2nd Byte 3rd Byte 4th Byte