Defines | Variables
core/vul/vul_reg_exp.cxx File Reference

Copyright (C) 1991 Texas Instruments Incorporated. More...

#include "vul_reg_exp.h"
#include <vcl_iostream.h>
#include <vcl_cstring.h>
#include <vcl_cstddef.h>

Go to the source code of this file.

Defines

#define END   0
#define BOL   1
#define EOL   2
#define ANY   3
#define ANYOF   4
#define ANYBUT   5
#define BRANCH   6
#define BACK   7
#define EXACTLY   8
#define NOTHING   9
#define STAR   10
#define PLUS   11
#define OPEN   20
#define CLOSE   30
#define OP(p)   (*(p))
#define NEXT(p)   (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))
#define OPERAND(p)   ((p) + 3)
#define UCHARAT(p)   ((const unsigned char*)(p))[0]
#define FAIL(m)   { regerror(m); return NULL; }
#define ISMULT(c)   ((c) == '*' || (c) == '+' || (c) == '?')
#define META   "^$.[()|?+*\\"
#define HASWIDTH   01
#define SIMPLE   02
#define SPSTART   04
#define WORST   0

Variables

const unsigned char MAGIC = 0234

Detailed Description

Copyright (C) 1991 Texas Instruments Incorporated.

Permission is granted to any individual or institution to use, copy, modify, and distribute this software, provided that this complete copyright and permission notice is maintained, intact, in all copies and supporting documentation.

Texas Instruments Incorporated provides this software "as is" without express or implied warranty.

Created: MNF Jun 13, 1989 Initial Design and Implementation Updated: LGO Aug 09, 1989 Inherit from Generic Updated: MBN Sep 07, 1989 Added conditional exception handling Updated: MBN Dec 15, 1989 Sprinkled "const" qualifiers all over the place! Updated: DLS Mar 22, 1991 New lite version

This is the header file for the regular expression class. An object of this class contains a regular expression, in a special "compiled" format. This compiled format consists of several slots all kept as the objects private data. The vul_reg_exp class provides a convenient way to represent regular expressions. It makes it easy to search for the same regular expression in many different strings without having to compile a string to regular expression format more than necessary.

A regular expression allows a programmer to specify complex patterns that can be searched for and matched against the character string of a String object. In its simplest case, a regular expression is a sequence of characters with which you can search for exact character matches. However, many times you may not know the exact sequence you want to find, or you may only want to find a match at the beginning or end of a String. The vul_reg_exp object allows specification of such patterns by utilizing the following regular expression meta-characters (note that more one of these meta-characters can be used in a single regular expression in order to create complex search patterns):

There are three constructors for vul_reg_exp. One just creates an empty vul_reg_exp object. Another creates a vul_reg_exp object and initializes it with a regular expression that is given in the form of a char*. The third takes a reference to a vul_reg_exp object as an argument and creates an object initialized with the information from the given vul_reg_exp object.

The find member function finds the first occurrence of the regular expression of that object in the string given to find as an argument. Find returns a boolean, and if true, mutates the private data appropriately. Find sets pointers to the beginning and end of the thing last found, they are pointers into the actual string that was searched. The start and end member functions return indices into the searched string that correspond to the beginning and end pointers respectively. The compile member function takes a char* and puts the compiled version of the char* argument into the object's private data fields. The == and != operators only check the to see if the compiled regular expression is the same, and the deep_equal functions also checks to see if the start and end pointers are the same. The is_valid function returns false if program is set to NULL, (i.e. there is no valid compiled expression). The set_invalid function sets the program to NULL (Warning: this deletes the compiled expression). The following examples may help clarify regular expression usage:

* The regular expression "^hello" matches a "hello" only at the beginning of a line. It would match "hello there" but not "hi, hello there".

* The regular expression "long$" matches a "long" only at the end of a line. It would match "so long\0", but not "long ago".

* The regular expression "t..t..g" will match anything that has a "t" then any two characters, another "t", any two characters and then a "g". It will match "testing", or "test again" but would not match "toasting"

* The regular expression "[1-9ab]" matches any number one through nine, and the characters "a" and "b". It would match "hello 1" or "begin", but would not match "no-match".

* The regular expression "[^1-9ab]" matches any character that is not a number one through nine, or an "a" or "b". It would NOT match "hello 1" or "begin", but would match "no-match".

* The regular expression "br* " matches something that begins with a "b", is followed by zero or more "r"s, and ends in a space. It would match "brrrrr ", and "b ", but would not match "brrh ".

* The regular expression "br+ " matches something that begins with a "b", is followed by one or more "r"s, and ends in a space. It would match "brrrrr ", and "br ", but would not match "b " or "brrh ".

* The regular expression "br? " matches something that begins with a "b", is followed by zero or one "r"s, and ends in a space. It would match "br ", and "b ", but would not match "brrrr " or "brrh ".

* The regular expression "(..p)b" matches something ending with pb and beginning with whatever the two characters before the first p encountered in the line were. It would find "repb" in "rep drepa qrepb". The regular expression "(..p)a" would find "repa qrepb" in "rep drepa qrepb"

* The regular expression "d(..p)" matches something ending with p, beginning with d, and having two characters in between that are the same as the two characters before the first p encountered in the line. It would match "drepa qrepb" in "rep drepa qrepb".

Definition in file vul_reg_exp.cxx.


Define Documentation

#define ANY   3

Definition at line 251 of file vul_reg_exp.cxx.

#define ANYBUT   5

Definition at line 253 of file vul_reg_exp.cxx.

#define ANYOF   4

Definition at line 252 of file vul_reg_exp.cxx.

#define BACK   7

Definition at line 255 of file vul_reg_exp.cxx.

#define BOL   1

Definition at line 249 of file vul_reg_exp.cxx.

#define BRANCH   6

Definition at line 254 of file vul_reg_exp.cxx.

#define CLOSE   30

Definition at line 262 of file vul_reg_exp.cxx.

#define END   0

Definition at line 248 of file vul_reg_exp.cxx.

#define EOL   2

Definition at line 250 of file vul_reg_exp.cxx.

#define EXACTLY   8

Definition at line 256 of file vul_reg_exp.cxx.

#define FAIL (   m)    { regerror(m); return NULL; }

Definition at line 308 of file vul_reg_exp.cxx.

#define HASWIDTH   01

Definition at line 315 of file vul_reg_exp.cxx.

#define ISMULT (   c)    ((c) == '*' || (c) == '+' || (c) == '?')

Definition at line 309 of file vul_reg_exp.cxx.

#define META   "^$.[()|?+*\\"

Definition at line 310 of file vul_reg_exp.cxx.

#define NEXT (   p)    (((*((p)+1)&0377)<<8) + (*((p)+2)&0377))

Definition at line 298 of file vul_reg_exp.cxx.

#define NOTHING   9

Definition at line 257 of file vul_reg_exp.cxx.

#define OP (   p)    (*(p))

Definition at line 297 of file vul_reg_exp.cxx.

#define OPEN   20

Definition at line 260 of file vul_reg_exp.cxx.

#define OPERAND (   p)    ((p) + 3)

Definition at line 299 of file vul_reg_exp.cxx.

#define PLUS   11

Definition at line 259 of file vul_reg_exp.cxx.

#define SIMPLE   02

Definition at line 316 of file vul_reg_exp.cxx.

#define SPSTART   04

Definition at line 317 of file vul_reg_exp.cxx.

#define STAR   10

Definition at line 258 of file vul_reg_exp.cxx.

#define UCHARAT (   p)    ((const unsigned char*)(p))[0]

Definition at line 306 of file vul_reg_exp.cxx.

#define WORST   0

Definition at line 318 of file vul_reg_exp.cxx.


Variable Documentation

const unsigned char MAGIC = 0234

Definition at line 301 of file vul_reg_exp.cxx.