ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Macros | Enumerations | Functions
Match.cxx File Reference
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include "Match.h"
Include dependency graph for Match.cxx:

Go to the source code of this file.

Macros

#define BOL   '^'
 
#define EOL   '$'
 
#define ANY   '.'
 
#define CCL   '['
 
#define CCLEND   ']'
 
#define NCCL   '^'
 
#define CLOSURE   '*'
 
#define PCLOSE   '+'
 
#define OPT   '?'
 
#define ISHEXDIGIT(x)   isxdigit((unsigned char)x)
 
#define ISOCTDIGIT(x)   ('0'<=(x) && (x)<='7')
 
#define MAPSIZE   16
 
#define E_NONE   0
 
#define E_ILLEGAL   1
 
#define E_NOMEM   2
 
#define E_PAT   3
 

Enumerations

enum  Eaction {
  kBOL = (0x8000 | '^'), kEOL = (0x8000 | '$'), kANY = (0x8000 | '.'), kCCL = (0x8000 | '['),
  kOPT = (0x8000 | '?'), kCLOSE = (0x8000 | '*'), kPCLOSE = (0x8000 | '+'), kEND = (0x8000 | 0)
}
 

Functions

void ADVANCE (const Pattern_t *&pat)
 Advance a pointer into the pattern template to the next pattern element, this is a+1 for all pattern elements but kCCL, where you have to skip past both the kCCL character and the bitmap that follows that character. More...
 
static void SETBIT (unsigned char b, Pattern_t *map)
 
static int TSTBIT (unsigned char b, const Pattern_t *map)
 
static const char * doccl (Pattern_t *map, const char *src)
 Set bits in the map corresponding to characters specified in the src character class. More...
 
static int hex2bin (int c)
 Convert the hex digit represented by 'c' to an int. More...
 
static int oct2bin (int c)
 Convert the hex digit represented by 'c' to an int. More...
 
static int omatch (const char **strp, size_t *slenp, const Pattern_t *pat, const char *start)
 Match one pattern element, pointed at by pat, against the character at **strp. More...
 
static const char * patcmp (const char *str, size_t slen, const Pattern_t *pat, const char *start)
 Like strcmp, but compares str against pat. More...
 
static int esc (const char **s)
 Map escape sequences into their equivalent symbols. More...
 
int Makepat (const char *exp, Pattern_t *pat, int maxpat)
 Make a pattern template from the string pointed to by exp. More...
 
const char * Matchs (const char *str, size_t slen, const Pattern_t *pat, const char **startpat)
 Match a string with a pattern. More...
 

Macro Definition Documentation

#define ANY   '.'

Definition at line 32 of file Match.cxx.

Referenced by Makepat().

#define BOL   '^'

Definition at line 30 of file Match.cxx.

Referenced by Makepat().

#define CCL   '['

Definition at line 33 of file Match.cxx.

Referenced by doccl(), and Makepat().

#define CCLEND   ']'

Definition at line 34 of file Match.cxx.

Referenced by doccl(), and Makepat().

#define CLOSURE   '*'

Definition at line 36 of file Match.cxx.

Referenced by Makepat().

#define E_ILLEGAL   1

Definition at line 104 of file Match.cxx.

Referenced by Makepat().

#define E_NOMEM   2

Definition at line 105 of file Match.cxx.

Referenced by Makepat().

#define E_NONE   0

Definition at line 103 of file Match.cxx.

Referenced by Makepat().

#define E_PAT   3

Definition at line 106 of file Match.cxx.

Referenced by Makepat().

#define EOL   '$'

Definition at line 31 of file Match.cxx.

Referenced by Makepat().

#define ISHEXDIGIT (   x)    isxdigit((unsigned char)x)

Definition at line 54 of file Match.cxx.

Referenced by esc().

#define ISOCTDIGIT (   x)    ('0'<=(x) && (x)<='7')

Definition at line 61 of file Match.cxx.

Referenced by esc().

#define MAPSIZE   16

Definition at line 64 of file Match.cxx.

Referenced by ADVANCE(), doccl(), and Makepat().

#define NCCL   '^'

