Defines | Functions

strfind.cc File Reference

#include <string>
#include <climits>
#include <algorithm>
#include <deque>
#include "Cell.h"
#include "ov.h"
#include "defun-dld.h"
#include "unwind-prot.h"
#include "gripes.h"
#include "utils.h"
Include dependency graph for strfind.cc:

Go to the source code of this file.

Defines

#define ORD(ch)   static_cast<unsigned char>(ch)
#define TABSIZE   (UCHAR_MAX + 1)

Functions

 DEFUN_DLD (strfind, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {@var{idx} =} strfind (@var{str}, @var{pattern})\n\ @deftypefnx {Loadable Function} {@var{idx} =} strfind (@var{cellstr}, @var{pattern})\n\ Search for @var{pattern} in the string @var{str} and return the\n\ starting index of every such occurrence in the vector @var{idx}.\n\ If there is no such occurrence, or if @var{pattern} is longer\n\ than @var{str}, then @var{idx} is the empty array @code{[]}.\n\ \n\ If a cell array of strings @var{cellstr} is specified\n\ then @var{idx} is a cell array of vectors, as specified\n\ above. Examples:\n\ \n\ @example\n\ @group\n\ strfind (\"abababa\", \"aba\")\n\ @result{} [1, 3, 5]\n\ \n\ strfind (@{\"abababa\", \"bebebe\", \"ab\"@}, \"aba\")\n\ @result{} ans =\n\ @{\n\ [1,1] =\n\ \n\ 1 3 5\n\ \n\ [1,2] = [](1x0)\n\ [1,3] = [](1x0)\n\ @}\n\ @end group\n\ @end example\n\ @seealso{findstr, strmatch, regexp, regexpi, find}\n\ @end deftypefn")
 DEFUN_DLD (strrep, args,,"-*- texinfo -*-\n\ @deftypefn {Loadable Function} {} strrep (@var{s}, @var{ptn}, @var{rep})\n\ @deftypefnx {Loadable Function} {} strrep (@var{s}, @var{ptn}, @var{rep}, \"overlaps\", @var{o})\n\ Replace all occurrences of the substring @var{ptn} in the string @var{s}\n\ with the string @var{rep} and return the result. For example:\n\ \n\ @example\n\ @group\n\ strrep (\"This is a test string\", \"is\", \"&%$\")\n\ @result{} \"Th&%$ &%$ a test string\"\n\ @end group\n\ @end example\n\ \n\ @var{s} may also be a cell array of strings, in which case the replacement is\n\ done for each element and a cell array is returned.\n\ @seealso{regexprep, strfind, findstr}\n\ @end deftypefn")
static void qs_preprocess (const Array< char > &needle, octave_idx_type table[TABSIZE])
static Array< charqs_replace (const Array< char > &str, const Array< char > &pat, const Array< char > &rep, const octave_idx_type table[TABSIZE], bool overlaps=true)
static Array< octave_idx_typeqs_search (const Array< char > &needle, const Array< char > &haystack, const octave_idx_type table[TABSIZE], bool overlaps=true)

Define Documentation

#define ORD (   ch  )     static_cast<unsigned char>(ch)

Definition at line 41 of file strfind.cc.

Referenced by qs_preprocess(), and qs_search().

#define TABSIZE   (UCHAR_MAX + 1)

Definition at line 42 of file strfind.cc.

Referenced by DEFUN_DLD().


Function Documentation

DEFUN_DLD ( strfind  ,
args   
)
DEFUN_DLD ( strrep  ,
args   
)
static void qs_preprocess ( const Array< char > &  needle,
octave_idx_type  table[TABSIZE] 
) [static]

Definition at line 47 of file strfind.cc.

References Array< T >::data(), Array< T >::numel(), ORD, and x.

Referenced by DEFUN_DLD().

static Array<char> qs_replace ( const Array< char > &  str,
const Array< char > &  pat,
const Array< char > &  rep,
const octave_idx_type  table[TABSIZE],
bool  overlaps = true 
) [static]
static Array<octave_idx_type> qs_search ( const Array< char > &  needle,
const Array< char > &  haystack,
const octave_idx_type  table[TABSIZE],
bool  overlaps = true 
) [static]

Definition at line 61 of file strfind.cc.

References Array< T >::data(), min(), Array< T >::numel(), ORD, x, and Array< T >::xelem().

Referenced by DEFUN_DLD(), and qs_replace().

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines