pike.git / src / builtin.cmod

version» Context lines:

pike.git/src/builtin.cmod:1:   /* -*- c -*-   || 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: builtin.cmod,v 1.156 2004/04/25 19:50:18 nilsson Exp $ + || $Id: builtin.cmod,v 1.157 2004/04/29 23:54:17 nilsson Exp $   */      #include "global.h"   #include "interpret.h"   #include "svalue.h"   #include "pike_macros.h"   #include "object.h"   #include "program.h"   #include "array.h"   #include "pike_error.h"
pike.git/src/builtin.cmod:585:    bad_arg_error("mkmapping", Pike_sp-args, args, 2, "array", Pike_sp+1-args,    "mkmapping called on arrays of different sizes (%d != %d)\n",    ind->size, val->size);       RETURN mkmapping(ind, val);   }      /*! @decl int count(string haystack, string needle)    *! @belongs String    *! -  *! Count the number of non-overlapping times the string @[needle] occurrs -  *! in the string @[haystack]. +  *! Count the number of non-overlapping times the string @[needle] +  *! occurs in the string @[haystack]. The special cases for the needle +  *! @expr{""@} is that it occurs one time in the empty string, zero +  *! times in a one character string and between every character +  *! (length-1) in any other string.    *!    *! @seealso    *! @[search()], @[`/()]    */   PIKEFUN int string_count(string haystack, string needle)    errname String.count;    optflags OPT_TRY_OPTIMIZE;   {    ptrdiff_t c = 0;    ptrdiff_t i, j;
pike.git/src/builtin.cmod:610:    case 0:    switch (haystack->len)    {    case 0: c=1; break; /* "" appears one time in "" */    case 1: c=0; break; /* "" doesn't appear in "x" */    default: c=haystack->len-1; /* one time between each character */    }    break;    case 1:    /* maybe optimize? */ +  /* It is already fairly optimized in pike_search_engine. */    default:    for (i=0; i<haystack->len; i++)    {    j=string_search(haystack,needle,i);    if (j==-1) break;    i=j+needle->len-1;    c++;    }    break;    }
pike.git/src/builtin.cmod:1888:    struct Buffer_struct *str = THIS;    if( str->str.s )    free_string_builder( &str->str );    }   }      /*! @endclass    */      /*! @class Replace +  *! +  *! This is a "compiled" version of the @[replace] function applied on +  *! a string, with more than one replace string. The replace strings +  *! are given to the create method as a @i{from@} and @i{to@} array +  *! and are then analyzed. The @expr{`()@} is then called with a +  *! string and the replace rules in the Replace object will be +  *! applied. The Replace object is used internally by the Pike +  *! optimizer and need not be used manually.    */   PIKECLASS multi_string_replace   {    CVAR struct tupel    {    int prefix;    struct pike_string *ind;    struct pike_string *val;    } *v;    CVAR size_t v_sz;
pike.git/src/builtin.cmod:1926:    return;    }    if (!from_ || !to_) {    Pike_error("Bad number of arguments to create().\n");    }    from = from_->u.array;    to = to_->u.array;    if (from->size != to->size) {    Pike_error("Replace must have equal-sized from and to arrays.\n");    } -  for (i = 0; i < (int)from->size; i++) { -  if (from->item[i].type != PIKE_T_STRING) { -  Pike_error("Replace: from array is not an array(string).\n"); +  +  if(from->type_field & ~BIT_STRING) { +  array_fix_type_field(from); +  if(from->type_field & ~BIT_STRING) +  SIMPLE_BAD_ARG_ERROR("Replace", 1, "array(string)");    } -  if (to->item[i].type != PIKE_T_STRING) { -  Pike_error("Replace: to array is not an array(string).\n"); +  if(to->type_field & ~BIT_STRING) { +  array_fix_type_field(to); +  if(to->type_field & ~BIT_STRING) +  SIMPLE_BAD_ARG_ERROR("Replace", 2, "array(string)");    } -  } +     if (THIS->v) {    for (i = 0; i < (int)THIS->v_sz; i++) {    if (!THIS->v[i].ind) break;    free_string(THIS->v[i].ind);    THIS->v[i].ind = NULL;    free_string(THIS->v[i].val);    THIS->v[i].val = NULL;    }    }    if (THIS->v && (THIS->v_sz < (size_t)from->size)) {
pike.git/src/builtin.cmod:2164:    THIS->v = NULL;    THIS->v_sz = 0;    THIS->sz = 0;    }   }      /*! @endclass    */      /*! @class SingleReplace +  *! +  *! This is a "compiled" version of the @[replace] function applied on +  *! a string, with just one replace string. The replace strings are +  *! given to the create method as a @i{from@} and @i{tom@} string and +  *! are then analyzed. The @expr{`()@} is then called with a string +  *! and the replace rule in the Replace object will be applied. The +  *! Replace object is used internally by the Pike optimizer and need +  *! not be used manually.    */   PIKECLASS single_string_replace   {    CVAR SearchMojt mojt;    CVAR struct pike_string *del;    CVAR struct pike_string *to;       INIT    {    THIS->mojt.vtab = NULL;
pike.git/src/builtin.cmod:2196:    if (THIS->del) {    free_string(THIS->del);    THIS->del = NULL;    }    if (THIS->to) {    free_string(THIS->to);    THIS->to = NULL;    }    }    -  /*! @decl void create(string|void del, string|void to) +  /*! @decl void create(string|void from, string|void to)    */    PIKEFUN void create(string|void del_, string|void to_)    {    struct pike_string *del;    struct pike_string *to;       /* Clean up... */    exit_single_string_replace_struct();       if (!del_) return;