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.696 2010/02/18 14:50:41 srb Exp $ + || $Id: builtin_functions.c,v 1.697 2010/02/23 13:16:38 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:1064:    }    }    }    }    /* FALL_THROUGH */    default:    SIMPLE_BAD_ARG_ERROR("search", 1, "string|array|mapping|object");    }   }    - /*! @decl int has_prefix(string s, string prefix) + /*! @decl int has_prefix(string|object s, string prefix)    *!    *! Returns @expr{1@} if the string @[s] starts with @[prefix],    *! returns @expr{0@} (zero) otherwise.    */   PMOD_EXPORT void f_has_prefix(INT32 args)   {    struct pike_string *a, *b;       if(args<2)    SIMPLE_TOO_FEW_ARGS_ERROR("has_prefix", 2); -  if(Pike_sp[-args].type!=T_STRING) -  SIMPLE_ARG_TYPE_ERROR("has_prefix", 1, "string"); +  if((Pike_sp[-args].type!=T_STRING) && (Pike_sp[-args].type!=T_OBJECT)) +  SIMPLE_ARG_TYPE_ERROR("has_prefix", 1, "string|object");    if(Pike_sp[1-args].type!=T_STRING)    SIMPLE_ARG_TYPE_ERROR("has_prefix", 2, "string");    -  a = Pike_sp[-args].u.string; +     b = Pike_sp[1-args].u.string;    -  +  if (Pike_sp[-args].type == T_OBJECT) { +  ptrdiff_t i; +  struct object *o = Pike_sp[-args].u.object; +  int inherit_no = Pike_sp[-args].subtype; +  push_int(0); +  +  for (i = 0; i < b->len; i++) { +  p_wchar2 ch = index_shared_string(b, i); +  Pike_sp[-1].u.integer = i; +  /* Note: Integers do not need to be freed. */ +  object_index_no_free(Pike_sp-1, o, inherit_no, Pike_sp-1); +  if (Pike_sp[-1].type != T_INTEGER) { +  Pike_error("Unexepected value returned from index operator.\n"); +  } +  if (ch != Pike_sp[-1].u.integer) { +  pop_n_elems(args + 1); +  push_int(0); +  return; +  } +  } +  pop_n_elems(arg+1); +  push_int(1); +  return; +  } +  +  a = Pike_sp[-args].u.string; +     /* First handle some common special cases. */    if ((b->len > a->len) || (b->size_shift > a->size_shift)) {    pop_n_elems(args);    push_int(0);    return;    }       /* Trivial cases. */    if ((a == b)||(!b->len)) {    pop_n_elems(args);
pike.git/src/builtin_functions.c:9260:    ADD_EFUN("search",f_search,    tOr4(tFunc(tStr tOr(tStr,tInt) tOr(tVoid,tInt),    tInt),    tFunc(tArr(tSetvar(0,tMix)) tVar(0) tOr(tVoid,tInt),    tInt),    tFunc(tMap(tSetvar(1,tMix),tSetvar(2,tMix)) tVar(2) tOr(tVoid,tVar(1)),    tVar(1)),    tFunc(tObj tMix tOr(tVoid, tSetvar(3, tMix)), tVar(3))),    0);    -  ADD_EFUN2("has_prefix", f_has_prefix, tFunc(tStr tStr,tInt01), +  ADD_EFUN2("has_prefix", f_has_prefix, tFunc(tOr(tStr,tObj) tStr,tInt01),    OPT_TRY_OPTIMIZE, 0, 0);       ADD_EFUN2("has_suffix", f_has_suffix, tFunc(tStr tStr,tInt01),    OPT_TRY_OPTIMIZE, 0, 0);       ADD_EFUN("has_index",f_has_index,    tOr5(tFunc(tStr tIntPos, tInt01),    tFunc(tArray tIntPos, tInt01),    tFunc(tSet(tSetvar(0,tMix)) tVar(0), tInt01),    tFunc(tMap(tSetvar(1,tMix),tMix) tVar(1), tInt01),