Definition at line 35 of file Match.cxx.

Referenced by doccl().

#define OPT   '?'
#define PCLOSE   '+'

Definition at line 37 of file Match.cxx.

Referenced by Makepat().

Enumeration Type Documentation

enum Eaction
Enumerator
kBOL 
kEOL 
kANY 
kCCL 
kOPT 
kCLOSE 
kPCLOSE 
kEND 

Definition at line 40 of file Match.cxx.

Function Documentation

void ADVANCE ( const Pattern_t *&  pat)
inline

Advance a pointer into the pattern template to the next pattern element, this is a+1 for all pattern elements but kCCL, where you have to skip past both the kCCL character and the bitmap that follows that character.

Definition at line 72 of file Match.cxx.

Referenced by patcmp().

static const char * doccl ( Pattern_t map,
const char *  src 
)
static

Set bits in the map corresponding to characters specified in the src character class.

Definition at line 244 of file Match.cxx.

Referenced by Makepat().

static int esc ( const char **  s)
static

Map escape sequences into their equivalent symbols.

Return the equivalent ASCII character. *s is advanced past the escape sequence. If no escape sequence is present, the current character is returned and the string is advanced by one. The following are recognized:

  • \b backspace
  • \f formfeed
  • \n newline
  • \r carriage return
  • \s space
  • \t tab
  • \e ASCII ESC character ('\033')
  • \DDD number formed of 1-3 octal digits
  • \xDD number formed of 1-2 hex digits
  • \^C C = any letter. Control code

Definition at line 438 of file Match.cxx.

Referenced by doccl(), and Makepat().

static int hex2bin ( int  c)
static

Convert the hex digit represented by 'c' to an int.

'c' must be one of: 0123456789abcdefABCDEF

Definition at line 406 of file Match.cxx.

Referenced by esc().

int Makepat ( const char *  exp,
Pattern_t pat,
int  maxpat 
)

Make a pattern template from the string pointed to by exp.

Stop when \0 is found in exp. The pattern template is assembled in pat whose length is given by maxpat.

Return:

  • E_ILLEGAL Illegal input pattern.
  • E_NOMEM out of memory.
  • E_PAT pattern too long.

Definition at line 129 of file Match.cxx.

Referenced by TRegexp::GenPattern(), and TTabCom::SetPattern().

const char* Matchs ( const char *  str,
size_t  slen,
const Pattern_t pat,
const char **  startpat 
)

Match a string with a pattern.

Definition at line 220 of file Match.cxx.

Referenced by TTabCom::DetermineContext(), and TRegexp::Index().

static int oct2bin ( int  c)
static

Convert the hex digit represented by 'c' to an int.

'c' must be a digit in the range '0'-'7'.

Definition at line 415 of file Match.cxx.

Referenced by esc().

static int omatch ( const char **  strp,
size_t slenp,
const Pattern_t pat,
const char *  start 
)
static

Match one pattern element, pointed at by pat, against the character at **strp.

Return 0 on a failure, 1 on success. *strp is advanced to skip over the matched character on a successful match. Closure is handled one level up by patcmp().

"start" points at the character at the left edge of the line. This might not be the same thing as *strp if the search is starting in the middle of the string. An end-of- line anchor matches end of string only.

Definition at line 369 of file Match.cxx.

Referenced by patcmp().

static const char * patcmp ( const char *  str,
size_t  slen,
const Pattern_t pat,
const char *  start 
)
static

Like strcmp, but compares str against pat.

Each element of str is compared with the template until either a mis-match is found or the end of the template is reached. In the former case a 0 is returned; in the latter, a pointer into str (pointing after the last character in the matched pattern) is returned. start points at the first character in the string, which might not be the same thing as str if the search started in the middle of the string.

Definition at line 287 of file Match.cxx.

Referenced by Matchs().

static void SETBIT ( unsigned char  b,
Pattern_t map 
)
static

Definition at line 89 of file Match.cxx.

Referenced by doccl().

static int TSTBIT ( unsigned char  b,
const Pattern_t map 
)
static

Definition at line 96 of file Match.cxx.

Referenced by omatch().