pike.git / src / stralloc.c

version» Context lines:

pike.git/src/stralloc.c:1:   /*   || This file is part of Pike. For copyright information see COPYRIGHT.   || Pike is distributed under GPL, LGPL and MPL. See the file COPYING   || for more information. - || $Id: stralloc.c,v 1.184 2004/11/06 17:34:02 grubba Exp $ + || $Id: stralloc.c,v 1.185 2004/11/06 17:55:34 grubba Exp $   */      #include "global.h"   #include "stralloc.h"   #include "pike_macros.h"   #include "dynamic_buffer.h"   #include "pike_macros.h"   #include "pike_memory.h"   #include "pike_error.h"   #include "gc.h"
pike.git/src/stralloc.c:2390:    }    continue;       case '.':    state = STATE_PRECISION;    continue;       case 'h':    flags |= APPEND_WIDTH_HALF;    continue; +  +  case 'w': /* Same as l, but for %s. */    case 'l':    if (flags & APPEND_WIDTH_LONG) {    flags |= APPEND_WIDTH_LONG_LONG;    } else {    flags |= APPEND_WIDTH_LONG;    }    continue;       case 'O':    {
pike.git/src/stralloc.c:2411:    dynamic_buffer old_buf;    init_buf(&old_buf);    describe_svalue(va_arg(args, struct svalue *), 0, NULL);    string_builder_binary_strcat(s, pike_global_buffer.s.str,    pike_global_buffer.s.len);    toss_buffer(&pike_global_buffer);    restore_buffer(&old_buf);    }    break;    case 'S': +  /* Note: On some platforms this is an alias for %ls, so if you +  * want to output wchar_t strings, use %ls instead! +  */    {    struct pike_string *str = va_arg(args, struct pike_string *);    size_t len = str->len;    if (precision && (precision < len)) len = precision;    if (min_width > len) {    if (flags & APPEND_LEFT) {    string_builder_append(s, MKPCHARP_STR(str), len);    string_builder_fill(s, min_width - len, MKPCHARP(" ", 0),    4, 0);    } else {    string_builder_fill(s, min_width - len, MKPCHARP(" ", 0),    4, 0);    string_builder_append(s, MKPCHARP_STR(str), len);    }    } else {    string_builder_append(s, MKPCHARP_STR(str), len);    }    }    break;    case 's': -  { +  if (flags & APPEND_WIDTH_LONG) { +  /* Wide string: %ws, %ls or %lls +  */ +  PCHARP str; +  size_t len; +  if ((flags & APPEND_WIDTH_LONG)== APPEND_WIDTH_LONG) { +  str = MKPCHARP(va_arg(args, p_wchar1 *), 1); +  } else { +  str = MKPCHARP(va_arg(args, p_wchar2 *), 2); +  } +  len = pcharp_strlen(str); +  if (precision && precision < len) len = precision; +  if (min_width > len) { +  if (flags & APPEND_LEFT) { +  string_builder_append(s, str, len); +  string_builder_fill(s, min_width - len, MKPCHARP(" ", 0), +  4, 0); +  } else { +  string_builder_fill(s, min_width - len, MKPCHARP(" ", 0), +  4, 0); +  string_builder_append(s, str, len); +  } +  } else { +  string_builder_append(s, str, len); +  } +  } else {    const char *str = va_arg(args, char *);    size_t len = strlen(str);    if (precision && precision < len) len = precision;    if (min_width > len) {    if (flags & APPEND_LEFT) {    string_builder_binary_strcat(s, str, len);    string_builder_fill(s, min_width - len, MKPCHARP(" ", 0),    4, 0);    } else {    string_builder_fill(s, min_width - len, MKPCHARP(" ", 0),
pike.git/src/stralloc.c:2480:    break;    case 'u':    string_builder_append_integerv(s, args, 10,    flags, min_width, precision);    break;    case 'd':    string_builder_append_integerv(s, args, 10,    flags | APPEND_SIGNED,    min_width, precision);    break; +  +  /* FIMXE: TODO: Doubles (ie 'a', 'e', 'E', 'f', 'g', 'G'). */ +     default:    Pike_fatal("string_builder_vsprintf(): Invalid formatting method: "    "'%c' 0x%x.\n", fmt[-1], fmt[-1]);    }    break;    }    } else {    const char *start = fmt;    while (*fmt && (*fmt != '%'))    fmt++;