pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*- -  * $Id: builtin.cmod,v 1.59 2001/07/13 11:26:37 grubba Exp $ +  * $Id: builtin.cmod,v 1.60 2001/07/25 23:42:58 nilsson Exp $    */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "opcodes.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"
pike.git/src/builtin.cmod:1119:    }    }    /* NOTE: res has already been pushed on the stack. */   }      #define INITIAL_BUF_LEN 4096      /*! @module String    */    - PIKECLASS Buffer +    /*! @class Buffer    *! A buffer, used for building strings. It's    *! conceptually similar to a string, but you can only @[add]    *! strings to it, and you can only @[get] the value from it once.    *!    *! There is a reason for those seemingly rather odd limitations,    *! it makes it possible to do some optimizations that really speed    *! things up.    *!    *! You do not need to use this class unless you add very many
pike.git/src/builtin.cmod:1145:    *! @code{    *! String.Buffer b = String.Buffer( );    *!    *! function add = b->add;    *!    *! .. call add several times in code ...    *!    *! string result = b->get(); // also clears the buffer    *! @}    */ + 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 );       -  PIKEFUN void create( int|void size ) +     /*! @decl void create()    *!    *! Initializes a new buffer.    *!    *! If no @[initial_size] is specified, 4096 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.    */ -  +  PIKEFUN void create( int|void size )    {    struct Buffer_struct *str = THIS;    if( args )    str->initial = MAXIMUM( size->u.integer, 512 );    else    {    str->initial = 256;    push_int(0);    }    }
pike.git/src/builtin.cmod:1276:    apply( res, "add", 1 );    RETURN res;    }       PIKEFUN object `+=( string what )    {    f_Buffer_add( 1 );    REF_RETURN fp->current_object;    }    -  PIKEFUN int add( string ... arg1 ) +     /*! @decl void add(string ... data)    *!    *! Adds @[data] to the buffer. Returns the size of the buffer.    *!    */ -  +  PIKEFUN int add( string ... arg1 )    {    struct Buffer_struct *str = THIS;    int j;    struct pike_string *a;       for( j = 0; j<args; j++ )    {    a = Pike_sp[-args+j].u.string;    if( !str->str.s )    init_string_builder_alloc( &str->str, str->initial, a->size_shift );    string_builder_shared_strcat( &str->str, a );    }    RETURN str->str.s->len;    }    -  PIKEFUN string get_copy() +     /*! @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 )    {    ptrdiff_t len = str->len;    if( len > 0 )    {    char *d = (char *)str->str;    switch( str->size_shift )    {
pike.git/src/builtin.cmod:1329:    case 2:    RETURN make_shared_binary_string2((int*)d,len>>2);    break;    }    }    }    push_text("");    return;    }    -  PIKEFUN string get( ) +     /*! @decl string get()    *!    *! Get the data from the buffer.    *!    *! @note    *! This will clear the data in the buffer    */ -  +  PIKEFUN string get( )    {    struct Buffer_struct *str = THIS;    if( str->str.s )    {    struct pike_string *s = finish_string_builder( &str->str );    str->str.malloced = 0;    str->str.s = 0;    RETURN s;    }    pop_n_elems(args);    push_text("");    return;    }    -  PIKEFUN int _sizeof() +     /*! @decl int _sizeof()    *!    *! Returns the size of the buffer.    */ -  +  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 ) );    }       EXIT    {    struct Buffer_struct *str = THIS;    if( str->str.s )    free_string_builder( &str->str );    }   }    - /*! @endmodule + /*! @endclass    */    - /*! @module String -  */ -  +    /*! @class Replace    */   PIKECLASS multi_string_replace   {    CVAR struct tupel    {    int prefix;    struct pike_string *ind;    struct pike_string *val;    } *v;