pike.git / src / builtin_functions.c

version» Context lines:

pike.git/src/builtin_functions.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: builtin_functions.c,v 1.605 2006/01/27 20:29:28 grubba Exp $ + || $Id: builtin_functions.c,v 1.606 2006/03/09 15:55:07 grubba 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_functions.c:3385:    }       if( (from->type_field & ~BIT_STRING) &&    (array_fix_type_field(from) & ~BIT_STRING) )    Pike_error("replace: from array not array(string).\n");       if( (to->type_field & ~BIT_STRING) &&    (array_fix_type_field(to) & ~BIT_STRING) )    Pike_error("replace: to array not array(string).\n");    +  if (from->size == 1) { +  /* Just a single string... */ +  return string_replace(str, from->item[0].u.string, to->item[0].u.string); +  } +     /* NOTE: The following test is needed, since sizeof(struct tupel)    * is somewhat greater than sizeof(struct svalue).    */    if (from->size > (ptrdiff_t)(LONG_MAX/sizeof(struct tupel)))    Pike_error("Array too large (size %" PRINTPTRDIFFT "d "    "exceeds %" PRINTSIZET "u).\n",    from->size, (size_t)(LONG_MAX/sizeof(struct tupel)));    ctx.v=(struct tupel *)xalloc(sizeof(struct tupel)*from->size);    init_string_builder(&ctx.ret,str->size_shift);    SET_ONERROR (uwp, free_replace_many_context, &ctx);
pike.git/src/builtin_functions.c:3471:    length--;    }       UNSET_ONERROR (uwp);    free((char *)ctx.v);    return finish_string_builder(&ctx.ret);   }      /*! @decl string replace(string s, string from, string to)    *! @decl string replace(string s, array(string) from, array(string) to) +  *! @decl string replace(string s, array(string) from, string to)    *! @decl string replace(string s, mapping(string:string) replacements)    *! @decl array replace(array a, mixed from, mixed to)    *! @decl mapping replace(mapping a, mixed from, mixed to)    *!    *! Generic replace function.    *!    *! This function can do several kinds replacement operations, the    *! different syntaxes do different things as follows:    *!    *! If all the arguments are strings, a copy of @[s] with every
pike.git/src/builtin_functions.c:3523:    }       stack_dup();    f_indices(1);    stack_swap();    f_values(1);    args++;    }    else    SIMPLE_TOO_FEW_ARGS_ERROR("replace", 3); +  } else if (args > 3) { +  pop_n_elems(args-3); +  args = 3;    }       switch(Pike_sp[-args].type)    {    case T_ARRAY:    {    array_replace(Pike_sp[-args].u.array,Pike_sp+1-args,Pike_sp+2-args);    pop_n_elems(args-1);    break;    }
pike.git/src/builtin_functions.c:3559:    case T_STRING:    if(Pike_sp[2-args].type != T_STRING)    SIMPLE_BAD_ARG_ERROR("replace", 3, "string");       s=string_replace(Pike_sp[-args].u.string,    Pike_sp[1-args].u.string,    Pike_sp[2-args].u.string);    break;       case T_ARRAY: -  if(Pike_sp[2-args].type != T_ARRAY) -  SIMPLE_BAD_ARG_ERROR("replace", 3, "array"); +  if (Pike_sp[2-args].type == T_STRING) { +  push_int(Pike_sp[1-args].u.array->size); +  stack_swap(); +  f_allocate(2); +  } else if(Pike_sp[2-args].type != T_ARRAY) +  SIMPLE_BAD_ARG_ERROR("replace", 3, "array|string");       s=replace_many(Pike_sp[-args].u.string,    Pike_sp[1-args].u.array,    Pike_sp[2-args].u.array);       }    pop_n_elems(args);    push_string(s);    break;    }
pike.git/src/builtin_functions.c:8632:      /* function(int:void) */    ADD_EFUN("random_seed",f_random_seed,    tFunc(tInt,tVoid),OPT_SIDE_EFFECT);       ADD_EFUN("random_string",f_random_string,    tFunc(tInt,tString), OPT_EXTERNAL_DEPEND);       ADD_EFUN2("replace", f_replace,    tOr5(tFunc(tStr tStr tStr,tStr), -  tFunc(tStr tArr(tStr) tArr(tStr),tStr), +  tFunc(tStr tArr(tStr) tOr(tArr(tStr), tStr), tStr),    tFunc(tStr tMap(tStr,tStr),tStr),    tFunc(tSetvar(0,tArray) tMix tMix,tVar(0)),    tFunc(tSetvar(1,tMapping) tMix tMix,tVar(1))),    OPT_TRY_OPTIMIZE, optimize_replace, 0);      /* function(int:int)|function(string:string)|function(0=array:0) */    ADD_EFUN("reverse",f_reverse,    tOr3(tFunc(tInt,tInt),    tFunc(tStr,tStr),    tFunc(tSetvar(0, tArray),tVar(0))),0);