pike.git/
src/
builtin.cmod
Branch:
Tag:
Non-build tags
All tags
No tags
2004-04-29
2004-04-29 23:54:17 by Martin Nilsson <mani@lysator.liu.se>
c5e2a4182d25dc2378827b5fcbcbdc64fb27ec49 (
47
lines) (+
36
/-
11
)
[
Show
|
Annotate
]
Branch:
7.9
Added autodoc. Made a type_field-related optimization.
Rev: src/builtin.cmod:1.157
2:
|| 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"
592:
/*! @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()], @[`/()]
617:
break; case 1: /* maybe optimize? */
+
/* It is already fairly optimized in pike_search_engine. */
default: for (i=0; i<haystack->len; i++) {
1895:
*/ /*! @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 {
1933:
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;
2171:
*/ /*! @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 {
2203:
} }
-
/*! @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_) {