2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
// file: repattrn.cpp
|
|
|
|
//
|
|
|
|
/*
|
|
|
|
**********************************************************************
|
|
|
|
* Copyright (C) 2002 International Business Machines Corporation *
|
|
|
|
* and others. All rights reserved. *
|
|
|
|
**********************************************************************
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "unicode/utypes.h"
|
2002-11-07 02:34:46 +00:00
|
|
|
|
|
|
|
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
#include "unicode/regex.h"
|
|
|
|
#include "uassert.h"
|
|
|
|
#include "uvector.h"
|
2003-01-08 23:38:23 +00:00
|
|
|
#include "uvectr32.h"
|
2002-10-22 00:09:32 +00:00
|
|
|
#include "regexcmp.h"
|
|
|
|
#include "regeximp.h"
|
|
|
|
|
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
2002-10-23 01:14:17 +00:00
|
|
|
// RegexPattern Default Constructor
|
2002-10-22 00:09:32 +00:00
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
RegexPattern::RegexPattern() {
|
2002-10-23 01:14:17 +00:00
|
|
|
init();
|
|
|
|
};
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Copy Constructor Note: This is a rather inefficient implementation,
|
|
|
|
// but it probably doesn't matter.
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
RegexPattern::RegexPattern(const RegexPattern &other) : UObject(other) {
|
|
|
|
init();
|
|
|
|
*this = other;
|
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Assignmenet Operator
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
RegexPattern &RegexPattern::operator = (const RegexPattern &other) {
|
|
|
|
if (this == &other) {
|
|
|
|
// Source and destination are the same. Don't do anything.
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean out any previous contents of object being assigned to.
|
|
|
|
zap();
|
|
|
|
|
|
|
|
// Give target object a default initialization
|
|
|
|
init();
|
|
|
|
|
|
|
|
// Copy simple fields
|
|
|
|
fPattern = other.fPattern;
|
|
|
|
fFlags = other.fFlags;
|
|
|
|
fLiteralText = other.fLiteralText;
|
|
|
|
fBadState = other.fBadState;
|
2002-10-24 22:16:07 +00:00
|
|
|
fMaxCaptureDigits = other.fMaxCaptureDigits;
|
2002-11-07 02:34:46 +00:00
|
|
|
fStaticSets = other.fStaticSets;
|
2002-10-23 01:14:17 +00:00
|
|
|
if (fBadState) {
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Copy the pattern. It's just values, nothing deep to copy.
|
2003-01-16 01:12:04 +00:00
|
|
|
// TODO: something with status
|
2002-10-23 01:14:17 +00:00
|
|
|
UErrorCode status = U_ZERO_ERROR;
|
2003-01-16 01:12:04 +00:00
|
|
|
fCompiledPat->assign(*other.fCompiledPat, status);
|
|
|
|
fGroupMap->assign(*other.fGroupMap, status);
|
2002-10-23 01:14:17 +00:00
|
|
|
|
2002-10-23 16:38:10 +00:00
|
|
|
// Note: do not copy fMatcher. It'll be created on first use if the
|
|
|
|
// destination needs one.
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
// Copy the Unicode Sets.
|
|
|
|
// Could be made more efficient if the sets were reference counted and shared,
|
|
|
|
// but I doubt that pattern copying will be particularly common.
|
2002-11-14 18:27:00 +00:00
|
|
|
// Note: init() already added an empty element zero to fSets
|
2003-01-16 01:12:04 +00:00
|
|
|
int32_t i;
|
2002-10-23 01:14:17 +00:00
|
|
|
for (i=1; i<other.fSets->size(); i++) {
|
|
|
|
UnicodeSet *sourceSet = (UnicodeSet *)other.fSets->elementAt(i);
|
|
|
|
UnicodeSet *newSet = new UnicodeSet(*sourceSet);
|
|
|
|
if (newSet == NULL) {
|
|
|
|
fBadState = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2002-11-07 20:06:39 +00:00
|
|
|
fSets->addElement(newSet, status);
|
2002-10-23 01:14:17 +00:00
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
fBadState = TRUE;
|
|
|
|
}
|
2002-10-23 01:14:17 +00:00
|
|
|
return *this;
|
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// init Shared initialization for use by constructors.
|
|
|
|
// Bring an uninitialized RegexPattern up to a default state.
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
void RegexPattern::init() {
|
|
|
|
fFlags = 0;
|
|
|
|
fBadState = FALSE;
|
2002-10-24 22:16:07 +00:00
|
|
|
fMaxCaptureDigits = 1; // TODO: calculate for real.
|
2002-11-07 02:34:46 +00:00
|
|
|
fStaticSets = NULL;
|
2002-10-23 16:38:10 +00:00
|
|
|
fMatcher = NULL;
|
2003-01-16 01:12:04 +00:00
|
|
|
fFrameSize = 0;
|
2003-01-17 01:43:54 +00:00
|
|
|
fDataSize = 0;
|
2002-10-23 01:14:17 +00:00
|
|
|
|
|
|
|
UErrorCode status=U_ZERO_ERROR;
|
|
|
|
// Init of a completely new RegexPattern.
|
2003-01-08 23:38:23 +00:00
|
|
|
fCompiledPat = new UVector32(status);
|
2003-01-16 01:12:04 +00:00
|
|
|
fGroupMap = new UVector32(status);
|
2002-10-23 01:14:17 +00:00
|
|
|
fSets = new UVector(status);
|
|
|
|
if (U_FAILURE(status) || fCompiledPat == NULL || fSets == NULL) {
|
|
|
|
fBadState = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Slot zero of the vector of sets is reserved. Fill it here.
|
|
|
|
fSets->addElement((int32_t)0, status);
|
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// zap Delete everything owned by this RegexPattern.
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
void RegexPattern::zap() {
|
2002-10-23 16:38:10 +00:00
|
|
|
delete fMatcher;
|
|
|
|
fMatcher = NULL;
|
2002-10-22 00:09:32 +00:00
|
|
|
delete fCompiledPat;
|
2002-10-23 01:14:17 +00:00
|
|
|
fCompiledPat = NULL;
|
2002-10-22 00:09:32 +00:00
|
|
|
int i;
|
2002-11-14 18:27:00 +00:00
|
|
|
for (i=1; i<fSets->size(); i++) {
|
2002-10-22 00:09:32 +00:00
|
|
|
UnicodeSet *s;
|
|
|
|
s = (UnicodeSet *)fSets->elementAt(i);
|
|
|
|
if (s != NULL) {
|
|
|
|
delete s;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete fSets;
|
|
|
|
fSets = NULL;
|
2003-01-16 01:12:04 +00:00
|
|
|
delete fGroupMap;
|
|
|
|
fGroupMap = NULL;
|
2002-10-23 01:14:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Destructor
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
RegexPattern::~RegexPattern() {
|
|
|
|
zap();
|
2002-10-22 00:09:32 +00:00
|
|
|
};
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// Clone
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
2002-10-22 00:09:32 +00:00
|
|
|
RegexPattern *RegexPattern::clone() const {
|
|
|
|
RegexPattern *copy = new RegexPattern(*this);
|
|
|
|
return copy;
|
|
|
|
};
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// operator == (comparison) Consider to patterns to be == if the
|
|
|
|
// pattern strings and the flags are the same.
|
|
|
|
//
|
|
|
|
//--------------------------------------------------------------------------
|
|
|
|
UBool RegexPattern::operator ==(const RegexPattern &other) const {
|
|
|
|
UBool r = this->fFlags == other.fFlags &&
|
|
|
|
this->fPattern == other.fPattern &&
|
|
|
|
this->fBadState == FALSE &&
|
|
|
|
other.fBadState == FALSE;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// compile
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
RegexPattern *RegexPattern::compile(
|
|
|
|
const UnicodeString ®ex,
|
2002-11-19 19:31:03 +00:00
|
|
|
uint32_t flags,
|
2002-10-22 00:09:32 +00:00
|
|
|
UParseError &pe,
|
2002-11-14 18:27:00 +00:00
|
|
|
UErrorCode &status) {
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2002-11-14 18:27:00 +00:00
|
|
|
if (U_FAILURE(status)) {
|
2002-10-22 00:09:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2003-02-07 02:04:14 +00:00
|
|
|
|
|
|
|
const uint32_t allFlags = UREGEX_CANON_EQ | UREGEX_CASE_INSENSITIVE | UREGEX_COMMENTS |
|
|
|
|
UREGEX_DOTALL | UREGEX_MULTILINE;
|
|
|
|
|
|
|
|
if ((flags & ~allFlags) != 0) {
|
|
|
|
status = U_REGEX_INVALID_FLAG;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-11-11 18:49:49 +00:00
|
|
|
if (flags != 0) {
|
2002-11-14 18:27:00 +00:00
|
|
|
status = U_REGEX_UNIMPLEMENTED;
|
2002-11-11 18:49:49 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
RegexPattern *This = new RegexPattern;
|
|
|
|
if (This == NULL) {
|
2002-11-14 18:27:00 +00:00
|
|
|
status = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (This->fBadState) {
|
|
|
|
status = U_REGEX_INVALID_STATE;
|
2002-10-22 00:09:32 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-10-23 01:14:17 +00:00
|
|
|
This->fFlags = flags;
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2002-11-14 18:27:00 +00:00
|
|
|
RegexCompile compiler(status);
|
|
|
|
compiler.compile(*This, regex, pe, status);
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
return This;
|
|
|
|
};
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
//
|
|
|
|
// compile with default flags.
|
|
|
|
//
|
|
|
|
RegexPattern *RegexPattern::compile( const UnicodeString ®ex,
|
|
|
|
UParseError &pe,
|
|
|
|
UErrorCode &err)
|
|
|
|
{
|
|
|
|
return compile(regex, 0, pe, err);
|
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// flags
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
2002-11-19 19:31:03 +00:00
|
|
|
uint32_t RegexPattern::flags() const {
|
2002-10-22 00:09:32 +00:00
|
|
|
return fFlags;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// matcher(UnicodeString, err)
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
RegexMatcher *RegexPattern::matcher(const UnicodeString &input,
|
|
|
|
UErrorCode &err) const {
|
|
|
|
RegexMatcher *retMatcher = NULL;
|
|
|
|
|
2002-11-14 18:27:00 +00:00
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
if (fBadState) {
|
|
|
|
U_FAILURE(U_REGEX_INVALID_STATE);
|
|
|
|
return NULL;
|
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
retMatcher = new RegexMatcher(this);
|
|
|
|
if (retMatcher == NULL) {
|
|
|
|
err = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
retMatcher->reset(input);
|
|
|
|
return retMatcher;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-23 01:14:17 +00:00
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// matches Convenience function to test for a match, starting
|
|
|
|
// with a pattern string and a data string.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
UBool RegexPattern::matches(const UnicodeString ®ex,
|
|
|
|
const UnicodeString &input,
|
|
|
|
UParseError &pe,
|
|
|
|
UErrorCode &status) {
|
|
|
|
|
2002-11-14 18:27:00 +00:00
|
|
|
if (U_FAILURE(status)) {return FALSE;}
|
|
|
|
|
|
|
|
UBool retVal;
|
2002-10-23 01:14:17 +00:00
|
|
|
RegexPattern *pat = NULL;
|
|
|
|
RegexMatcher *matcher = NULL;
|
|
|
|
|
2002-11-14 18:27:00 +00:00
|
|
|
pat = RegexPattern::compile(regex, 0, pe, status);
|
2002-10-23 01:14:17 +00:00
|
|
|
matcher = pat->matcher(input, status);
|
2002-11-14 18:27:00 +00:00
|
|
|
retVal = matcher->matches(status);
|
2002-10-23 01:14:17 +00:00
|
|
|
|
|
|
|
delete matcher;
|
|
|
|
delete pat;
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// pattern
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
UnicodeString RegexPattern::pattern() const {
|
|
|
|
return fPattern;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// split
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
2002-10-23 01:14:17 +00:00
|
|
|
int32_t RegexPattern::split(const UnicodeString &input,
|
2002-10-22 00:09:32 +00:00
|
|
|
UnicodeString dest[],
|
2002-10-23 16:38:10 +00:00
|
|
|
int32_t destCapacity,
|
|
|
|
UErrorCode &status) const
|
2002-10-22 00:09:32 +00:00
|
|
|
{
|
2002-10-23 16:38:10 +00:00
|
|
|
//
|
|
|
|
// Check arguements for validity
|
|
|
|
//
|
|
|
|
if (U_FAILURE(status)) {
|
2002-10-22 00:09:32 +00:00
|
|
|
return 0;
|
|
|
|
};
|
2002-10-23 16:38:10 +00:00
|
|
|
|
|
|
|
if (destCapacity < 1) {
|
|
|
|
status = U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// If we don't already have a cached matcher object from a previous call
|
|
|
|
// to split(), create one now.
|
|
|
|
//
|
|
|
|
if (fMatcher == NULL) {
|
|
|
|
RegexMatcher *m = matcher(input, status);
|
|
|
|
if (U_FAILURE(status)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
// Need to cast off const to cache the matcher
|
|
|
|
RegexPattern *nonConstThis = (RegexPattern *)this;
|
|
|
|
nonConstThis->fMatcher = m;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Set our input text into the matcher
|
|
|
|
//
|
|
|
|
fMatcher->reset(input);
|
|
|
|
int32_t inputLen = input.length();
|
|
|
|
int32_t nextOutputStringStart = 0;
|
|
|
|
if (inputLen == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Loop through the input text, searching for the delimiter pattern
|
|
|
|
//
|
|
|
|
int i;
|
2003-01-16 01:12:04 +00:00
|
|
|
int32_t numCaptureGroups = fGroupMap->size();
|
2002-10-23 16:38:10 +00:00
|
|
|
for (i=0; ; i++) {
|
|
|
|
if (i==destCapacity-1) {
|
|
|
|
// There is only one output string left.
|
|
|
|
// Fill it with whatever is left from the input, then exit the loop.
|
|
|
|
dest[i].setTo(input, nextOutputStringStart, inputLen-nextOutputStringStart);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fMatcher->find()) {
|
|
|
|
// We found another delimiter. Move everything from where we started looking
|
|
|
|
// up until the start of the delimiter into the next output string.
|
2002-10-24 22:16:07 +00:00
|
|
|
int32_t fieldLen = fMatcher->fMatchStart - nextOutputStringStart;
|
2002-10-23 16:38:10 +00:00
|
|
|
dest[i].setTo(input, nextOutputStringStart, fieldLen);
|
2002-10-24 22:16:07 +00:00
|
|
|
nextOutputStringStart = fMatcher->fMatchEnd;
|
2002-11-19 19:31:03 +00:00
|
|
|
|
|
|
|
// If the delimiter pattern has capturing parentheses, the captured
|
|
|
|
// text goes out into the next n destination strings.
|
|
|
|
int32_t groupNum;
|
2003-01-16 01:12:04 +00:00
|
|
|
for (groupNum=1; groupNum<=numCaptureGroups; groupNum++) {
|
2002-11-19 19:31:03 +00:00
|
|
|
if (i==destCapacity-1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
dest[i] = fMatcher->group(groupNum, status);
|
|
|
|
}
|
|
|
|
|
2002-10-23 16:38:10 +00:00
|
|
|
if (nextOutputStringStart == inputLen) {
|
|
|
|
// The delimiter was at the end of the string. We're done.
|
|
|
|
break;
|
|
|
|
}
|
2002-11-19 19:31:03 +00:00
|
|
|
|
|
|
|
if (i==destCapacity-1) {
|
|
|
|
// We've filled up the last output string with capture group data.
|
|
|
|
// Give back the last string, to be used for the remainder of the input.
|
|
|
|
i--;
|
|
|
|
}
|
2002-10-23 16:38:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// We ran off the end of the input while looking for the next delimiter.
|
|
|
|
// All the remaining text goes into the current output string.
|
|
|
|
dest[i].setTo(input, nextOutputStringStart, inputLen-nextOutputStringStart);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i+1;
|
2002-10-22 00:09:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// dump Output the compiled form of the pattern.
|
|
|
|
// Debugging function only.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------
|
2002-12-18 01:23:47 +00:00
|
|
|
static const char * const opNames[] = {URX_OPCODE_NAMES};
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2002-11-19 19:31:03 +00:00
|
|
|
void RegexPattern::dumpOp(int32_t index) const {
|
|
|
|
int32_t op = fCompiledPat->elementAti(index);
|
|
|
|
int32_t val = URX_VAL(op);
|
|
|
|
int32_t type = URX_TYPE(op);
|
|
|
|
int32_t pinnedType = type;
|
|
|
|
if (pinnedType >= sizeof(opNames)/sizeof(char *)) {
|
|
|
|
pinnedType = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%4d %08x %-15s ", index, op, opNames[pinnedType]);
|
|
|
|
switch (type) {
|
|
|
|
case URX_NOP:
|
|
|
|
case URX_DOTANY:
|
|
|
|
case URX_FAIL:
|
|
|
|
case URX_BACKSLASH_A:
|
|
|
|
case URX_BACKSLASH_G:
|
|
|
|
case URX_BACKSLASH_X:
|
|
|
|
case URX_END:
|
|
|
|
// Types with no operand field of interest.
|
|
|
|
break;
|
|
|
|
|
2003-01-16 01:12:04 +00:00
|
|
|
case URX_RESERVED_OP:
|
2002-11-19 19:31:03 +00:00
|
|
|
case URX_START_CAPTURE:
|
|
|
|
case URX_END_CAPTURE:
|
|
|
|
case URX_STATE_SAVE:
|
|
|
|
case URX_JMP:
|
|
|
|
case URX_BACKSLASH_B:
|
|
|
|
case URX_BACKSLASH_D:
|
|
|
|
case URX_BACKSLASH_W:
|
|
|
|
case URX_BACKSLASH_Z:
|
|
|
|
case URX_CARET:
|
|
|
|
case URX_DOLLAR:
|
|
|
|
case URX_STRING_LEN:
|
2003-01-16 01:12:04 +00:00
|
|
|
case URX_CTR_INIT:
|
|
|
|
case URX_CTR_INIT_NG:
|
|
|
|
case URX_CTR_INIT_P:
|
|
|
|
case URX_CTR_LOOP:
|
|
|
|
case URX_CTR_LOOP_NG:
|
|
|
|
case URX_CTR_LOOP_P:
|
|
|
|
case URX_RELOC_OPRND:
|
2003-01-17 01:43:54 +00:00
|
|
|
case URX_STO_SP:
|
|
|
|
case URX_LD_SP:
|
2003-01-25 18:57:42 +00:00
|
|
|
case URX_BACKREF:
|
|
|
|
case URX_STO_INP_LOC:
|
|
|
|
case URX_JMPX:
|
2003-02-07 02:04:14 +00:00
|
|
|
case URX_LA_START:
|
|
|
|
case URX_LA_END:
|
2002-11-19 19:31:03 +00:00
|
|
|
// types with an integer operand field.
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%d", val);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case URX_ONECHAR:
|
2003-02-07 02:04:14 +00:00
|
|
|
case URX_ONECHAR_I:
|
2002-11-19 19:31:03 +00:00
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%c", val<256?val:'?');
|
|
|
|
break;
|
|
|
|
|
|
|
|
case URX_STRING:
|
2003-02-07 02:04:14 +00:00
|
|
|
case URX_STRING_I:
|
2002-11-19 19:31:03 +00:00
|
|
|
{
|
|
|
|
int32_t lengthOp = fCompiledPat->elementAti(index+1);
|
|
|
|
U_ASSERT(URX_TYPE(lengthOp) == URX_STRING_LEN);
|
|
|
|
int32_t length = URX_VAL(lengthOp);
|
|
|
|
int32_t i;
|
|
|
|
for (i=val; i<val+length; i++) {
|
|
|
|
UChar c = fLiteralText[i];
|
|
|
|
if (c < 32 || c >= 256) {c = '.';}
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%c", c);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2002-11-19 19:31:03 +00:00
|
|
|
case URX_SETREF:
|
|
|
|
{
|
|
|
|
UnicodeString s;
|
|
|
|
UnicodeSet *set = (UnicodeSet *)fSets->elementAt(val);
|
|
|
|
set->toPattern(s, TRUE);
|
|
|
|
for (int32_t i=0; i<s.length(); i++) {
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%c", s.charAt(i));
|
|
|
|
}
|
|
|
|
}
|
2002-11-20 23:30:20 +00:00
|
|
|
break;
|
2002-10-22 00:09:32 +00:00
|
|
|
|
2002-11-20 23:30:20 +00:00
|
|
|
case URX_STATIC_SETREF:
|
|
|
|
{
|
|
|
|
UnicodeString s;
|
|
|
|
if (val & URX_NEG_SET) {
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("NOT ");
|
|
|
|
val &= ~URX_NEG_SET;
|
|
|
|
}
|
|
|
|
UnicodeSet *set = fStaticSets[val];
|
|
|
|
set->toPattern(s, TRUE);
|
|
|
|
for (int32_t i=0; i<s.length(); i++) {
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%c", s.charAt(i));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-11-19 19:31:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("??????");
|
|
|
|
break;
|
2002-10-22 00:09:32 +00:00
|
|
|
}
|
2002-11-19 19:31:03 +00:00
|
|
|
REGEX_DUMP_DEBUG_PRINTF("\n");
|
|
|
|
}
|
2002-10-22 00:09:32 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-11-19 19:31:03 +00:00
|
|
|
|
|
|
|
void RegexPattern::dump() const {
|
|
|
|
int index;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("Original Pattern: ");
|
|
|
|
for (i=0; i<fPattern.length(); i++) {
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("%c", fPattern.charAt(i));
|
|
|
|
}
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("\n");
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("Pattern Valid?: %s\n", fBadState? "no" : "yes");
|
|
|
|
REGEX_DUMP_DEBUG_PRINTF("\nIndex Binary Type Operand\n"
|
|
|
|
"-------------------------------------------\n");
|
|
|
|
for (index = 0; index<fCompiledPat->size(); index++) {
|
|
|
|
dumpOp(index);
|
2002-10-22 00:09:32 +00:00
|
|
|
}
|
2002-11-19 19:31:03 +00:00
|
|
|
REGEX_DUMP_DEBUG_PRINTF("\n\n");
|
2002-10-22 00:09:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const char RegexPattern::fgClassID = 0;
|
|
|
|
|
2002-11-07 20:06:39 +00:00
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// regex_cleanup Memory cleanup function, free/delete all
|
|
|
|
// cached memory. Called by ICU's u_cleanup() function.
|
|
|
|
//
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
U_CFUNC UBool
|
|
|
|
regex_cleanup(void) {
|
|
|
|
RegexCompile::cleanup();
|
|
|
|
return TRUE;
|
|
|
|
};
|
2002-11-07 02:34:46 +00:00
|
|
|
|
2002-10-22 00:09:32 +00:00
|
|
|
U_NAMESPACE_END
|
2002-11-07 02:34:46 +00:00
|
|
|
#endif // !UCONFIG_NO_REGULAR_EXPRESSIONS
|