pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:2642:    s->s->len+=str->len;   }      PMOD_EXPORT ptrdiff_t string_builder_quote_string(struct string_builder *buf,    const struct pike_string *str,    ptrdiff_t i,    ptrdiff_t max_len,    int flags)   {    ptrdiff_t old_len = buf->s->len; +  int inhibit_whitespace = (flags & QUOTE_NORMALIZE_WS);       for (; i < str->len; i++) {    p_wchar2 ch = index_shared_string(str, i);    if (ch < 0 || ch > 0xffff) {    /* Huge character. */    string_builder_binary_strcat(buf, "\\U", 2);    string_builder_append_integer(buf, (unsigned INT32)ch, 16, APPEND_ZERO_PAD, 8, 8); -  +  inhibit_whitespace = 0;    } else if (ch > 0xff) {    /* Unicode character. */    string_builder_binary_strcat(buf, "\\u", 2);    string_builder_append_integer(buf, ch, 16, APPEND_ZERO_PAD, 4, 4); -  +  inhibit_whitespace = 0;    } else if (ch & 0x60) {    /* Printable character or DEL. */ -  if (ch == '\177') { -  /* DEL */ +  if (ch == '\177' || ch == ' ') { +  /* DEL or SP */    goto ctrl_char; -  } else if ((ch == '"') || (ch == '\\')) { +  } +  +  inhibit_whitespace = 0; +  +  if ((ch == '"') || (ch == '\\')) {    string_builder_putchar(buf, '\\');    }    string_builder_putchar(buf, ch);    } else {    p_wchar2 next_ch;    ctrl_char: -  /* Control character. */ +  /* Control character or whitespace. */ +  if (flags & QUOTE_NORMALIZE_WS) { +  /* Normalize all sequences of whitespace to a single SP. */ +  if (!inhibit_whitespace) { +  string_builder_putchar(buf, ' '); +  inhibit_whitespace = 1; +  } +  goto next; +  }    string_builder_putchar(buf, '\\');    if ((ch > 6) && (ch < 14)) {    string_builder_putchar(buf, "0123456abtnvfr"[ch]);    if ((ch == 10) && (flags & QUOTE_BREAK_AT_LF)) {    if (buf->s->len > max_len) {    /* Too bad; no place for the lf. */    buf->s->len = old_len;    return i;    }    return i+1;
pike.git/src/stralloc.c:2702:    string_builder_append_integer(buf, ch, 8, 0, 1, 1);    string_builder_binary_strcat(buf, "\"\"", 2);    }    goto next;    }    string_builder_append_integer(buf, ch, 8, 0, 1, 1);    }    next:    if (buf->s->len > max_len) {    buf->s->len = old_len; -  return i; +  inhibit_whitespace = 0; +  break;    }    old_len = buf->s->len;    } -  +  if (inhibit_whitespace && (inhibit_whitespace != QUOTE_NORMALIZE_WS)) { +  /* Get rid of the SP at the end of the buffer. */ +  buf->s->len--; +  }    return i;   }      PMOD_EXPORT void string_builder_append_integer(struct string_builder *s,    INT64 val,    unsigned int base,    int flags,    size_t min_width,    size_t precision)   {