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.692 2009/08/26 15:50:31 grubba Exp $ + || $Id: builtin_functions.c,v 1.693 2009/09/09 13:01:45 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:894:    bad_arg_error("search", Pike_sp-args, args, 3, "int(0..)", Pike_sp+2-args,    "Start must be greater or equal to zero.\n");    }    }       if(haystack->len < start)    bad_arg_error("search", Pike_sp-args, args, 3, "int(0..)", Pike_sp-args,    "Start must not be greater than the "    "length of the string.\n");    -  if(Pike_sp[1-args].type == T_STRING) { -  /* Handle searching for the empty string. */ -  if (Pike_sp[1-args].u.string->len) { -  start = string_search(haystack, -  Pike_sp[1-args].u.string, -  start); +  if ((Pike_sp[1-args].type == T_INT) || +  ((Pike_sp[1-args].type == T_STRING) && +  (Pike_sp[1-args].u.string->len == 1))) { +  INT_TYPE val; +  if (Pike_sp[1-args].type == T_INT) { +  val = Pike_sp[1-args].u.integer; +  } else { +  val = index_shared_string(Pike_sp[1-args].u.string, 0);    } -  } else if (Pike_sp[1-args].type == T_INT) { -  INT_TYPE val = Pike_sp[1-args].u.integer; +        switch(Pike_sp[-args].u.string->size_shift) {    case 0:    {    p_wchar0 *str = STR0(haystack);    if (val >= 256) {    start = -1;    break;    }    while (start < haystack->len) {
pike.git/src/builtin_functions.c:950: Inside #if defined(PIKE_DEBUG)
  #ifdef PIKE_DEBUG    default:    Pike_fatal("search(): Unsupported string shift: %d!\n",    haystack->size_shift);    break;   #endif    }    if (start >= haystack->len) {    start = -1;    } +  } else if(Pike_sp[1-args].type == T_STRING) { +  /* Handle searching for the empty string. */ +  if (Pike_sp[1-args].u.string->len) { +  start = string_search(haystack, +  Pike_sp[1-args].u.string, +  start); +  }    } else {    SIMPLE_BAD_ARG_ERROR("search", 2, "string | int");    }    pop_n_elems(args);    push_int64(start);    break;    }       case T_ARRAY:    start=0;