pike.git
/
src
/
builtin.cmod
version
»
Context lines:
10
20
40
80
file
none
3
pike.git/src/builtin.cmod:2348:
*/ PIKECLASS Buffer { CVAR struct string_builder str; CVAR int initial; void f_Buffer_get_copy( INT32 args ); void f_Buffer_get( INT32 args ); void f_Buffer_add( INT32 args );
+
typedef void (_low_f_sprintf)(INT32, int, struct string_builder *);
+
static _low_f_sprintf *low_f_sprintf;
/*! @decl void create(int initial_size) *! *! Initializes a new buffer. *! *! If no @[initial_size] is specified, 256 is used. If you *! know approximately how big the buffer will be, you can optimize *! the operation of @[add()] (slightly) by passing the size to this *! function. */
pike.git/src/builtin.cmod:2617:
/*! @decl void putchar(int c) *! Appends the character @[c] at the end of the string. */ PIKEFUN void putchar(int c) { struct Buffer_struct *str = THIS; if(!str->str.s) init_string_builder_alloc(&str->str, str->initial, 0); string_builder_putchar(&str->str, c); }
+
/*! @decl int sprintf(mixed ... arguments)
+
*! Appends the output from @[sprintf] at the end of the string.
+
*/
+
PIKEFUN int sprintf(mixed ... arguments)
+
{
+
// FIXME: Reset length on exception?
+
struct Buffer_struct *str = THIS;
+
if(!str->str.s)
+
init_string_builder_alloc(&str->str, str->initial, 0);
+
low_f_sprintf(args, 0, &str->str);
+
RETURN str->str.s->len;
+
}
+
/*! @decl string get_copy() *! *! Get the data from the buffer. Significantly slower than @[get], *! but does not clear the buffer. */ PIKEFUN string get_copy() { struct pike_string *str = THIS->str.s; if( str ) {
pike.git/src/builtin.cmod:2685:
PIKEFUN int _sizeof() { struct Buffer_struct *str = THIS; RETURN str->str.s ? str->str.s->len : 0; } INIT { struct Buffer_struct *str = THIS; MEMSET( str, 0, sizeof( *str ) );
+
low_f_sprintf = PIKE_MODULE_IMPORT(sprintf, low_f_sprintf);
} EXIT gc_trivial; { struct Buffer_struct *str = THIS; if( str->str.s ) free_string_builder( &str->str ); }