Added Xerces-C++ 3.1.2
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ASCIIRangeFactory.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/ASCIIRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/RangeTokenMap.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ASCIIRangeFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
ASCIIRangeFactory::ASCIIRangeFactory()
|
||||
{
|
||||
}
|
||||
|
||||
ASCIIRangeFactory::~ASCIIRangeFactory() {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ASCIIRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void ASCIIRangeFactory::buildRanges(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fRangesCreated)
|
||||
return;
|
||||
|
||||
if (!fKeywordsInitialized) {
|
||||
initializeKeywordMap(rangeTokMap);
|
||||
}
|
||||
|
||||
TokenFactory* tokFactory = rangeTokMap->getTokenFactory();
|
||||
|
||||
// Create space ranges
|
||||
RangeToken* tok = tokFactory->createRange();
|
||||
tok->addRange(chHTab, chHTab);
|
||||
tok->addRange(chLF, chLF);
|
||||
tok->addRange(chFF, chFF);
|
||||
tok->addRange(chCR, chCR);
|
||||
tok->addRange(chSpace, chSpace);
|
||||
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
|
||||
rangeTokMap->setRangeToken(fgASCIISpace, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
|
||||
rangeTokMap->setRangeToken(fgASCIISpace, tok , true);
|
||||
|
||||
// Create digits ranges
|
||||
tok = tokFactory->createRange();
|
||||
tok->addRange(chDigit_0, chDigit_9);
|
||||
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
|
||||
rangeTokMap->setRangeToken(fgASCIIDigit, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
|
||||
rangeTokMap->setRangeToken(fgASCIIDigit, tok , true);
|
||||
|
||||
// Create word ranges
|
||||
tok = tokFactory->createRange();
|
||||
tok->addRange(chDigit_0, chDigit_9);
|
||||
tok->addRange(chLatin_A, chLatin_Z);
|
||||
tok->addRange(chUnderscore, chUnderscore);
|
||||
tok->addRange(chLatin_a, chLatin_z);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgASCIIWord, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgASCIIWord, tok , true);
|
||||
|
||||
// Create xdigit ranges
|
||||
tok = tokFactory->createRange();
|
||||
tok->addRange(chDigit_0, chDigit_9);
|
||||
tok->addRange(chLatin_A, chLatin_F);
|
||||
tok->addRange(chLatin_a, chLatin_a);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
|
||||
rangeTokMap->setRangeToken(fgASCIIXDigit, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgASCIIXDigit, tok , true);
|
||||
|
||||
// Create ascii ranges
|
||||
tok = tokFactory->createRange();
|
||||
tok->addRange(0x00, 0x7F);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgASCII, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgASCII, tok , true);
|
||||
|
||||
fRangesCreated = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ASCIIRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void ASCIIRangeFactory::initializeKeywordMap(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fKeywordsInitialized)
|
||||
return;
|
||||
|
||||
rangeTokMap->addKeywordMap(fgASCIISpace, fgASCIICategory);
|
||||
rangeTokMap->addKeywordMap(fgASCIIDigit, fgASCIICategory);
|
||||
rangeTokMap->addKeywordMap(fgASCIIWord, fgASCIICategory);
|
||||
rangeTokMap->addKeywordMap(fgASCIIXDigit, fgASCIICategory);
|
||||
rangeTokMap->addKeywordMap(fgASCII, fgASCIICategory);
|
||||
|
||||
fKeywordsInitialized = true;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file ASCIIRangeFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ASCIIRangeFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_ASCIIRANGEFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_ASCIIRANGEFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeFactory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT ASCIIRangeFactory: public RangeFactory {
|
||||
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ASCIIRangeFactory();
|
||||
~ASCIIRangeFactory();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Initialization methods
|
||||
// -----------------------------------------------------------------------
|
||||
void initializeKeywordMap(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void buildRanges(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ASCIIRangeFactory(const ASCIIRangeFactory&);
|
||||
ASCIIRangeFactory& operator=(const ASCIIRangeFactory&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file ASCIIRangeFactory.hpp
|
||||
*/
|
||||
@@ -0,0 +1,214 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: BMPattern.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/BMPattern.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/Janitor.hpp>
|
||||
#include <xercesc/framework/MemoryManager.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BMPattern: Constructors
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef JanitorMemFunCall<BMPattern> CleanupType;
|
||||
|
||||
BMPattern::BMPattern( const XMLCh* const pattern
|
||||
, bool ignoreCase
|
||||
, MemoryManager* const manager) :
|
||||
|
||||
fIgnoreCase(ignoreCase)
|
||||
, fShiftTableLen(256)
|
||||
, fShiftTable(0)
|
||||
, fPattern(0)
|
||||
, fUppercasePattern(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &BMPattern::cleanUp);
|
||||
|
||||
try {
|
||||
fPattern = XMLString::replicate(pattern, fMemoryManager);
|
||||
initialize();
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
BMPattern::BMPattern( const XMLCh* const pattern
|
||||
, int tableSize
|
||||
, bool ignoreCase
|
||||
, MemoryManager* const manager) :
|
||||
|
||||
fIgnoreCase(ignoreCase)
|
||||
, fShiftTableLen(tableSize)
|
||||
, fShiftTable(0)
|
||||
, fPattern(0)
|
||||
, fUppercasePattern(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &BMPattern::cleanUp);
|
||||
|
||||
try {
|
||||
fPattern = XMLString::replicate(pattern, fMemoryManager);
|
||||
initialize();
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
BMPattern::~BMPattern() {
|
||||
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BMPattern: matches methods
|
||||
// ---------------------------------------------------------------------------
|
||||
int BMPattern::matches(const XMLCh* const content, XMLSize_t start, XMLSize_t limit) const {
|
||||
|
||||
const XMLSize_t patternLen = XMLString::stringLen(fPattern);
|
||||
// Uppercase Content
|
||||
XMLCh* ucContent = 0;
|
||||
|
||||
if (patternLen == 0)
|
||||
return (int)start;
|
||||
|
||||
if (fIgnoreCase) {
|
||||
|
||||
ucContent = XMLString::replicate(content, fMemoryManager);
|
||||
XMLString::upperCase(ucContent);
|
||||
}
|
||||
|
||||
ArrayJanitor<XMLCh> janUCContent(ucContent, fMemoryManager);
|
||||
|
||||
XMLSize_t index = start + patternLen;
|
||||
|
||||
while (index <= limit) {
|
||||
|
||||
XMLSize_t patternIndex = patternLen;
|
||||
XMLSize_t nIndex = index + 1;
|
||||
XMLCh ch = 0;
|
||||
|
||||
while (patternIndex > 0) {
|
||||
|
||||
ch = content[--index];
|
||||
|
||||
if (ch != fPattern[--patternIndex]) {
|
||||
|
||||
// No match, so we will break. But first we have
|
||||
// to check the ignore case flag. If it is set, then
|
||||
// we try to match with the case ignored
|
||||
if (!fIgnoreCase ||
|
||||
(fUppercasePattern[patternIndex] != ucContent[index]))
|
||||
break;
|
||||
}
|
||||
|
||||
if (patternIndex == 0)
|
||||
return (int)index;
|
||||
}
|
||||
|
||||
index += fShiftTable[ch % fShiftTableLen] + 1;
|
||||
|
||||
if (index < nIndex)
|
||||
index = nIndex;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BMPattern: private helpers methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void BMPattern::initialize() {
|
||||
|
||||
const XMLSize_t patternLen = XMLString::stringLen(fPattern);
|
||||
XMLCh* lowercasePattern = 0;
|
||||
|
||||
fShiftTable = (XMLSize_t*) fMemoryManager->allocate(fShiftTableLen*sizeof(XMLSize_t)); //new XMLSize_t[fShiftTableLen];
|
||||
|
||||
if (fIgnoreCase) {
|
||||
|
||||
fUppercasePattern = XMLString::replicate(fPattern, fMemoryManager);
|
||||
lowercasePattern = XMLString::replicate(fPattern, fMemoryManager);
|
||||
XMLString::upperCase(fUppercasePattern);
|
||||
XMLString::lowerCase(lowercasePattern);
|
||||
}
|
||||
|
||||
ArrayJanitor<XMLCh> janLowercase(lowercasePattern, fMemoryManager);
|
||||
|
||||
for (unsigned int i=0; i< fShiftTableLen; i++)
|
||||
fShiftTable[i] = patternLen;
|
||||
|
||||
for (unsigned int k=0; k< patternLen; k++) {
|
||||
|
||||
XMLCh ch = fPattern[k];
|
||||
XMLSize_t diff = patternLen - k - 1;
|
||||
int index = ch % fShiftTableLen;
|
||||
|
||||
if (diff < fShiftTable[index])
|
||||
fShiftTable[index] = diff;
|
||||
|
||||
if (fIgnoreCase) {
|
||||
|
||||
for (int j=0; j< 2; j++) {
|
||||
|
||||
ch = (j == 0) ? fUppercasePattern[k] : lowercasePattern[k];
|
||||
index = ch % fShiftTableLen;
|
||||
|
||||
if (diff < fShiftTable[index])
|
||||
fShiftTable[index] = diff;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BMPattern: Cleanup
|
||||
// ---------------------------------------------------------------------------
|
||||
void BMPattern::cleanUp() {
|
||||
|
||||
fMemoryManager->deallocate(fPattern);//delete [] fPattern;
|
||||
fMemoryManager->deallocate(fUppercasePattern);//delete [] fUppercasePattern;
|
||||
fMemoryManager->deallocate(fShiftTable);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file BMPattern.cpp
|
||||
*/
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: BMPattern.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_BMPATTERN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_BMPATTERN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT BMPattern : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Constructors */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This is the constructor which takes the pattern information. A default
|
||||
* shift table size is used.
|
||||
*
|
||||
* @param pattern The pattern to match against.
|
||||
*
|
||||
* @param ignoreCase A flag to indicate whether to ignore case
|
||||
* matching or not.
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
BMPattern
|
||||
(
|
||||
const XMLCh* const pattern
|
||||
, bool ignoreCase
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/**
|
||||
* This is the constructor which takes all of the information
|
||||
* required to construct a BM pattern object.
|
||||
*
|
||||
* @param pattern The pattern to match against.
|
||||
*
|
||||
* @param tableSize Indicates the size of the shift table.
|
||||
*
|
||||
* @param ignoreCase A flag to indicate whether to ignore case
|
||||
* matching or not.
|
||||
*
|
||||
* @param manager The configurable memory manager
|
||||
*/
|
||||
BMPattern
|
||||
(
|
||||
const XMLCh* const pattern
|
||||
, int tableSize
|
||||
, bool ignoreCase
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
//@}
|
||||
|
||||
/** @name Destructor. */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* Destructor of BMPattern
|
||||
*/
|
||||
~BMPattern();
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Matching functions
|
||||
// -----------------------------------------------------------------------
|
||||
/** @name Matching Functions */
|
||||
//@{
|
||||
|
||||
/**
|
||||
* This method will perform a match of the given content against a
|
||||
* predefined pattern.
|
||||
*/
|
||||
int matches(const XMLCh* const content, XMLSize_t start, XMLSize_t limit) const;
|
||||
|
||||
//@}
|
||||
|
||||
private :
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
BMPattern();
|
||||
BMPattern(const BMPattern&);
|
||||
BMPattern& operator=(const BMPattern&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// This method will perform a case insensitive match
|
||||
// -----------------------------------------------------------------------
|
||||
bool matchesIgnoreCase(const XMLCh ch1, const XMLCh ch2);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Initialize/Clean up methods
|
||||
// -----------------------------------------------------------------------
|
||||
void initialize();
|
||||
void cleanUp();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fPattern
|
||||
// fUppercasePattern
|
||||
// This is the pattern to match against, and its upper case form.
|
||||
//
|
||||
// fIgnoreCase
|
||||
// This is an indicator whether cases should be ignored during
|
||||
// matching.
|
||||
//
|
||||
// fShiftTable
|
||||
// fShiftTableLen
|
||||
// This is a table of offsets for shifting purposes used by the BM
|
||||
// search algorithm, and its length.
|
||||
// -----------------------------------------------------------------------
|
||||
bool fIgnoreCase;
|
||||
unsigned int fShiftTableLen;
|
||||
XMLSize_t* fShiftTable;
|
||||
XMLCh* fPattern;
|
||||
XMLCh* fUppercasePattern;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
* End of file BMPattern.hpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,369 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: BlockRangeFactory.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/BlockRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeTokenMap.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local static data
|
||||
// ---------------------------------------------------------------------------
|
||||
const int BLOCKNAMESIZE = 93;
|
||||
|
||||
// Block Names IsX
|
||||
// only define Specials as FEFF..FEFF, missing Specials as FFF0..FFFD, add manually
|
||||
// only define private use as E000..F8FF,
|
||||
// missing 2 private use (F0000..FFFFD and 100000..10FFFD), add manually
|
||||
const XMLCh fgBlockNames[][50] =
|
||||
{
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_a, chLatin_s, chLatin_i, chLatin_c, chLatin_L, chLatin_a,
|
||||
chLatin_t, chLatin_i, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_L, chLatin_a, chLatin_t, chLatin_i, chLatin_n, chDash, chDigit_1,
|
||||
chLatin_S, chLatin_u, chLatin_p, chLatin_p, chLatin_l, chLatin_e, chLatin_m, chLatin_e,
|
||||
chLatin_n, chLatin_t, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_L, chLatin_a, chLatin_t, chLatin_i, chLatin_n, chLatin_E, chLatin_x,
|
||||
chLatin_t, chLatin_e, chLatin_n, chLatin_d, chLatin_e, chLatin_d, chDash, chLatin_A,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_L, chLatin_a, chLatin_t, chLatin_i, chLatin_n, chLatin_E, chLatin_x,
|
||||
chLatin_t, chLatin_e, chLatin_n, chLatin_d, chLatin_e, chLatin_d, chDash, chLatin_B,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_I, chLatin_P, chLatin_A, chLatin_E, chLatin_x, chLatin_t, chLatin_e,
|
||||
chLatin_n, chLatin_s, chLatin_i, chLatin_o, chLatin_n, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_S, chLatin_p, chLatin_a, chLatin_c, chLatin_i, chLatin_n, chLatin_g,
|
||||
chLatin_M, chLatin_o, chLatin_d, chLatin_i, chLatin_f, chLatin_i, chLatin_e, chLatin_r,
|
||||
chLatin_L, chLatin_e, chLatin_t, chLatin_t, chLatin_e, chLatin_r, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_o, chLatin_m, chLatin_b, chLatin_i, chLatin_n, chLatin_i, chLatin_n,
|
||||
chLatin_g, chLatin_D, chLatin_i, chLatin_a, chLatin_c, chLatin_r, chLatin_i,
|
||||
chLatin_t, chLatin_i, chLatin_c, chLatin_a, chLatin_l, chLatin_M, chLatin_a,
|
||||
chLatin_r, chLatin_k, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_r, chLatin_e, chLatin_e, chLatin_k, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_y, chLatin_r, chLatin_i, chLatin_l, chLatin_l, chLatin_i, chLatin_c,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_A, chLatin_r, chLatin_m, chLatin_e, chLatin_n, chLatin_i, chLatin_a, chLatin_n,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_H, chLatin_e, chLatin_b, chLatin_r, chLatin_e, chLatin_w, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_A, chLatin_r, chLatin_a, chLatin_b, chLatin_i, chLatin_c, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_S, chLatin_y, chLatin_r, chLatin_i, chLatin_a, chLatin_c, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_T, chLatin_h, chLatin_a, chLatin_a, chLatin_n, chLatin_a, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_D, chLatin_e, chLatin_v, chLatin_a, chLatin_n, chLatin_a, chLatin_g, chLatin_a,
|
||||
chLatin_r, chLatin_i, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_e, chLatin_n, chLatin_g, chLatin_a, chLatin_l, chLatin_i, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_u, chLatin_r, chLatin_m, chLatin_u, chLatin_k, chLatin_h, chLatin_i,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_u, chLatin_j, chLatin_a, chLatin_r, chLatin_a, chLatin_t, chLatin_i,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_O, chLatin_r, chLatin_i, chLatin_y, chLatin_a, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_T, chLatin_a, chLatin_m, chLatin_i, chLatin_l, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_T, chLatin_e, chLatin_l, chLatin_u, chLatin_g, chLatin_u, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_K, chLatin_a, chLatin_n, chLatin_n, chLatin_a, chLatin_d, chLatin_a, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_a, chLatin_l, chLatin_a, chLatin_y, chLatin_a, chLatin_l, chLatin_a,
|
||||
chLatin_m, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_S, chLatin_i, chLatin_n, chLatin_h, chLatin_a, chLatin_l, chLatin_a, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_T, chLatin_h, chLatin_a, chLatin_i, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_L, chLatin_a, chLatin_o, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_T, chLatin_i, chLatin_b, chLatin_e, chLatin_t, chLatin_a, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_y, chLatin_a, chLatin_n, chLatin_m, chLatin_a, chLatin_r, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_e, chLatin_o, chLatin_r, chLatin_g, chLatin_i, chLatin_a, chLatin_n,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_H, chLatin_a, chLatin_n, chLatin_g, chLatin_u, chLatin_l, chLatin_J,
|
||||
chLatin_a, chLatin_m, chLatin_o, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_E, chLatin_t, chLatin_h, chLatin_i, chLatin_o, chLatin_p, chLatin_i, chLatin_c,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_h, chLatin_e, chLatin_r, chLatin_o, chLatin_k, chLatin_e, chLatin_e,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_U, chLatin_n, chLatin_i, chLatin_f, chLatin_i, chLatin_e, chLatin_d,
|
||||
chLatin_C, chLatin_a, chLatin_n, chLatin_a, chLatin_d, chLatin_i, chLatin_a, chLatin_n,
|
||||
chLatin_A, chLatin_b, chLatin_o, chLatin_r, chLatin_i, chLatin_g, chLatin_i, chLatin_n, chLatin_a, chLatin_l,
|
||||
chLatin_S, chLatin_y, chLatin_l, chLatin_l, chLatin_a, chLatin_b, chLatin_i, chLatin_c, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_O, chLatin_g, chLatin_h, chLatin_a, chLatin_m, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_R, chLatin_u, chLatin_n, chLatin_i, chLatin_c, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_K, chLatin_h, chLatin_m, chLatin_e, chLatin_r, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_o, chLatin_n, chLatin_g, chLatin_o, chLatin_l, chLatin_i,
|
||||
chLatin_a, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_L, chLatin_a, chLatin_t, chLatin_i, chLatin_n, chLatin_E, chLatin_x,
|
||||
chLatin_t, chLatin_e, chLatin_n, chLatin_d, chLatin_e, chLatin_d, chLatin_A,
|
||||
chLatin_d, chLatin_d, chLatin_i, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chLatin_a,
|
||||
chLatin_l, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_r, chLatin_e, chLatin_e, chLatin_k, chLatin_E, chLatin_x,
|
||||
chLatin_t, chLatin_e, chLatin_n, chLatin_d, chLatin_e, chLatin_d, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_e, chLatin_n, chLatin_e, chLatin_r, chLatin_a, chLatin_l,
|
||||
chLatin_P, chLatin_u, chLatin_n, chLatin_c, chLatin_t, chLatin_u, chLatin_a, chLatin_t,
|
||||
chLatin_i, chLatin_o, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_S, chLatin_u, chLatin_p, chLatin_e, chLatin_r, chLatin_s, chLatin_c, chLatin_r,
|
||||
chLatin_i, chLatin_p, chLatin_t, chLatin_s, chLatin_a, chLatin_n, chLatin_d,
|
||||
chLatin_S, chLatin_u, chLatin_b, chLatin_s, chLatin_c, chLatin_r, chLatin_i,
|
||||
chLatin_p, chLatin_t, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_u, chLatin_r, chLatin_r, chLatin_e, chLatin_n, chLatin_c, chLatin_y,
|
||||
chLatin_S, chLatin_y, chLatin_m, chLatin_b, chLatin_o, chLatin_l, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_o, chLatin_m, chLatin_b, chLatin_i, chLatin_n, chLatin_i, chLatin_n,
|
||||
chLatin_g, chLatin_M, chLatin_a, chLatin_r, chLatin_k, chLatin_s,
|
||||
chLatin_f, chLatin_o, chLatin_r, chLatin_S, chLatin_y, chLatin_m, chLatin_b,
|
||||
chLatin_o, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_L, chLatin_e, chLatin_t, chLatin_t, chLatin_e, chLatin_r, chLatin_l, chLatin_i,
|
||||
chLatin_k, chLatin_e, chLatin_S, chLatin_y, chLatin_m, chLatin_b, chLatin_o,
|
||||
chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_N, chLatin_u, chLatin_m, chLatin_b, chLatin_e, chLatin_r, chLatin_F,
|
||||
chLatin_o, chLatin_r, chLatin_m, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_A, chLatin_r, chLatin_r, chLatin_o, chLatin_w, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_a, chLatin_t, chLatin_h, chLatin_e, chLatin_m, chLatin_a, chLatin_t,
|
||||
chLatin_i, chLatin_c, chLatin_a, chLatin_l, chLatin_O, chLatin_p, chLatin_e,
|
||||
chLatin_r, chLatin_a, chLatin_t, chLatin_o, chLatin_r, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_i, chLatin_s, chLatin_c, chLatin_e, chLatin_l, chLatin_l, chLatin_a,
|
||||
chLatin_n, chLatin_e, chLatin_o, chLatin_u, chLatin_s, chLatin_T, chLatin_e,
|
||||
chLatin_c, chLatin_h, chLatin_n, chLatin_i, chLatin_c, chLatin_a, chLatin_l, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_o, chLatin_n, chLatin_t, chLatin_r, chLatin_o, chLatin_l,
|
||||
chLatin_P, chLatin_i, chLatin_c, chLatin_t, chLatin_u, chLatin_r, chLatin_e, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_O, chLatin_p, chLatin_t, chLatin_i, chLatin_c, chLatin_a, chLatin_l,
|
||||
chLatin_C, chLatin_h, chLatin_a, chLatin_r, chLatin_a, chLatin_c, chLatin_t, chLatin_e,
|
||||
chLatin_r, chLatin_R, chLatin_e, chLatin_c, chLatin_o, chLatin_g, chLatin_n,
|
||||
chLatin_i, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_E, chLatin_n, chLatin_c, chLatin_l, chLatin_o, chLatin_s, chLatin_e, chLatin_d,
|
||||
chLatin_A, chLatin_l, chLatin_p, chLatin_h, chLatin_a, chLatin_n, chLatin_u,
|
||||
chLatin_m, chLatin_e, chLatin_r, chLatin_i, chLatin_c, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_o, chLatin_x, chLatin_D, chLatin_r, chLatin_a, chLatin_w,
|
||||
chLatin_i, chLatin_n, chLatin_g, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_l, chLatin_o, chLatin_c, chLatin_k, chLatin_E, chLatin_l,
|
||||
chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_e, chLatin_o, chLatin_m, chLatin_e, chLatin_t, chLatin_r, chLatin_i,
|
||||
chLatin_c, chLatin_S, chLatin_h, chLatin_a, chLatin_p, chLatin_e, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_i, chLatin_s, chLatin_c, chLatin_e, chLatin_l, chLatin_l, chLatin_a,
|
||||
chLatin_n, chLatin_e, chLatin_o, chLatin_u, chLatin_s, chLatin_S, chLatin_y,
|
||||
chLatin_m, chLatin_b, chLatin_o, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_D, chLatin_i, chLatin_n, chLatin_g, chLatin_b, chLatin_a, chLatin_t, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_r, chLatin_a, chLatin_i, chLatin_l, chLatin_l, chLatin_e,
|
||||
chLatin_P, chLatin_a, chLatin_t, chLatin_t, chLatin_e, chLatin_r, chLatin_n, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_R, chLatin_a, chLatin_d, chLatin_i, chLatin_c,
|
||||
chLatin_a, chLatin_l, chLatin_s, chLatin_S, chLatin_u, chLatin_p, chLatin_p, chLatin_l, chLatin_e, chLatin_m,
|
||||
chLatin_e, chLatin_n, chLatin_t, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_K, chLatin_a, chLatin_n, chLatin_g, chLatin_x, chLatin_i,
|
||||
chLatin_R, chLatin_a, chLatin_d, chLatin_i, chLatin_c, chLatin_a, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_I, chLatin_d, chLatin_e, chLatin_o, chLatin_g, chLatin_r, chLatin_a, chLatin_p,
|
||||
chLatin_h, chLatin_i, chLatin_c, chLatin_D, chLatin_e, chLatin_s, chLatin_c, chLatin_r, chLatin_i, chLatin_p,
|
||||
chLatin_t, chLatin_i, chLatin_o, chLatin_n, chLatin_C, chLatin_h, chLatin_a, chLatin_r, chLatin_a, chLatin_c,
|
||||
chLatin_t, chLatin_e, chLatin_r, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_S, chLatin_y, chLatin_m, chLatin_b,
|
||||
chLatin_o, chLatin_l, chLatin_s, chLatin_a, chLatin_n, chLatin_d,
|
||||
chLatin_P, chLatin_u, chLatin_n, chLatin_c, chLatin_t, chLatin_u, chLatin_a, chLatin_t,
|
||||
chLatin_i, chLatin_o, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_H, chLatin_i, chLatin_r, chLatin_a, chLatin_g, chLatin_a, chLatin_n, chLatin_a,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_K, chLatin_a, chLatin_t, chLatin_a, chLatin_k, chLatin_a, chLatin_n, chLatin_a,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_o, chLatin_p, chLatin_o, chLatin_m, chLatin_o, chLatin_f, chLatin_o,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_H, chLatin_a, chLatin_n, chLatin_g, chLatin_u, chLatin_l, chLatin_C,
|
||||
chLatin_o, chLatin_m, chLatin_p, chLatin_a, chLatin_t, chLatin_i, chLatin_b, chLatin_i,
|
||||
chLatin_l, chLatin_i, chLatin_t, chLatin_y, chLatin_J, chLatin_a, chLatin_m,
|
||||
chLatin_o, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_K, chLatin_a, chLatin_n, chLatin_b, chLatin_u, chLatin_n, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_o, chLatin_p, chLatin_o, chLatin_m, chLatin_o, chLatin_f, chLatin_o,
|
||||
chLatin_E, chLatin_x, chLatin_t, chLatin_e, chLatin_n, chLatin_d, chLatin_e, chLatin_d, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_E, chLatin_n, chLatin_c, chLatin_l, chLatin_o, chLatin_s, chLatin_e, chLatin_d,
|
||||
chLatin_C, chLatin_J, chLatin_K, chLatin_L, chLatin_e, chLatin_t,
|
||||
chLatin_t, chLatin_e, chLatin_r, chLatin_s, chLatin_a, chLatin_n, chLatin_d,
|
||||
chLatin_M, chLatin_o, chLatin_n, chLatin_t, chLatin_h, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_C, chLatin_o, chLatin_m, chLatin_p,
|
||||
chLatin_a, chLatin_t, chLatin_i, chLatin_b, chLatin_i, chLatin_l, chLatin_i, chLatin_t,
|
||||
chLatin_y, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_U, chLatin_n, chLatin_i, chLatin_f,
|
||||
chLatin_i, chLatin_e, chLatin_d, chLatin_I, chLatin_d, chLatin_e, chLatin_o,
|
||||
chLatin_g, chLatin_r, chLatin_a, chLatin_p, chLatin_h, chLatin_s,
|
||||
chLatin_E, chLatin_x, chLatin_t, chLatin_e, chLatin_n, chLatin_s, chLatin_i, chLatin_o, chLatin_n, chLatin_A,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_U, chLatin_n, chLatin_i, chLatin_f,
|
||||
chLatin_i, chLatin_e, chLatin_d, chLatin_I, chLatin_d, chLatin_e, chLatin_o,
|
||||
chLatin_g, chLatin_r, chLatin_a, chLatin_p, chLatin_h, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_Y, chLatin_i, chLatin_S, chLatin_y, chLatin_l, chLatin_l, chLatin_a,
|
||||
chLatin_b, chLatin_l, chLatin_e, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_Y, chLatin_i, chLatin_R, chLatin_a, chLatin_d, chLatin_i, chLatin_c,
|
||||
chLatin_a, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_H, chLatin_a, chLatin_n, chLatin_g, chLatin_u, chLatin_l, chLatin_S,
|
||||
chLatin_y, chLatin_l, chLatin_l, chLatin_a, chLatin_b, chLatin_l, chLatin_e, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_P, chLatin_r, chLatin_i, chLatin_v, chLatin_a, chLatin_t, chLatin_e,
|
||||
chLatin_U, chLatin_s, chLatin_e, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_C, chLatin_o, chLatin_m, chLatin_p,
|
||||
chLatin_a, chLatin_t, chLatin_i, chLatin_b, chLatin_i, chLatin_l, chLatin_i, chLatin_t,
|
||||
chLatin_y, chLatin_I, chLatin_d, chLatin_e, chLatin_o, chLatin_g, chLatin_r,
|
||||
chLatin_a, chLatin_p, chLatin_h, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_A, chLatin_l, chLatin_p, chLatin_h, chLatin_a, chLatin_b, chLatin_e, chLatin_t,
|
||||
chLatin_i, chLatin_c, chLatin_P, chLatin_r, chLatin_e, chLatin_s, chLatin_e,
|
||||
chLatin_n, chLatin_t, chLatin_a, chLatin_t, chLatin_i, chLatin_o, chLatin_n,
|
||||
chLatin_F, chLatin_o, chLatin_r, chLatin_m, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_A, chLatin_r, chLatin_a, chLatin_b, chLatin_i, chLatin_c, chLatin_P,
|
||||
chLatin_r, chLatin_e, chLatin_s, chLatin_e, chLatin_n, chLatin_t, chLatin_a, chLatin_t,
|
||||
chLatin_i, chLatin_o, chLatin_n, chLatin_F, chLatin_o, chLatin_r, chLatin_m,
|
||||
chLatin_s, chDash, chLatin_A, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_o, chLatin_m, chLatin_b, chLatin_i, chLatin_n, chLatin_i, chLatin_n,
|
||||
chLatin_g, chLatin_H, chLatin_a, chLatin_l, chLatin_f, chLatin_M,
|
||||
chLatin_a, chLatin_r, chLatin_k, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_C, chLatin_o, chLatin_m, chLatin_p,
|
||||
chLatin_a, chLatin_t, chLatin_i, chLatin_b, chLatin_i, chLatin_l, chLatin_i, chLatin_t,
|
||||
chLatin_y, chLatin_F, chLatin_o, chLatin_r, chLatin_m, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_S, chLatin_m, chLatin_a, chLatin_l, chLatin_l, chLatin_F, chLatin_o,
|
||||
chLatin_r, chLatin_m, chLatin_V, chLatin_a, chLatin_r, chLatin_i, chLatin_a,
|
||||
chLatin_n, chLatin_t, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_A, chLatin_r, chLatin_a, chLatin_b, chLatin_i, chLatin_c, chLatin_P,
|
||||
chLatin_r, chLatin_e, chLatin_s, chLatin_e, chLatin_n, chLatin_t, chLatin_a, chLatin_t,
|
||||
chLatin_i, chLatin_o, chLatin_n, chLatin_F, chLatin_o, chLatin_r, chLatin_m,
|
||||
chLatin_s, chDash, chLatin_B, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_S, chLatin_p, chLatin_e, chLatin_c, chLatin_i, chLatin_a, chLatin_l, chLatin_s,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_H, chLatin_a, chLatin_l, chLatin_f, chLatin_w, chLatin_i, chLatin_d, chLatin_t,
|
||||
chLatin_h, chLatin_a, chLatin_n, chLatin_d, chLatin_F, chLatin_u,
|
||||
chLatin_l, chLatin_l, chLatin_w, chLatin_i, chLatin_d, chLatin_t, chLatin_h,
|
||||
chLatin_F, chLatin_o, chLatin_r, chLatin_m, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_O, chLatin_l, chLatin_d, chLatin_I, chLatin_t, chLatin_a, chLatin_l, chLatin_i,
|
||||
chLatin_c, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_G, chLatin_o, chLatin_t, chLatin_h, chLatin_i, chLatin_c, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_D, chLatin_e, chLatin_s, chLatin_e, chLatin_r, chLatin_e, chLatin_t, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_B, chLatin_y, chLatin_z, chLatin_a, chLatin_n, chLatin_t, chLatin_i, chLatin_n, chLatin_e,
|
||||
chLatin_M, chLatin_u, chLatin_s, chLatin_i, chLatin_c, chLatin_a, chLatin_l,
|
||||
chLatin_S, chLatin_y, chLatin_m, chLatin_b, chLatin_o, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_u, chLatin_s, chLatin_i, chLatin_c, chLatin_a, chLatin_l,
|
||||
chLatin_S, chLatin_y, chLatin_m, chLatin_b, chLatin_o, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_M, chLatin_a, chLatin_t, chLatin_h, chLatin_e,
|
||||
chLatin_m, chLatin_a, chLatin_t, chLatin_i, chLatin_c, chLatin_a, chLatin_l,
|
||||
chLatin_A, chLatin_l, chLatin_p, chLatin_h, chLatin_a,
|
||||
chLatin_n, chLatin_u, chLatin_m, chLatin_e, chLatin_r, chLatin_i, chLatin_c,
|
||||
chLatin_S, chLatin_y, chLatin_m, chLatin_b, chLatin_o, chLatin_l, chLatin_s, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_U, chLatin_n, chLatin_i, chLatin_f,
|
||||
chLatin_i, chLatin_e, chLatin_d, chLatin_I, chLatin_d, chLatin_e, chLatin_o,
|
||||
chLatin_g, chLatin_r, chLatin_a, chLatin_p, chLatin_h, chLatin_s,
|
||||
chLatin_E, chLatin_x, chLatin_t, chLatin_e, chLatin_n, chLatin_s, chLatin_i, chLatin_o, chLatin_n, chLatin_B,
|
||||
chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_C, chLatin_J, chLatin_K, chLatin_C, chLatin_o, chLatin_m, chLatin_p,
|
||||
chLatin_a, chLatin_t, chLatin_i, chLatin_b, chLatin_i, chLatin_l, chLatin_i, chLatin_t, chLatin_y,
|
||||
chLatin_I, chLatin_d, chLatin_e, chLatin_o, chLatin_g, chLatin_r, chLatin_a, chLatin_p, chLatin_h, chLatin_s,
|
||||
chLatin_S, chLatin_u, chLatin_p, chLatin_p, chLatin_l, chLatin_e, chLatin_m, chLatin_e, chLatin_n, chLatin_t, chNull },
|
||||
{ chLatin_I, chLatin_s, chLatin_T, chLatin_a, chLatin_g, chLatin_s, chNull },
|
||||
};
|
||||
|
||||
const XMLInt32 blockRanges[] =
|
||||
{
|
||||
0x0000,0x007F,0x0080,0x00FF,0x0100,0x017F,0x0180,0x024F,0x0250,0x02AF,0x02B0,0x02FF,
|
||||
0x0300,0x036F,0x0370,0x03FF,0x0400,0x04FF,0x0530,0x058F,0x0590,0x05FF,0x0600,0x06FF,
|
||||
0x0700,0x074F,0x0780,0x07BF,0x0900,0x097F,0x0980,0x09FF,0x0A00,0x0A7F,0x0A80,0x0AFF,
|
||||
0x0B00,0x0B7F,0x0B80,0x0BFF,0x0C00,0x0C7F,0x0C80,0x0CFF,0x0D00,0x0D7F,0x0D80,0x0DFF,
|
||||
0x0E00,0x0E7F,0x0E80,0x0EFF,0x0F00,0x0FFF,0x1000,0x109F,0x10A0,0x10FF,0x1100,0x11FF,
|
||||
0x1200,0x137F,0x13A0,0x13FF,0x1400,0x167F,0x1680,0x169F,0x16A0,0x16FF,0x1780,0x17FF,
|
||||
0x1800,0x18AF,0x1E00,0x1EFF,0x1F00,0x1FFF,0x2000,0x206F,0x2070,0x209F,0x20A0,0x20CF,
|
||||
0x20D0,0x20FF,0x2100,0x214F,0x2150,0x218F,0x2190,0x21FF,0x2200,0x22FF,0x2300,0x23FF,
|
||||
0x2400,0x243F,0x2440,0x245F,0x2460,0x24FF,0x2500,0x257F,0x2580,0x259F,0x25A0,0x25FF,
|
||||
0x2600,0x26FF,0x2700,0x27BF,0x2800,0x28FF,0x2E80,0x2EFF,0x2F00,0x2FDF,0x2FF0,0x2FFF,
|
||||
0x3000,0x303F,0x3040,0x309F,0x30A0,0x30FF,0x3100,0x312F,0x3130,0x318F,0x3190,0x319F,
|
||||
0x31A0,0x31BF,0x3200,0x32FF,0x3300,0x33FF,0x3400,0x4DB5,0x4E00,0x9FFF,0xA000,0xA48F,
|
||||
0xA490,0xA4CF,0xAC00,0xD7A3,0xE000,0xF8FF,0xF900,0xFAFF,0xFB00,0xFB4F,0xFB50,0xFDFF,
|
||||
0xFE20,0xFE2F,0xFE30,0xFE4F,0xFE50,0xFE6F,0xFE70,0xFEFE,0xFEFF,0xFEFF,0xFF00,0xFFEF,
|
||||
0x10300,0x1032F,0x10330,0x1034F,0x10400,0x1044F,0x1D000,0x1D0FF,0x1D100,0x1D1FF,
|
||||
0x1D400,0x1D7FF,0x20000,0x2A6D6,0x2F800,0x2FA1F,0xE0000,0xE007F, chNull
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BlockRangeFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
BlockRangeFactory::BlockRangeFactory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
BlockRangeFactory::~BlockRangeFactory() {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BlockRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void BlockRangeFactory::buildRanges(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fRangesCreated)
|
||||
return;
|
||||
|
||||
if (!fKeywordsInitialized) {
|
||||
initializeKeywordMap(rangeTokMap);
|
||||
}
|
||||
|
||||
TokenFactory* tokFactory = rangeTokMap->getTokenFactory();
|
||||
|
||||
//for performance, once the desired specials and private use are found
|
||||
//don't need to compareString anymore
|
||||
bool foundSpecial = false;
|
||||
bool foundPrivate = false;
|
||||
|
||||
for (int i=0; i < BLOCKNAMESIZE; i++) {
|
||||
RangeToken* tok = tokFactory->createRange();
|
||||
tok->addRange(blockRanges[i*2], blockRanges[(i*2)+1]);
|
||||
|
||||
if (!foundSpecial && XMLString::equals((XMLCh*)fgBlockNames[i] , (XMLCh*) fgBlockIsSpecials)) {
|
||||
tok->addRange(0xFFF0, 0xFFFD);
|
||||
foundSpecial = true;
|
||||
}
|
||||
if (!foundPrivate && XMLString::equals((XMLCh*)fgBlockNames[i] , (XMLCh*) fgBlockIsPrivateUse)) {
|
||||
tok->addRange(0xF0000, 0xFFFFD);
|
||||
tok->addRange(0x100000, 0x10FFFD);
|
||||
foundPrivate = true;
|
||||
}
|
||||
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgBlockNames[i], tok);
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgBlockNames[i], tok , true);
|
||||
}
|
||||
|
||||
fRangesCreated = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BlockRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void BlockRangeFactory::initializeKeywordMap(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fKeywordsInitialized)
|
||||
return;
|
||||
|
||||
for (int i=0; i< BLOCKNAMESIZE; i++) {
|
||||
rangeTokMap->addKeywordMap(fgBlockNames[i], fgBlockCategory);
|
||||
}
|
||||
|
||||
fKeywordsInitialized = true;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file BlockRangeFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: BlockRangeFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_BLOCKRANGEFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_BLOCKRANGEFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeFactory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT BlockRangeFactory: public RangeFactory {
|
||||
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
BlockRangeFactory();
|
||||
~BlockRangeFactory();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Initialization methods
|
||||
// -----------------------------------------------------------------------
|
||||
void initializeKeywordMap(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void buildRanges(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
BlockRangeFactory(const BlockRangeFactory&);
|
||||
BlockRangeFactory& operator=(const BlockRangeFactory&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file BlockRangeFactory.hpp
|
||||
*/
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: CharToken.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/CharToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
CharToken::CharToken(const Token::tokType tkType, const XMLInt32 ch, MemoryManager* const manager)
|
||||
: Token(tkType, manager)
|
||||
, fCharData(ch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
CharToken::~CharToken() {
|
||||
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file CharToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: CharToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_CHARTOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_CHARTOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT CharToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
CharToken(const tokType tkType, const XMLInt32 ch
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~CharToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLInt32 getChar() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Match methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool match(const XMLInt32 ch);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
CharToken(const CharToken&);
|
||||
CharToken& operator=(const CharToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
XMLInt32 fCharData;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CharToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLInt32 CharToken::getChar() const {
|
||||
|
||||
return fCharData;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CharToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline bool CharToken::match(const XMLInt32 ch){
|
||||
|
||||
return ch == fCharData;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file CharToken.hpp
|
||||
*/
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ClosureToken.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/ClosureToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ClosureToken: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
ClosureToken::ClosureToken(const Token::tokType tkType, Token* const tok, MemoryManager* const manager)
|
||||
: Token(tkType, manager)
|
||||
, fMin(-1)
|
||||
, fMax(-1)
|
||||
, fChild(tok)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
ClosureToken::~ClosureToken() {
|
||||
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file ClosureToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,114 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ClosureToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_CLOSURETOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_CLOSURETOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT ClosureToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
ClosureToken(const tokType tkType, Token* const tok
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~ClosureToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t size() const;
|
||||
int getMin() const;
|
||||
int getMax() const;
|
||||
Token* getChild(const XMLSize_t index) const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setMin(const int minVal);
|
||||
void setMax(const int maxVal);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ClosureToken(const ClosureToken&);
|
||||
ClosureToken& operator=(const ClosureToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
int fMin;
|
||||
int fMax;
|
||||
Token* fChild;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ClosureToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLSize_t ClosureToken::size() const {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
inline int ClosureToken::getMax() const {
|
||||
|
||||
return fMax;
|
||||
}
|
||||
|
||||
inline int ClosureToken::getMin() const {
|
||||
|
||||
return fMin;
|
||||
}
|
||||
|
||||
inline Token* ClosureToken::getChild(const XMLSize_t) const {
|
||||
|
||||
return fChild;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ClosureToken: setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void ClosureToken::setMax(const int maxVal) {
|
||||
|
||||
fMax = maxVal;
|
||||
}
|
||||
|
||||
inline void ClosureToken::setMin(const int minVal) {
|
||||
|
||||
fMin = minVal;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file ClosureToken.hpp
|
||||
*/
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ConcatToken.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/ConcatToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
ConcatToken::ConcatToken(Token* const tok1, Token* const tok2, MemoryManager* const manager)
|
||||
: Token(Token::T_CONCAT, manager)
|
||||
, fChild1(tok1)
|
||||
, fChild2(tok2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
ConcatToken::~ConcatToken() {
|
||||
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file ConcatToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ConcatToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_CONCATTOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_CONCATTOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT ConcatToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
ConcatToken(Token* const tok1, Token* const tok2
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~ConcatToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
Token* getChild(const XMLSize_t index) const;
|
||||
XMLSize_t size() const;
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ConcatToken(const ConcatToken&);
|
||||
ConcatToken& operator=(const ConcatToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
Token* fChild1;
|
||||
Token* fChild2;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StringToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLSize_t ConcatToken::size() const {
|
||||
|
||||
return 2;
|
||||
}
|
||||
|
||||
inline Token* ConcatToken::getChild(const XMLSize_t index) const {
|
||||
|
||||
return index == 0 ? fChild1 : fChild2;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file ConcatToken.hpp
|
||||
*/
|
||||
@@ -0,0 +1,120 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Match.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Match.hpp>
|
||||
#include <xercesc/framework/MemoryManager.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Match: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
Match::Match(MemoryManager* const manager) :
|
||||
fNoGroups(0)
|
||||
, fPositionsSize(0)
|
||||
, fStartPositions(0)
|
||||
, fEndPositions(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Match::Match(const Match& toCopy) :
|
||||
XMemory(toCopy)
|
||||
, fNoGroups(0)
|
||||
, fPositionsSize(0)
|
||||
, fStartPositions(0)
|
||||
, fEndPositions(0)
|
||||
, fMemoryManager(0)
|
||||
{
|
||||
initialize(toCopy);
|
||||
}
|
||||
|
||||
Match& Match::operator=(const Match& toAssign) {
|
||||
|
||||
initialize(toAssign);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
Match::~Match() {
|
||||
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Match: Setter Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void Match::setNoGroups(const int n) {
|
||||
|
||||
if (fNoGroups <= 0 || fPositionsSize < n) {
|
||||
|
||||
cleanUp();
|
||||
fPositionsSize = n;
|
||||
fStartPositions = (int*) fMemoryManager->allocate(n * sizeof(int));//new int[n];
|
||||
fEndPositions = (int*) fMemoryManager->allocate(n * sizeof(int));//new int[n];
|
||||
}
|
||||
|
||||
fNoGroups = n;
|
||||
|
||||
for (int i=0; i< fPositionsSize; i++) {
|
||||
|
||||
fStartPositions[i] = -1;
|
||||
fEndPositions[i] = -1;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Match: private helpers methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void Match::initialize(const Match &toCopy){
|
||||
|
||||
//do not copy over value of fPositionSize as it is irrelevant to the
|
||||
//state of the Match
|
||||
|
||||
fMemoryManager = toCopy.fMemoryManager;
|
||||
int toCopySize = toCopy.getNoGroups();
|
||||
setNoGroups(toCopySize);
|
||||
|
||||
for (int i=0; i<toCopySize; i++){
|
||||
setStartPos(i, toCopy.getStartPos(i));
|
||||
setEndPos(i, toCopy.getEndPos(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void Match::cleanUp() {
|
||||
|
||||
fMemoryManager->deallocate(fStartPositions);//delete [] fStartPositions;
|
||||
fMemoryManager->deallocate(fEndPositions);//delete [] fEndPositions;
|
||||
|
||||
fStartPositions = 0;
|
||||
fEndPositions = 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file Match.cpp
|
||||
*/
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Match.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_MATCH_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_MATCH_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* An instance of this class has ranges captured in matching
|
||||
*/
|
||||
class XMLUTIL_EXPORT Match : public XMemory
|
||||
{
|
||||
public:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
Match(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
/**
|
||||
* Copy constructor
|
||||
*/
|
||||
Match(const Match& toCopy);
|
||||
Match& operator=(const Match& toAssign);
|
||||
|
||||
virtual ~Match();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
int getNoGroups() const;
|
||||
int getStartPos(int index) const;
|
||||
int getEndPos(int index) const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter functions
|
||||
// -----------------------------------------------------------------------
|
||||
void setNoGroups(const int n);
|
||||
void setStartPos(const int index, const int value);
|
||||
void setEndPos(const int index, const int value);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Initialize/Clean up methods
|
||||
// -----------------------------------------------------------------------
|
||||
void initialize(const Match& toCopy);
|
||||
void cleanUp();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fNoGroups
|
||||
// Represents no of regular expression groups
|
||||
//
|
||||
// fStartPositions
|
||||
// Array of start positions in the target text matched to specific
|
||||
// regular expression group
|
||||
//
|
||||
// fEndPositions
|
||||
// Array of end positions in the target text matched to specific
|
||||
// regular expression group
|
||||
//
|
||||
// fPositionsSize
|
||||
// Actual size of Start/EndPositions array.
|
||||
// -----------------------------------------------------------------------
|
||||
int fNoGroups;
|
||||
int fPositionsSize;
|
||||
int* fStartPositions;
|
||||
int* fEndPositions;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
/**
|
||||
* Inline Methods
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Match: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline int Match::getNoGroups() const {
|
||||
|
||||
if (fNoGroups < 0)
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
||||
|
||||
return fNoGroups;
|
||||
}
|
||||
|
||||
inline int Match::getStartPos(int index) const {
|
||||
|
||||
if (!fStartPositions)
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
||||
|
||||
if (index < 0 || fNoGroups <= index)
|
||||
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
||||
|
||||
return fStartPositions[index];
|
||||
}
|
||||
|
||||
inline int Match::getEndPos(int index) const {
|
||||
|
||||
if (!fEndPositions)
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
||||
|
||||
if (index < 0 || fNoGroups <= index)
|
||||
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
||||
|
||||
return fEndPositions[index];
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Match: setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void Match::setStartPos(const int index, const int value) {
|
||||
|
||||
if (!fStartPositions)
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
||||
|
||||
if (index < 0 || fNoGroups <= index)
|
||||
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
||||
|
||||
fStartPositions[index] = value;
|
||||
}
|
||||
|
||||
inline void Match::setEndPos(const int index, const int value) {
|
||||
|
||||
if (!fEndPositions)
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
||||
|
||||
if (index < 0 || fNoGroups <= index)
|
||||
ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
||||
|
||||
fEndPositions[index] = value;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,216 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Op.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Op.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Op: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
Op::Op(const Op::opType type, MemoryManager* const manager)
|
||||
: fMemoryManager(manager)
|
||||
, fOpType(type)
|
||||
, fNextOp(0)
|
||||
{
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Op: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLSize_t Op::getSize() const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
XMLInt32 Op::getData() const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
XMLInt32 Op::getData2() const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
const Op* Op::elementAt(XMLSize_t) const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
const Op* Op::getChild() const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
const XMLCh* Op::getLiteral() const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
const Token* Op::getToken() const {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CharOp: Constructors and Destuctors
|
||||
// ---------------------------------------------------------------------------
|
||||
CharOp::CharOp(const Op::opType type, const XMLInt32 charData
|
||||
, MemoryManager* const manager)
|
||||
: Op(type, manager)
|
||||
, fCharData(charData) {
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// CharOp: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLInt32 CharOp::getData() const {
|
||||
|
||||
return fCharData;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnionOp: Constructors and Destuctors
|
||||
// ---------------------------------------------------------------------------
|
||||
UnionOp::UnionOp(const Op::opType type, const XMLSize_t size, MemoryManager* const manager)
|
||||
: Op(type, manager)
|
||||
, fBranches(new (manager) RefVectorOf<Op> (size, false, manager)) {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnionOp: Getter/Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLSize_t UnionOp::getSize() const {
|
||||
|
||||
return fBranches->size();
|
||||
}
|
||||
|
||||
const Op* UnionOp::elementAt(XMLSize_t index) const {
|
||||
|
||||
return fBranches->elementAt(index);
|
||||
}
|
||||
|
||||
void UnionOp::addElement(Op* const op) {
|
||||
|
||||
fBranches->addElement(op);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ChildOp: Constructors and Destuctors
|
||||
// ---------------------------------------------------------------------------
|
||||
ChildOp::ChildOp(const Op::opType type, MemoryManager* const manager)
|
||||
: Op(type, manager)
|
||||
, fChild(0) {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ChildOp: Getter/Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const Op* ChildOp::getChild() const {
|
||||
|
||||
return fChild;
|
||||
}
|
||||
|
||||
void ChildOp::setChild(const Op* const child) {
|
||||
|
||||
fChild = child;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ModifierOp: Constructors and Destuctors
|
||||
// ---------------------------------------------------------------------------
|
||||
ModifierOp::ModifierOp(const Op::opType type, const XMLInt32 v1, const XMLInt32 v2
|
||||
, MemoryManager* const manager)
|
||||
: ChildOp(type, manager)
|
||||
, fVal1(v1)
|
||||
, fVal2(v2) {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ModifierOp: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLInt32 ModifierOp::getData() const {
|
||||
|
||||
return fVal1;
|
||||
}
|
||||
|
||||
XMLInt32 ModifierOp::getData2() const {
|
||||
|
||||
return fVal2;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeOp: Constructors and Destuctors
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeOp::RangeOp(const Op::opType type, const Token* const token, MemoryManager* const manager)
|
||||
: Op (type, manager)
|
||||
, fToken(token) {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeOp: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const Token* RangeOp::getToken() const {
|
||||
|
||||
return fToken;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StringOp: Constructors and Destuctors
|
||||
// ---------------------------------------------------------------------------
|
||||
StringOp::StringOp(const Op::opType type, const XMLCh* const literal
|
||||
, MemoryManager* const manager)
|
||||
: Op (type, manager)
|
||||
, fLiteral(XMLString::replicate(literal, manager)) {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StringOp: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLCh* StringOp::getLiteral() const {
|
||||
|
||||
return fLiteral;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End file Op.cpp
|
||||
*/
|
||||
@@ -0,0 +1,306 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Op.hpp 932887 2010-04-11 13:04:59Z borisk $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_OP_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_OP_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class Token;
|
||||
|
||||
|
||||
class XMLUTIL_EXPORT Op : public XMemory
|
||||
{
|
||||
public:
|
||||
|
||||
typedef enum {
|
||||
O_DOT = 0,
|
||||
O_CHAR = 1,
|
||||
O_RANGE = 3,
|
||||
O_NRANGE = 4,
|
||||
O_ANCHOR = 5,
|
||||
O_STRING = 6,
|
||||
O_CLOSURE = 7,
|
||||
O_NONGREEDYCLOSURE = 8,
|
||||
O_FINITE_CLOSURE = 9,
|
||||
O_FINITE_NONGREEDYCLOSURE = 10,
|
||||
O_QUESTION = 11,
|
||||
O_NONGREEDYQUESTION = 12,
|
||||
O_UNION = 13,
|
||||
O_CAPTURE = 15,
|
||||
O_BACKREFERENCE = 16
|
||||
} opType;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
virtual ~Op() { }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
opType getOpType() const;
|
||||
const Op* getNextOp() const;
|
||||
virtual XMLInt32 getData() const;
|
||||
virtual XMLInt32 getData2() const;
|
||||
virtual XMLSize_t getSize() const;
|
||||
virtual const Op* elementAt(XMLSize_t index) const;
|
||||
virtual const Op* getChild() const;
|
||||
virtual const Token* getToken() const;
|
||||
virtual const XMLCh* getLiteral() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter functions
|
||||
// -----------------------------------------------------------------------
|
||||
void setOpType(const opType type);
|
||||
void setNextOp(const Op* const next);
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected Constructors
|
||||
// -----------------------------------------------------------------------
|
||||
Op(const opType type, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
friend class OpFactory;
|
||||
|
||||
MemoryManager* const fMemoryManager;
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
Op(const Op&);
|
||||
Op& operator=(const Op&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fOpType
|
||||
// Indicates the type of operation
|
||||
//
|
||||
// fNextOp
|
||||
// Points to the next operation in the chain
|
||||
// -----------------------------------------------------------------------
|
||||
opType fOpType;
|
||||
const Op* fNextOp;
|
||||
};
|
||||
|
||||
|
||||
class XMLUTIL_EXPORT CharOp: public Op {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
CharOp(const opType type, const XMLInt32 charData, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~CharOp() {}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
XMLInt32 getData() const;
|
||||
|
||||
private:
|
||||
// Private data members
|
||||
XMLInt32 fCharData;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
CharOp(const CharOp&);
|
||||
CharOp& operator=(const CharOp&);
|
||||
};
|
||||
|
||||
class XMLUTIL_EXPORT UnionOp : public Op {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
UnionOp(const opType type, const XMLSize_t size,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~UnionOp() { delete fBranches; }
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t getSize() const;
|
||||
const Op* elementAt(XMLSize_t index) const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter functions
|
||||
// -----------------------------------------------------------------------
|
||||
void addElement(Op* const op);
|
||||
|
||||
private:
|
||||
// Private Data members
|
||||
RefVectorOf<Op>* fBranches;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
UnionOp(const UnionOp&);
|
||||
UnionOp& operator=(const UnionOp&);
|
||||
};
|
||||
|
||||
|
||||
class XMLUTIL_EXPORT ChildOp: public Op {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
ChildOp(const opType type, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~ChildOp() {}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
const Op* getChild() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter functions
|
||||
// -----------------------------------------------------------------------
|
||||
void setChild(const Op* const child);
|
||||
|
||||
private:
|
||||
// Private data members
|
||||
const Op* fChild;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ChildOp(const ChildOp&);
|
||||
ChildOp& operator=(const ChildOp&);
|
||||
};
|
||||
|
||||
class XMLUTIL_EXPORT ModifierOp: public ChildOp {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
ModifierOp(const opType type, const XMLInt32 v1, const XMLInt32 v2, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~ModifierOp() {}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
XMLInt32 getData() const;
|
||||
XMLInt32 getData2() const;
|
||||
|
||||
private:
|
||||
// Private data members
|
||||
XMLInt32 fVal1;
|
||||
XMLInt32 fVal2;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ModifierOp(const ModifierOp&);
|
||||
ModifierOp& operator=(const ModifierOp&);
|
||||
};
|
||||
|
||||
class XMLUTIL_EXPORT RangeOp: public Op {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
RangeOp(const opType type, const Token* const token, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~RangeOp() {}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
const Token* getToken() const;
|
||||
|
||||
private:
|
||||
// Private data members
|
||||
const Token* fToken;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RangeOp(const RangeOp&);
|
||||
RangeOp& operator=(const RangeOp&);
|
||||
};
|
||||
|
||||
class XMLUTIL_EXPORT StringOp: public Op {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StringOp(const opType type, const XMLCh* const literal, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~StringOp() { fMemoryManager->deallocate(fLiteral);}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter functions
|
||||
// -----------------------------------------------------------------------
|
||||
const XMLCh* getLiteral() const;
|
||||
|
||||
private:
|
||||
// Private data members
|
||||
XMLCh* fLiteral;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
StringOp(const StringOp&);
|
||||
StringOp& operator=(const StringOp&);
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Op: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline Op::opType Op::getOpType() const {
|
||||
|
||||
return fOpType;
|
||||
}
|
||||
|
||||
inline const Op* Op::getNextOp() const {
|
||||
|
||||
return fNextOp;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Op: setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void Op::setOpType(const Op::opType type) {
|
||||
|
||||
fOpType = type;
|
||||
}
|
||||
|
||||
inline void Op::setNextOp(const Op* const nextOp) {
|
||||
|
||||
fNextOp = nextOp;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file Op.hpp
|
||||
*/
|
||||
@@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: OpFactory.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Op.hpp>
|
||||
#include <xercesc/util/regx/OpFactory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// OpFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
OpFactory::OpFactory(MemoryManager* const manager) :
|
||||
fOpVector(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
fOpVector = new (fMemoryManager) RefVectorOf<Op>(16, true, fMemoryManager);
|
||||
}
|
||||
|
||||
OpFactory::~OpFactory() {
|
||||
|
||||
delete fOpVector;
|
||||
fOpVector = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// OpFactory - Factory methods
|
||||
// ---------------------------------------------------------------------------
|
||||
Op* OpFactory::createDotOp() {
|
||||
|
||||
Op* tmpOp = new (fMemoryManager) Op(Op::O_DOT, fMemoryManager);
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
CharOp* OpFactory::createCharOp(XMLInt32 data) {
|
||||
|
||||
CharOp* tmpOp = new (fMemoryManager) CharOp(Op::O_CHAR, data, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
CharOp* OpFactory::createAnchorOp(XMLInt32 data) {
|
||||
|
||||
CharOp* tmpOp = new (fMemoryManager) CharOp(Op::O_ANCHOR, data, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
CharOp* OpFactory::createCaptureOp(int number, const Op* const next) {
|
||||
|
||||
CharOp* tmpOp = new (fMemoryManager) CharOp(Op::O_CAPTURE, number, fMemoryManager);
|
||||
|
||||
tmpOp->setNextOp(next);
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
UnionOp* OpFactory::createUnionOp(XMLSize_t size) {
|
||||
|
||||
UnionOp* tmpOp = new (fMemoryManager) UnionOp(Op::O_UNION, size, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
ChildOp* OpFactory::createClosureOp(int id) {
|
||||
|
||||
ModifierOp* tmpOp = new (fMemoryManager) ModifierOp(Op::O_CLOSURE, id, -1, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
ChildOp* OpFactory::createNonGreedyClosureOp() {
|
||||
|
||||
ChildOp* tmpOp = new (fMemoryManager) ChildOp(Op::O_NONGREEDYCLOSURE, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
ChildOp* OpFactory::createQuestionOp(bool nonGreedy) {
|
||||
|
||||
ChildOp* tmpOp = new (fMemoryManager) ChildOp(nonGreedy ? Op::O_NONGREEDYQUESTION :
|
||||
Op::O_QUESTION, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
RangeOp* OpFactory::createRangeOp(const Token* const token) {
|
||||
|
||||
RangeOp* tmpOp = new (fMemoryManager) RangeOp(Op::O_RANGE, token, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
CharOp* OpFactory::createBackReferenceOp(int refNo) {
|
||||
|
||||
CharOp* tmpOp = new (fMemoryManager) CharOp(Op::O_BACKREFERENCE, refNo, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
StringOp* OpFactory::createStringOp(const XMLCh* const literal) {
|
||||
|
||||
StringOp* tmpOp = new (fMemoryManager) StringOp(Op::O_STRING, literal, fMemoryManager);
|
||||
|
||||
fOpVector->addElement(tmpOp);
|
||||
return tmpOp;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file OpFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: OpFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_OPFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_OPFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class Op;
|
||||
class CharOp;
|
||||
class UnionOp;
|
||||
class ChildOp;
|
||||
class RangeOp;
|
||||
class StringOp;
|
||||
class ModifierOp;
|
||||
class Token;
|
||||
|
||||
/*
|
||||
* A Factory class used by 'RegularExpression' to create different types of
|
||||
* operations (Op) objects. The class will keep track of all objects created
|
||||
* for cleanup purposes. Each 'RegularExpression' object will have its own
|
||||
* instance of OpFactory and when a 'RegularExpression' object is deleted
|
||||
* all associated Op objects will be deleted.
|
||||
*/
|
||||
|
||||
class XMLUTIL_EXPORT OpFactory : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and destructors
|
||||
// -----------------------------------------------------------------------
|
||||
OpFactory(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~OpFactory();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Factory methods
|
||||
// -----------------------------------------------------------------------
|
||||
Op* createDotOp();
|
||||
CharOp* createCharOp(XMLInt32 data);
|
||||
CharOp* createAnchorOp(XMLInt32 data);
|
||||
CharOp* createCaptureOp(int number, const Op* const next);
|
||||
UnionOp* createUnionOp(XMLSize_t size);
|
||||
ChildOp* createClosureOp(int id);
|
||||
ChildOp* createNonGreedyClosureOp();
|
||||
ChildOp* createQuestionOp(bool nonGreedy);
|
||||
RangeOp* createRangeOp(const Token* const token);
|
||||
CharOp* createBackReferenceOp(int refNo);
|
||||
StringOp* createStringOp(const XMLCh* const literal);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Reset methods
|
||||
// -----------------------------------------------------------------------
|
||||
/*
|
||||
* Remove all created Op objects from Vector
|
||||
*/
|
||||
void reset();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
OpFactory(const OpFactory&);
|
||||
OpFactory& operator=(const OpFactory&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fOpVector
|
||||
// Contains Op objects. Used for memory cleanup.
|
||||
// -----------------------------------------------------------------------
|
||||
RefVectorOf<Op>* fOpVector;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// OpFactory - Factory methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void OpFactory::reset() {
|
||||
|
||||
fOpVector->removeAllElements();
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file OpFactory
|
||||
*/
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ParenToken.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/ParenToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ParenToken: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
ParenToken::ParenToken(const Token::tokType tkType,
|
||||
Token* const tok, const int noParen, MemoryManager* const manager)
|
||||
: Token(tkType, manager)
|
||||
, fNoParen(noParen)
|
||||
, fChild(tok)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
ParenToken::~ParenToken() {
|
||||
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file ParenToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ParenToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PARENTOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PARENTOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT ParenToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
ParenToken(const tokType tkType, Token* const tok,
|
||||
const int noParen, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~ParenToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t size() const;
|
||||
int getNoParen() const;
|
||||
Token* getChild(const XMLSize_t index) const;
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ParenToken(const ParenToken&);
|
||||
ParenToken& operator=(const ParenToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
int fNoParen;
|
||||
Token* fChild;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ParenToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLSize_t ParenToken::size() const {
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int ParenToken::getNoParen() const {
|
||||
|
||||
return fNoParen;
|
||||
}
|
||||
|
||||
inline Token* ParenToken::getChild(const XMLSize_t) const {
|
||||
|
||||
return fChild;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file ParenToken.hpp
|
||||
*/
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ParserForXMLSchema.cpp 1662882 2015-02-28 02:07:25Z scantor $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/ParserForXMLSchema.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/TokenInc.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/ParseException.hpp>
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ParserForXMLSchema: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
ParserForXMLSchema::ParserForXMLSchema(MemoryManager* const manager)
|
||||
: RegxParser(manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ParserForXMLSchema::~ParserForXMLSchema() {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ParserForXMLSchema: Parsing/Processing methods
|
||||
// ---------------------------------------------------------------------------
|
||||
Token* ParserForXMLSchema::processCaret() {
|
||||
|
||||
// XML Schema treats "^" like any other char
|
||||
processNext();
|
||||
return getTokenFactory()->createChar(chCaret);
|
||||
}
|
||||
|
||||
Token* ParserForXMLSchema::processDollar() {
|
||||
|
||||
// XML Schema treats "$" like any other char
|
||||
processNext();
|
||||
return getTokenFactory()->createChar(chDollarSign);
|
||||
}
|
||||
|
||||
Token* ParserForXMLSchema::processPlus(Token* const tok) {
|
||||
|
||||
// XML Schema doesn't support reluctant quantifiers
|
||||
processNext();
|
||||
return getTokenFactory()->createConcat(tok,
|
||||
getTokenFactory()->createClosure(tok));
|
||||
}
|
||||
|
||||
Token* ParserForXMLSchema::processStar(Token* const tok) {
|
||||
|
||||
// XML Schema doesn't support reluctant quantifiers
|
||||
processNext();
|
||||
return getTokenFactory()->createClosure(tok);
|
||||
}
|
||||
|
||||
Token* ParserForXMLSchema::processQuestion(Token* const tok) {
|
||||
|
||||
// XML Schema doesn't support reluctant quantifiers
|
||||
processNext();
|
||||
|
||||
TokenFactory* tokFactory = getTokenFactory();
|
||||
Token* retTok = tokFactory->createUnion();
|
||||
retTok->addChild(tok, tokFactory);
|
||||
retTok->addChild(tokFactory->createToken(Token::T_EMPTY), tokFactory);
|
||||
return retTok;
|
||||
}
|
||||
|
||||
Token* ParserForXMLSchema::processParen() {
|
||||
|
||||
// XML Schema doesn't support back references
|
||||
processNext();
|
||||
Token* retTok = getTokenFactory()->createParenthesis(parseRegx(true), 0);
|
||||
|
||||
if (getState() != REGX_T_RPAREN) {
|
||||
ThrowXMLwithMemMgr(ParseException, XMLExcepts::Parser_Factor1, getMemoryManager());
|
||||
}
|
||||
|
||||
processNext();
|
||||
return retTok;
|
||||
}
|
||||
|
||||
Token* ParserForXMLSchema::processBackReference() {
|
||||
|
||||
// XML Schema doesn't support back references
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, getMemoryManager());
|
||||
return 0; // for compilers that complain about no return value
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// ParserForXMLSchema: Helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
bool ParserForXMLSchema::checkQuestion(const XMLSize_t ) {
|
||||
|
||||
// XML Schema doesn't support reluctant quantifiers
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
XMLInt32 ParserForXMLSchema::decodeEscaped() {
|
||||
|
||||
// XML Schema doesn't support an escaped "$"
|
||||
if (getState() != REGX_T_BACKSOLIDUS)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, getMemoryManager());
|
||||
|
||||
XMLInt32 ch = getCharData();
|
||||
|
||||
switch (ch) {
|
||||
case chLatin_n:
|
||||
ch = chLF;
|
||||
break;
|
||||
case chLatin_r:
|
||||
ch = chCR;
|
||||
break;
|
||||
case chLatin_t:
|
||||
ch = chHTab;
|
||||
break;
|
||||
case chBackSlash:
|
||||
case chPipe:
|
||||
case chPeriod:
|
||||
case chCaret:
|
||||
case chDash:
|
||||
case chQuestion:
|
||||
case chAsterisk:
|
||||
case chPlus:
|
||||
case chOpenCurly:
|
||||
case chCloseCurly:
|
||||
case chOpenParen:
|
||||
case chCloseParen:
|
||||
case chOpenSquare:
|
||||
case chCloseSquare:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
XMLCh chString[] = {chBackSlash, (XMLCh)ch, chNull};
|
||||
ThrowXMLwithMemMgr1(ParseException,XMLExcepts::Parser_Process2, chString, getMemoryManager());
|
||||
}
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file ParserForXMLSchema.cpp
|
||||
*/
|
||||
@@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: ParserForXMLSchema.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_PARSERFORXMLSCHEMA_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_PARSERFORXMLSCHEMA_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RegxParser.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class Token;
|
||||
class RangeToken;
|
||||
|
||||
class XMLUTIL_EXPORT ParserForXMLSchema : public RegxParser {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
ParserForXMLSchema(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~ParserForXMLSchema();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Parsing/Processing methods
|
||||
// -----------------------------------------------------------------------
|
||||
Token* processCaret();
|
||||
Token* processDollar();
|
||||
Token* processStar(Token* const tok);
|
||||
Token* processPlus(Token* const tok);
|
||||
Token* processQuestion(Token* const tok);
|
||||
Token* processParen();
|
||||
Token* processBackReference();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool checkQuestion(const XMLSize_t off);
|
||||
XMLInt32 decodeEscaped();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
ParserForXMLSchema(const ParserForXMLSchema&);
|
||||
ParserForXMLSchema& operator=(const ParserForXMLSchema&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file ParserForXMLSchema.hpp
|
||||
*/
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RangeFactory.cpp 471747 2006-11-06 14:31:56Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeFactory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeFactory::RangeFactory() :
|
||||
fRangesCreated(false)
|
||||
, fKeywordsInitialized(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RangeFactory::~RangeFactory() {
|
||||
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file RangeFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RangeFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_RANGEFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_RANGEFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMemory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class RangeTokenMap;
|
||||
|
||||
class XMLUTIL_EXPORT RangeFactory : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and destructors
|
||||
// -----------------------------------------------------------------------
|
||||
virtual ~RangeFactory();
|
||||
|
||||
//-----------------------------------------------------------------------
|
||||
// Initialization methods
|
||||
// -----------------------------------------------------------------------
|
||||
/**
|
||||
* To maintain src code compatibility, we added a default parameter.
|
||||
* The caller is expected to pass in a valid RangeTokenMap instance.
|
||||
*/
|
||||
virtual void initializeKeywordMap(RangeTokenMap *rangeTokMap = 0) = 0;
|
||||
|
||||
/*
|
||||
* Used by children to build commonly used ranges
|
||||
* To maintain src code compatibility, we added a default parameter.
|
||||
* The caller is expected to pass in a valid RangeTokenMap instance.
|
||||
*/
|
||||
virtual void buildRanges(RangeTokenMap *rangeTokMap = 0) = 0;
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructor and destructors
|
||||
// -----------------------------------------------------------------------
|
||||
RangeFactory();
|
||||
|
||||
//friend class RangeTokenMap;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Data
|
||||
// -----------------------------------------------------------------------
|
||||
bool fRangesCreated;
|
||||
bool fKeywordsInitialized;
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RangeFactory(const RangeFactory&);
|
||||
RangeFactory& operator=(const RangeFactory&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file RangeFactory.hpp
|
||||
*/
|
||||
@@ -0,0 +1,874 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RangeToken.cpp 901107 2010-01-20 08:45:02Z borisk $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/IllegalArgumentException.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
|
||||
#if XERCES_USE_TRANSCODER_ICU
|
||||
#include <unicode/uchar.h>
|
||||
|
||||
#if (U_ICU_VERSION_MAJOR_NUM > 2) || (U_ICU_VERSION_MAJOR_NUM == 2 && U_ICU_VERSION_MINOR_NUM >=4)
|
||||
#include <unicode/uset.h>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/Janitor.hpp>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Static member data initialization
|
||||
// ---------------------------------------------------------------------------
|
||||
const int RangeToken::MAPSIZE = 256;
|
||||
const unsigned int RangeToken::INITIALSIZE = 16;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeToken: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeToken::RangeToken(const Token::tokType tkType,
|
||||
MemoryManager* const manager)
|
||||
: Token(tkType, manager)
|
||||
, fSorted(false)
|
||||
, fCompacted(false)
|
||||
, fNonMapIndex(0)
|
||||
, fElemCount(0)
|
||||
, fMaxCount(INITIALSIZE)
|
||||
, fMap(0)
|
||||
, fRanges(0)
|
||||
, fCaseIToken(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RangeToken::~RangeToken() {
|
||||
|
||||
// TODO(dbertoni) This is a temporary hack until we can change the ABI.
|
||||
// See Jira issue XERCESC-1866 for more details.
|
||||
if (fCaseIToken && fCaseIToken->fCaseIToken == this)
|
||||
{
|
||||
fCaseIToken->fCaseIToken = 0;
|
||||
}
|
||||
fMemoryManager->deallocate(fMap);//delete [] fMap;
|
||||
fMemoryManager->deallocate(fRanges);//delete[] fRanges;
|
||||
}
|
||||
|
||||
|
||||
// This is a struct that defines a mapping for
|
||||
// case-insensitive matching. The first character
|
||||
// is the character we try to match in the range.
|
||||
// The second is the character we add to the range,
|
||||
// because it maps to the first when we're folding
|
||||
// case.
|
||||
struct ExceptionCharsStruct
|
||||
{
|
||||
XMLInt32 baseChar;
|
||||
|
||||
XMLInt32 matchingChar;
|
||||
};
|
||||
|
||||
|
||||
// This is an array of character mappings that we will
|
||||
// add to ranges for case-insensitive matching.
|
||||
static const ExceptionCharsStruct s_exceptions[] =
|
||||
{
|
||||
{ 0x49, 0x130 },
|
||||
{ 0x49, 0x131 },
|
||||
{ 0x4b, 0x212a },
|
||||
{ 0x53, 0x17f },
|
||||
{ 0x69, 0x130 },
|
||||
{ 0x69, 0x131 },
|
||||
{ 0x6b, 0x212a },
|
||||
{ 0x73, 0x17f },
|
||||
{ 0xc5, 0x212b },
|
||||
{ 0xe5, 0x212b },
|
||||
{ 0x1c4, 0x1c5 },
|
||||
{ 0x1c6, 0x1c5 },
|
||||
{ 0x1c7, 0x1c8 },
|
||||
{ 0x1c9, 0x1c8 },
|
||||
{ 0x1ca, 0x1cb },
|
||||
{ 0x1cc, 0x1cb },
|
||||
{ 0x1f1, 0x1f2 },
|
||||
{ 0x1f3, 0x1f2 },
|
||||
{ 0x392, 0x3d0 },
|
||||
{ 0x395, 0x3f5 },
|
||||
{ 0x398, 0x3d1 },
|
||||
{ 0x398, 0x3f4 },
|
||||
{ 0x399, 0x345 },
|
||||
{ 0x399, 0x1fbe },
|
||||
{ 0x39a, 0x3f0 },
|
||||
{ 0x39c, 0xb5 },
|
||||
{ 0x3a0, 0x3d6 },
|
||||
{ 0x3a1, 0x3f1 },
|
||||
{ 0x3a3, 0x3c2 },
|
||||
{ 0x3a6, 0x3d5 },
|
||||
{ 0x3a9, 0x2126 },
|
||||
{ 0x3b2, 0x3d0 },
|
||||
{ 0x3b5, 0x3f5 },
|
||||
{ 0x3b8, 0x3d1 },
|
||||
{ 0x3b8, 0x3f4 },
|
||||
{ 0x3b9, 0x345 },
|
||||
{ 0x3b9, 0x1fbe },
|
||||
{ 0x3ba, 0x3f0 },
|
||||
{ 0x3bc, 0xb5 },
|
||||
{ 0x3c0, 0x3d6 },
|
||||
{ 0x3c1, 0x3f1 },
|
||||
{ 0x3c3, 0x3c2 },
|
||||
{ 0x3c6, 0x3d5 },
|
||||
{ 0x3c9, 0x2126 },
|
||||
{ 0x1e60, 0x1e9b },
|
||||
{ 0x1e61, 0x1e9b }
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeToken: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeToken* RangeToken::getCaseInsensitiveToken(TokenFactory* const tokFactory) {
|
||||
|
||||
if (fCaseIToken == 0 && tokFactory && fRanges) {
|
||||
|
||||
bool isNRange = (getTokenType() == T_NRANGE) ? true : false;
|
||||
RangeToken* lwrToken = tokFactory->createRange(isNRange);
|
||||
|
||||
#if XERCES_USE_TRANSCODER_ICU && ((U_ICU_VERSION_MAJOR_NUM > 2) || (U_ICU_VERSION_MAJOR_NUM == 2 && U_ICU_VERSION_MINOR_NUM >=4))
|
||||
UChar* rangeStr=(UChar*)fMemoryManager->allocate(40*fElemCount*sizeof(UChar));
|
||||
ArrayJanitor<UChar> janRange(rangeStr, fMemoryManager);
|
||||
int c=0;
|
||||
rangeStr[c++] = chOpenSquare;
|
||||
for (unsigned int i = 0; i < fElemCount - 1; i += 2) {
|
||||
XMLCh buffer[10];
|
||||
XMLSize_t len, j;
|
||||
|
||||
rangeStr[c++] = chBackSlash;
|
||||
rangeStr[c++] = chLatin_U;
|
||||
XMLString::binToText(fRanges[i], buffer, 10, 16, fMemoryManager);
|
||||
len = XMLString::stringLen(buffer);
|
||||
for(j=0;j<(8-len);j++)
|
||||
rangeStr[c++] = chDigit_0;
|
||||
XMLCh* p=buffer;
|
||||
while(*p)
|
||||
rangeStr[c++] = *p++;
|
||||
if(fRanges[i+1]!=fRanges[i])
|
||||
{
|
||||
rangeStr[c++] = chDash;
|
||||
rangeStr[c++] = chBackSlash;
|
||||
rangeStr[c++] = chLatin_U;
|
||||
XMLString::binToText(fRanges[i+1], buffer, 10, 16, fMemoryManager);
|
||||
len = XMLString::stringLen(buffer);
|
||||
for(j=0;j<(8-len);j++)
|
||||
rangeStr[c++] = chDigit_0;
|
||||
p=buffer;
|
||||
while(*p)
|
||||
rangeStr[c++] = *p++;
|
||||
}
|
||||
}
|
||||
rangeStr[c++] = chCloseSquare;
|
||||
rangeStr[c++] = chNull;
|
||||
UErrorCode ec=U_ZERO_ERROR;
|
||||
USet* range=uset_openPatternOptions(rangeStr, -1, USET_CASE_INSENSITIVE, &ec);
|
||||
if(range)
|
||||
{
|
||||
ec = U_ZERO_ERROR;
|
||||
uint32_t cbCount=uset_serialize(range, NULL, 0, &ec);
|
||||
uint16_t* buffer=(uint16_t*)fMemoryManager->allocate(cbCount*sizeof(uint16_t));
|
||||
ArrayJanitor<uint16_t> janSet(buffer, fMemoryManager);
|
||||
ec = U_ZERO_ERROR;
|
||||
uset_serialize(range, buffer, cbCount, &ec);
|
||||
USerializedSet serializedSet;
|
||||
uset_getSerializedSet(&serializedSet, buffer, cbCount);
|
||||
int32_t nSets=uset_getSerializedRangeCount(&serializedSet);
|
||||
for(int32_t i=0; i<nSets; i++)
|
||||
{
|
||||
UChar32 start, end;
|
||||
uset_getSerializedRange(&serializedSet, i, &start, &end);
|
||||
lwrToken->addRange(start, end);
|
||||
}
|
||||
// does this release the memory allocated by the set?
|
||||
uset_setSerializedToOne(&serializedSet, 32);
|
||||
uset_close(range);
|
||||
}
|
||||
#else
|
||||
unsigned int exceptIndex = 0;
|
||||
|
||||
for (unsigned int i = 0; i < fElemCount - 1; i += 2) {
|
||||
for (XMLInt32 ch = fRanges[i]; ch <= fRanges[i + 1]; ++ch) {
|
||||
#if XERCES_USE_TRANSCODER_ICU
|
||||
const XMLInt32 upperCh = u_toupper(ch);
|
||||
|
||||
if (upperCh != ch)
|
||||
{
|
||||
lwrToken->addRange(upperCh, upperCh);
|
||||
}
|
||||
|
||||
const XMLInt32 lowerCh = u_tolower(ch);
|
||||
|
||||
if (lowerCh != ch)
|
||||
{
|
||||
lwrToken->addRange(lowerCh, lowerCh);
|
||||
}
|
||||
|
||||
const XMLInt32 titleCh = u_totitle(ch);
|
||||
|
||||
if (titleCh != ch && titleCh != upperCh)
|
||||
{
|
||||
lwrToken->addRange(titleCh, titleCh);
|
||||
}
|
||||
#else
|
||||
if (ch >= chLatin_A && ch <= chLatin_Z)
|
||||
{
|
||||
ch += chLatin_a - chLatin_A;
|
||||
|
||||
lwrToken->addRange(ch, ch);
|
||||
}
|
||||
else if (ch >= chLatin_a && ch <= chLatin_z)
|
||||
{
|
||||
ch -= chLatin_a - chLatin_A;
|
||||
|
||||
lwrToken->addRange(ch, ch);
|
||||
}
|
||||
#endif
|
||||
|
||||
const unsigned int exceptionsSize =
|
||||
sizeof(s_exceptions) / sizeof(s_exceptions[0]);
|
||||
|
||||
// Add any exception chars. These are characters where the the
|
||||
// case mapping is not symmetric. (Unicode case mappings are not isomorphic...)
|
||||
while (exceptIndex < exceptionsSize)
|
||||
{
|
||||
if (s_exceptions[exceptIndex].baseChar < ch)
|
||||
{
|
||||
++exceptIndex;
|
||||
}
|
||||
else if (s_exceptions[exceptIndex].baseChar == ch)
|
||||
{
|
||||
const XMLInt32 matchingChar =
|
||||
s_exceptions[exceptIndex].matchingChar;
|
||||
|
||||
lwrToken->addRange(
|
||||
matchingChar,
|
||||
matchingChar);
|
||||
|
||||
++exceptIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lwrToken->mergeRanges(this);
|
||||
#endif
|
||||
lwrToken->compactRanges();
|
||||
lwrToken->createMap();
|
||||
|
||||
fCaseIToken = lwrToken;
|
||||
// TODO(dbertoni) This is a temporary hack until we can change the ABI.
|
||||
// See Jira issue XERCESC-1866 for more details.
|
||||
// Overload the fCaseIToken data member to be the case-insensitive token
|
||||
// that's caching the case-insensitive one. We need this because tokens
|
||||
// have varying lifetimes.
|
||||
fCaseIToken->setCaseInsensitiveToken(this);
|
||||
}
|
||||
|
||||
return fCaseIToken;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeToken: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeToken::setRangeValues(XMLInt32* const rangeValues, const unsigned int count)
|
||||
{
|
||||
if (fRanges) {
|
||||
|
||||
if (fMap) {
|
||||
fMemoryManager->deallocate(fMap);//delete [] fMap;
|
||||
fMap = 0;
|
||||
}
|
||||
|
||||
fElemCount = 0;
|
||||
fMemoryManager->deallocate(fRanges);//delete [] fRanges;
|
||||
fRanges = 0;
|
||||
}
|
||||
|
||||
fElemCount = fMaxCount = count;
|
||||
fRanges = rangeValues;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeToken: Range manipulation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeToken::addRange(const XMLInt32 start, const XMLInt32 end) {
|
||||
|
||||
XMLInt32 val1, val2;
|
||||
|
||||
fCaseIToken = 0;
|
||||
|
||||
if (start <= end) {
|
||||
|
||||
val1 = start;
|
||||
val2 = end;
|
||||
}
|
||||
else {
|
||||
|
||||
val1 = end;
|
||||
val2 = start;
|
||||
}
|
||||
|
||||
if (fRanges == 0) {
|
||||
|
||||
fRanges = (XMLInt32*) fMemoryManager->allocate
|
||||
(
|
||||
fMaxCount * sizeof(XMLInt32)
|
||||
);//new XMLInt32[fMaxCount];
|
||||
fRanges[0] = val1;
|
||||
fRanges[1] = val2;
|
||||
fElemCount = 2;
|
||||
fSorted = true;
|
||||
}
|
||||
else {
|
||||
|
||||
if (fRanges[fElemCount-1] + 1 == val1) {
|
||||
|
||||
fRanges[fElemCount-1] = val2;
|
||||
return;
|
||||
}
|
||||
|
||||
if (fElemCount + 2 >= fMaxCount) {
|
||||
expand(2);
|
||||
}
|
||||
|
||||
if(fSorted && fRanges[fElemCount-1] >= val1)
|
||||
{
|
||||
for (int i = 0; i < (int)fElemCount; i +=2)
|
||||
{
|
||||
// check if this range is already part of this one
|
||||
if (fRanges[i] <= val1 && fRanges[i+1] >= val2)
|
||||
break;
|
||||
// or if the new one extends the old one
|
||||
else if(fRanges[i]==val1 && fRanges[i+1] < val2)
|
||||
{
|
||||
fRanges[i+1]=val2;
|
||||
break;
|
||||
}
|
||||
else if (fRanges[i] > val1 ||
|
||||
(fRanges[i]==val1 && fRanges[i+1] > val2))
|
||||
{
|
||||
for(int j=fElemCount-1;j>=i;j--)
|
||||
fRanges[j+2]=fRanges[j];
|
||||
fRanges[i] = val1;
|
||||
fRanges[i+1] = val2;
|
||||
fElemCount += 2;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fRanges[fElemCount-1] >= val1)
|
||||
fSorted = false;
|
||||
|
||||
fRanges[fElemCount++] = val1;
|
||||
fRanges[fElemCount++] = val2;
|
||||
|
||||
if (!fSorted) {
|
||||
sortRanges();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RangeToken::sortRanges() {
|
||||
|
||||
if (fSorted || fRanges == 0)
|
||||
return;
|
||||
|
||||
for (int i = fElemCount - 4; i >= 0; i -= 2) {
|
||||
|
||||
for (int j = 0; j <= i; j +=2) {
|
||||
|
||||
if (fRanges[j] > fRanges[j + 2]
|
||||
|| (fRanges[j]==fRanges[j+2] && fRanges[j+1] > fRanges[j+3])) {
|
||||
|
||||
XMLInt32 tmpVal = fRanges[j+2];
|
||||
fRanges[j+2] = fRanges[j];
|
||||
fRanges[j] = tmpVal;
|
||||
tmpVal = fRanges[j+3];
|
||||
fRanges[j+3] = fRanges[j+1];
|
||||
fRanges[j+1] = tmpVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fSorted = true;
|
||||
}
|
||||
|
||||
void RangeToken::compactRanges() {
|
||||
|
||||
if (fCompacted || fRanges == 0 || fElemCount <= 2)
|
||||
return;
|
||||
|
||||
unsigned int base = 0;
|
||||
unsigned int target = 0;
|
||||
|
||||
while (target < fElemCount) {
|
||||
|
||||
if (base != target) {
|
||||
|
||||
fRanges[base] = fRanges[target++];
|
||||
fRanges[base+1] = fRanges[target++];
|
||||
}
|
||||
else
|
||||
target += 2;
|
||||
|
||||
XMLInt32 baseEnd = fRanges[base + 1];
|
||||
|
||||
while (target < fElemCount) {
|
||||
|
||||
XMLInt32 startRange = fRanges[target];
|
||||
|
||||
if (baseEnd + 1 < startRange)
|
||||
break;
|
||||
|
||||
XMLInt32 endRange = fRanges[target + 1];
|
||||
|
||||
if (baseEnd + 1 == startRange || baseEnd < endRange) {
|
||||
|
||||
baseEnd = endRange;
|
||||
fRanges[base+1] = baseEnd;
|
||||
target += 2;
|
||||
}
|
||||
else if (baseEnd >= endRange) {
|
||||
target += 2;
|
||||
}
|
||||
else {
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_CompactRangesError, fMemoryManager);
|
||||
}
|
||||
} // inner while
|
||||
|
||||
base += 2;
|
||||
}
|
||||
|
||||
fElemCount = base;
|
||||
fCompacted = true;
|
||||
}
|
||||
|
||||
void RangeToken::mergeRanges(const Token *const tok) {
|
||||
|
||||
|
||||
if (tok->getTokenType() != this->getTokenType())
|
||||
ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Regex_MergeRangesTypeMismatch, fMemoryManager);
|
||||
|
||||
RangeToken* rangeTok = (RangeToken *) tok;
|
||||
|
||||
if (rangeTok->fRanges == 0)
|
||||
return;
|
||||
|
||||
fCaseIToken = 0;
|
||||
sortRanges();
|
||||
rangeTok->sortRanges();
|
||||
|
||||
if (fRanges == 0) {
|
||||
|
||||
fMaxCount = rangeTok->fMaxCount;
|
||||
fRanges = (XMLInt32*) fMemoryManager->allocate
|
||||
(
|
||||
fMaxCount * sizeof(XMLInt32)
|
||||
);//new XMLInt32[fMaxCount];
|
||||
for (unsigned int index = 0; index < rangeTok->fElemCount; index++) {
|
||||
fRanges[index] = rangeTok->fRanges[index];
|
||||
}
|
||||
|
||||
fElemCount = rangeTok->fElemCount;
|
||||
fSorted = true;
|
||||
return;
|
||||
}
|
||||
|
||||
unsigned int newMaxCount = (fElemCount + rangeTok->fElemCount >= fMaxCount)
|
||||
? fMaxCount + rangeTok->fMaxCount : fMaxCount;
|
||||
XMLInt32* result = (XMLInt32*) fMemoryManager->allocate
|
||||
(
|
||||
newMaxCount * sizeof(XMLInt32)
|
||||
);//new XMLInt32[newMaxCount];
|
||||
|
||||
for (unsigned int i=0, j=0, k=0; i < fElemCount || j < rangeTok->fElemCount;) {
|
||||
|
||||
if (i >= fElemCount) {
|
||||
|
||||
for (int count = 0; count < 2; count++) {
|
||||
result[k++] = rangeTok->fRanges[j++];
|
||||
}
|
||||
}
|
||||
else if (j >= rangeTok->fElemCount) {
|
||||
|
||||
for (int count = 0; count < 2; count++) {
|
||||
result[k++] = fRanges[i++];
|
||||
}
|
||||
}
|
||||
else if (rangeTok->fRanges[j] < fRanges[i]
|
||||
|| (rangeTok->fRanges[j] == fRanges[i]
|
||||
&& rangeTok->fRanges[j+1] < fRanges[i+1])) {
|
||||
|
||||
for (int count = 0; count < 2; count++) {
|
||||
result[k++] = rangeTok->fRanges[j++];
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
for (int count = 0; count < 2; count++) {
|
||||
|
||||
result[k++] = fRanges[i++];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fMemoryManager->deallocate(fRanges);//delete [] fRanges;
|
||||
fElemCount += rangeTok->fElemCount;
|
||||
fRanges = result;
|
||||
fMaxCount = newMaxCount;
|
||||
}
|
||||
|
||||
void RangeToken::subtractRanges(RangeToken* const tok) {
|
||||
|
||||
if (fRanges == 0 || tok->fRanges == 0)
|
||||
return;
|
||||
|
||||
if (tok->getTokenType() == T_NRANGE) {
|
||||
|
||||
intersectRanges(tok);
|
||||
return;
|
||||
}
|
||||
|
||||
fCaseIToken = 0;
|
||||
sortRanges();
|
||||
compactRanges();
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
|
||||
unsigned int newMax = (fElemCount + tok->fElemCount >= fMaxCount)
|
||||
? fMaxCount + tok->fMaxCount : fMaxCount;
|
||||
XMLInt32* result = (XMLInt32*) fMemoryManager->allocate
|
||||
(
|
||||
newMax * sizeof(XMLInt32)
|
||||
);//new XMLInt32[newMax];
|
||||
unsigned int newElemCount = 0;
|
||||
unsigned int srcCount = 0;
|
||||
unsigned int subCount = 0;
|
||||
|
||||
while (srcCount < fElemCount && subCount < tok->fElemCount) {
|
||||
|
||||
XMLInt32 srcBegin = fRanges[srcCount];
|
||||
XMLInt32 srcEnd = fRanges[srcCount + 1];
|
||||
XMLInt32 subBegin = tok->fRanges[subCount];
|
||||
XMLInt32 subEnd = tok->fRanges[subCount + 1];
|
||||
|
||||
if (srcEnd < subBegin) { // no overlap
|
||||
|
||||
result[newElemCount++] = fRanges[srcCount++];
|
||||
result[newElemCount++] = fRanges[srcCount++];
|
||||
}
|
||||
else if (srcEnd >= subBegin && srcBegin <= subEnd) {
|
||||
|
||||
if (subBegin <= srcBegin && srcEnd <= subEnd) {
|
||||
srcCount += 2;
|
||||
}
|
||||
else if (subBegin <= srcBegin) {
|
||||
|
||||
fRanges[srcCount] = subEnd + 1;
|
||||
subCount += 2;
|
||||
}
|
||||
else if (srcEnd <= subEnd) {
|
||||
|
||||
result[newElemCount++] = srcBegin;
|
||||
result[newElemCount++] = subBegin - 1;
|
||||
srcCount += 2;
|
||||
}
|
||||
else {
|
||||
|
||||
result[newElemCount++] = srcBegin;
|
||||
result[newElemCount++] = subBegin - 1;
|
||||
fRanges[srcCount] = subEnd + 1;
|
||||
subCount += 2;
|
||||
}
|
||||
}
|
||||
else if (subEnd < srcBegin) {
|
||||
subCount += 2;
|
||||
}
|
||||
else {
|
||||
fMemoryManager->deallocate(result);//delete [] result;
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_SubtractRangesError, fMemoryManager);
|
||||
}
|
||||
} //end while
|
||||
|
||||
while (srcCount < fElemCount) {
|
||||
|
||||
result[newElemCount++] = fRanges[srcCount++];
|
||||
result[newElemCount++] = fRanges[srcCount++];
|
||||
}
|
||||
|
||||
fMemoryManager->deallocate(fRanges);//delete [] fRanges;
|
||||
fRanges = result;
|
||||
fElemCount = newElemCount;
|
||||
fMaxCount = newMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore whether 'tok' is NRANGE or not.
|
||||
*/
|
||||
void RangeToken::intersectRanges(RangeToken* const tok) {
|
||||
|
||||
if (fRanges == 0 || tok->fRanges == 0)
|
||||
return;
|
||||
|
||||
fCaseIToken = 0;
|
||||
sortRanges();
|
||||
compactRanges();
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
|
||||
unsigned int newMax = (fElemCount + tok->fElemCount >= fMaxCount)
|
||||
? fMaxCount + tok->fMaxCount : fMaxCount;
|
||||
XMLInt32* result = (XMLInt32*) fMemoryManager->allocate
|
||||
(
|
||||
newMax * sizeof(XMLInt32)
|
||||
);//new XMLInt32[newMax];
|
||||
unsigned int newElemCount = 0;
|
||||
unsigned int srcCount = 0;
|
||||
unsigned int tokCount = 0;
|
||||
|
||||
while (srcCount < fElemCount && tokCount < tok->fElemCount) {
|
||||
|
||||
XMLInt32 srcBegin = fRanges[srcCount];
|
||||
XMLInt32 srcEnd = fRanges[srcCount + 1];
|
||||
XMLInt32 tokBegin = tok->fRanges[tokCount];
|
||||
XMLInt32 tokEnd = tok->fRanges[tokCount + 1];
|
||||
|
||||
if (srcEnd < tokBegin) {
|
||||
srcCount += 2;
|
||||
}
|
||||
else if (srcEnd >= tokBegin && srcBegin <= tokEnd) {
|
||||
|
||||
if (tokBegin <= srcBegin && srcEnd <= tokEnd) {
|
||||
|
||||
result[newElemCount++] = srcBegin;
|
||||
result[newElemCount++] = srcEnd;
|
||||
srcCount += 2;
|
||||
}
|
||||
else if (tokBegin <= srcBegin) {
|
||||
|
||||
result[newElemCount++] = srcBegin;
|
||||
result[newElemCount++] = tokEnd;
|
||||
tokCount += 2;
|
||||
|
||||
if (tokCount < tok->fElemCount)
|
||||
fRanges[srcCount] = tokEnd + 1;
|
||||
else
|
||||
srcCount += 2;
|
||||
}
|
||||
else if (srcEnd <= tokEnd) {
|
||||
|
||||
result[newElemCount++] = tokBegin;
|
||||
result[newElemCount++] = srcEnd;
|
||||
srcCount += 2;
|
||||
}
|
||||
else {
|
||||
|
||||
result[newElemCount++] = tokBegin;
|
||||
result[newElemCount++] = tokEnd;
|
||||
tokCount += 2;
|
||||
|
||||
if (tokCount < tok->fElemCount)
|
||||
fRanges[srcCount] = tokEnd + 1;
|
||||
else
|
||||
srcCount += 2;
|
||||
}
|
||||
}
|
||||
else if (tokEnd < srcBegin) {
|
||||
tokCount += 2;
|
||||
|
||||
if (tokCount >= tok->fElemCount)
|
||||
srcCount += 2;
|
||||
}
|
||||
else {
|
||||
|
||||
fMemoryManager->deallocate(result);//delete [] result;
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_IntersectRangesError, fMemoryManager);
|
||||
}
|
||||
} //end while
|
||||
|
||||
fMemoryManager->deallocate(fRanges);//delete [] fRanges;
|
||||
fRanges = result;
|
||||
fElemCount = newElemCount;
|
||||
fMaxCount = newMax;
|
||||
}
|
||||
|
||||
/**
|
||||
* for RANGE: Creates complement.
|
||||
* for NRANGE: Creates the same meaning RANGE.
|
||||
*/
|
||||
RangeToken* RangeToken::complementRanges(RangeToken* const tok,
|
||||
TokenFactory* const tokFactory,
|
||||
MemoryManager* const manager) {
|
||||
|
||||
if (tok->getTokenType() != T_RANGE && tok->getTokenType() != T_NRANGE)
|
||||
ThrowXMLwithMemMgr(IllegalArgumentException, XMLExcepts::Regex_ComplementRangesInvalidArg, manager);
|
||||
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
|
||||
XMLInt32 lastElem = tok->fRanges[tok->fElemCount - 1];
|
||||
RangeToken* rangeTok = tokFactory->createRange();
|
||||
|
||||
if (tok->fRanges[0] > 0) {
|
||||
rangeTok->addRange(0, tok->fRanges[0] - 1);
|
||||
}
|
||||
|
||||
for (unsigned int i= 1; i< tok->fElemCount - 2; i += 2) {
|
||||
rangeTok->addRange(tok->fRanges[i] + 1, tok->fRanges[i+1] - 1);
|
||||
}
|
||||
|
||||
if (lastElem != UTF16_MAX) {
|
||||
rangeTok->addRange(lastElem + 1, UTF16_MAX);
|
||||
}
|
||||
|
||||
rangeTok->fCompacted = true;
|
||||
|
||||
return rangeTok;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeToken: Match methods
|
||||
// ---------------------------------------------------------------------------
|
||||
bool RangeToken::match(const XMLInt32 ch) {
|
||||
|
||||
createMap();
|
||||
|
||||
bool ret;
|
||||
|
||||
if (getTokenType() == T_RANGE) {
|
||||
|
||||
if (ch < MAPSIZE)
|
||||
return ((fMap[ch/32] & (1<<(ch&0x1f))) != 0);
|
||||
|
||||
ret = false;
|
||||
|
||||
for (unsigned int i= fNonMapIndex; i< fElemCount; i +=2) {
|
||||
|
||||
if (fRanges[i] <= ch && ch <= fRanges[i+1])
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
if (ch < MAPSIZE)
|
||||
return ((fMap[ch/32] & (1<<(ch&0x1f))) == 0);
|
||||
|
||||
ret = true;
|
||||
|
||||
for (unsigned int i= fNonMapIndex; i< fElemCount; i += 2) {
|
||||
|
||||
if (fRanges[i] <= ch && ch <= fRanges[i+1])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeToken: Private helpers methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeToken::expand(const unsigned int length) {
|
||||
|
||||
unsigned int newMax = fElemCount + length;
|
||||
|
||||
// Avoid too many reallocations by expanding by a percentage
|
||||
unsigned int minNewMax = (unsigned int)((double)fElemCount * 1.25);
|
||||
if (newMax < minNewMax)
|
||||
newMax = minNewMax;
|
||||
|
||||
XMLInt32* newList = (XMLInt32*) fMemoryManager->allocate
|
||||
(
|
||||
newMax * sizeof(XMLInt32)
|
||||
);//new XMLInt32[newMax];
|
||||
for (unsigned int index = 0; index < fElemCount; index++)
|
||||
newList[index] = fRanges[index];
|
||||
|
||||
fMemoryManager->deallocate(fRanges);//delete [] fRanges;
|
||||
fRanges = newList;
|
||||
fMaxCount = newMax;
|
||||
}
|
||||
|
||||
void RangeToken::doCreateMap() {
|
||||
|
||||
assert(!fMap);
|
||||
|
||||
int asize = MAPSIZE/32;
|
||||
fMap = (int*) fMemoryManager->allocate(asize * sizeof(int));//new int[asize];
|
||||
fNonMapIndex = fElemCount;
|
||||
|
||||
for (int i = 0; i < asize; i++) {
|
||||
fMap[i] = 0;
|
||||
}
|
||||
|
||||
for (unsigned int j= 0; j < fElemCount; j += 2) {
|
||||
|
||||
XMLInt32 begin = fRanges[j];
|
||||
XMLInt32 end = fRanges[j+1];
|
||||
|
||||
if (begin < MAPSIZE) {
|
||||
|
||||
for (int k = begin; k <= end && k < MAPSIZE; k++) {
|
||||
fMap[k/32] |= 1<<(k&0x1F);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
fNonMapIndex = j;
|
||||
break;
|
||||
}
|
||||
|
||||
if (end >= MAPSIZE) {
|
||||
|
||||
fNonMapIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file RangeToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RangeToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_RANGETOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_RANGETOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class TokenFactory;
|
||||
|
||||
|
||||
class XMLUTIL_EXPORT RangeToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
RangeToken(const tokType tkType,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~RangeToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constants
|
||||
// -----------------------------------------------------------------------
|
||||
static const int MAPSIZE;
|
||||
static const unsigned int INITIALSIZE;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
RangeToken* getCaseInsensitiveToken(TokenFactory* const tokFactory);
|
||||
|
||||
void setCaseInsensitiveToken(RangeToken* tok);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setRangeValues(XMLInt32* const rangeValues, const unsigned int count);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Range manipulation methods
|
||||
// -----------------------------------------------------------------------
|
||||
void addRange(const XMLInt32 start, const XMLInt32 end);
|
||||
void mergeRanges(const Token *const tok);
|
||||
void sortRanges();
|
||||
void compactRanges();
|
||||
void subtractRanges(RangeToken* const tok);
|
||||
void intersectRanges(RangeToken* const tok);
|
||||
static RangeToken* complementRanges(RangeToken* const tok,
|
||||
TokenFactory* const tokFactory,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
bool empty() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Match methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool match(const XMLInt32 ch);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Creates the map. This will happen automatically,
|
||||
// necessary.
|
||||
// -----------------------------------------------------------------------
|
||||
void createMap();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RangeToken(const RangeToken&);
|
||||
RangeToken& operator=(const RangeToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void expand(const unsigned int length);
|
||||
|
||||
void doCreateMap();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
bool fSorted;
|
||||
bool fCompacted;
|
||||
int fNonMapIndex;
|
||||
unsigned int fElemCount;
|
||||
unsigned int fMaxCount;
|
||||
int* fMap;
|
||||
XMLInt32* fRanges;
|
||||
RangeToken* fCaseIToken;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
inline void RangeToken::setCaseInsensitiveToken(RangeToken* tok)
|
||||
{
|
||||
fCaseIToken = tok;
|
||||
}
|
||||
|
||||
inline void RangeToken::createMap()
|
||||
{
|
||||
if (!fMap)
|
||||
{
|
||||
doCreateMap();
|
||||
}
|
||||
}
|
||||
|
||||
inline bool RangeToken::empty() const
|
||||
{
|
||||
return fElemCount==0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file RangeToken.hpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RangeTokenMap.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeTokenMap.hpp>
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/XMLRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/ASCIIRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/UnicodeRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/BlockRangeFactory.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
#include <xercesc/util/XMLExceptMsgs.hpp>
|
||||
#include <xercesc/util/StringPool.hpp>
|
||||
#include <xercesc/util/XMLInitializer.hpp>
|
||||
#include <xercesc/util/OutOfMemoryException.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
RangeTokenMap* RangeTokenMap::fInstance = 0;
|
||||
|
||||
void XMLInitializer::initializeRangeTokenMap()
|
||||
{
|
||||
RangeTokenMap::fInstance = new RangeTokenMap(
|
||||
XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
if (RangeTokenMap::fInstance)
|
||||
RangeTokenMap::fInstance->buildTokenRanges();
|
||||
}
|
||||
|
||||
void XMLInitializer::terminateRangeTokenMap()
|
||||
{
|
||||
delete RangeTokenMap::fInstance;
|
||||
RangeTokenMap::fInstance = 0;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenElemMap: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeTokenElemMap::RangeTokenElemMap(unsigned int categoryId) :
|
||||
fCategoryId(categoryId)
|
||||
, fRange(0)
|
||||
, fNRange(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
RangeTokenElemMap::~RangeTokenElemMap()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
typedef JanitorMemFunCall<RangeTokenMap> CleanupType;
|
||||
|
||||
RangeTokenMap::RangeTokenMap(MemoryManager* manager) :
|
||||
fTokenRegistry(0)
|
||||
, fRangeMap(0)
|
||||
, fCategories(0)
|
||||
, fTokenFactory(0)
|
||||
, fMutex(manager)
|
||||
{
|
||||
CleanupType cleanup(this, &RangeTokenMap::cleanUp);
|
||||
|
||||
try {
|
||||
fTokenRegistry = new (manager) RefHashTableOf<RangeTokenElemMap>(109, manager);
|
||||
fRangeMap = new (manager) RefHashTableOf<RangeFactory>(29, manager);
|
||||
fCategories = new (manager) XMLStringPool(109, manager);
|
||||
fTokenFactory = new (manager) TokenFactory(manager);
|
||||
initializeRegistry();
|
||||
}
|
||||
catch(const OutOfMemoryException&)
|
||||
{
|
||||
cleanup.release();
|
||||
|
||||
throw;
|
||||
}
|
||||
|
||||
cleanup.release();
|
||||
}
|
||||
|
||||
RangeTokenMap::~RangeTokenMap() {
|
||||
|
||||
cleanUp();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeToken* RangeTokenMap::getRange(const XMLCh* const keyword,
|
||||
const bool complement) {
|
||||
|
||||
if (!fTokenRegistry->containsKey(keyword))
|
||||
return 0;
|
||||
|
||||
RangeTokenElemMap* elemMap = fTokenRegistry->get(keyword);
|
||||
RangeToken* rangeTok = elemMap->getRangeToken(complement);
|
||||
|
||||
if (!rangeTok)
|
||||
{
|
||||
XMLMutexLock lockInit(&fMutex);
|
||||
|
||||
// make sure that it was not created while we were locked
|
||||
rangeTok = elemMap->getRangeToken(complement);
|
||||
|
||||
if (!rangeTok)
|
||||
{
|
||||
unsigned int categId = elemMap->getCategoryId();
|
||||
const XMLCh* categName = fCategories->getValueForId(categId);
|
||||
RangeFactory* rangeFactory = fRangeMap->get(categName);
|
||||
|
||||
if (rangeFactory)
|
||||
{
|
||||
rangeFactory->buildRanges(this);
|
||||
rangeTok = elemMap->getRangeToken(complement);
|
||||
|
||||
// see if we are complementing an existing range
|
||||
if (!rangeTok && complement)
|
||||
{
|
||||
rangeTok = elemMap->getRangeToken();
|
||||
if (rangeTok)
|
||||
{
|
||||
rangeTok = RangeToken::complementRanges(rangeTok, fTokenFactory, fTokenRegistry->getMemoryManager());
|
||||
elemMap->setRangeToken(rangeTok , complement);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rangeTok;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Putter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeTokenMap::addCategory(const XMLCh* const categoryName) {
|
||||
|
||||
fCategories->addOrFind(categoryName);
|
||||
}
|
||||
|
||||
void RangeTokenMap::addRangeMap(const XMLCh* const categoryName,
|
||||
RangeFactory* const rangeFactory) {
|
||||
|
||||
fRangeMap->put((void*)categoryName, rangeFactory);
|
||||
}
|
||||
|
||||
void RangeTokenMap::addKeywordMap(const XMLCh* const keyword,
|
||||
const XMLCh* const categoryName) {
|
||||
|
||||
unsigned int categId = fCategories->getId(categoryName);
|
||||
|
||||
if (categId == 0) {
|
||||
ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Regex_InvalidCategoryName, categoryName, fTokenRegistry->getMemoryManager());
|
||||
}
|
||||
|
||||
if (fTokenRegistry->containsKey(keyword)) {
|
||||
|
||||
RangeTokenElemMap* elemMap = fTokenRegistry->get(keyword);
|
||||
|
||||
if (elemMap->getCategoryId() != categId)
|
||||
elemMap->setCategoryId(categId);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
fTokenRegistry->put((void*) keyword, new RangeTokenElemMap(categId));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeTokenMap::setRangeToken(const XMLCh* const keyword,
|
||||
RangeToken* const tok,const bool complement) {
|
||||
|
||||
if (fTokenRegistry->containsKey(keyword)) {
|
||||
fTokenRegistry->get(keyword)->setRangeToken(tok, complement);
|
||||
}
|
||||
else {
|
||||
ThrowXMLwithMemMgr1(RuntimeException, XMLExcepts::Regex_KeywordNotFound, keyword, fTokenRegistry->getMemoryManager());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Initialization methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeTokenMap::initializeRegistry() {
|
||||
|
||||
// Add categories
|
||||
fCategories->addOrFind(fgXMLCategory);
|
||||
fCategories->addOrFind(fgASCIICategory);
|
||||
fCategories->addOrFind(fgUnicodeCategory);
|
||||
fCategories->addOrFind(fgBlockCategory);
|
||||
|
||||
// Add xml range factory
|
||||
RangeFactory* rangeFact = new XMLRangeFactory();
|
||||
fRangeMap->put((void*)fgXMLCategory, rangeFact);
|
||||
rangeFact->initializeKeywordMap(this);
|
||||
|
||||
// Add ascii range factory
|
||||
rangeFact = new ASCIIRangeFactory();
|
||||
fRangeMap->put((void*)fgASCIICategory, rangeFact);
|
||||
rangeFact->initializeKeywordMap(this);
|
||||
|
||||
// Add unicode range factory
|
||||
rangeFact = new UnicodeRangeFactory();
|
||||
fRangeMap->put((void*)fgUnicodeCategory, rangeFact);
|
||||
rangeFact->initializeKeywordMap(this);
|
||||
|
||||
// Add block range factory
|
||||
rangeFact = new BlockRangeFactory();
|
||||
fRangeMap->put((void*)fgBlockCategory, rangeFact);
|
||||
rangeFact->initializeKeywordMap(this);
|
||||
}
|
||||
|
||||
void RangeTokenMap::buildTokenRanges()
|
||||
{
|
||||
// Build ranges */
|
||||
RangeFactory* rangeFactory = fRangeMap->get(fgXMLCategory);
|
||||
rangeFactory->buildRanges(this);
|
||||
|
||||
rangeFactory = fRangeMap->get(fgASCIICategory);
|
||||
rangeFactory->buildRanges(this);
|
||||
|
||||
rangeFactory = fRangeMap->get(fgUnicodeCategory);
|
||||
rangeFactory->buildRanges(this);
|
||||
|
||||
rangeFactory = fRangeMap->get(fgBlockCategory);
|
||||
rangeFactory->buildRanges(this);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Instance methods
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeTokenMap* RangeTokenMap::instance()
|
||||
{
|
||||
return fInstance;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void RangeTokenMap::cleanUp()
|
||||
{
|
||||
delete fTokenRegistry;
|
||||
fTokenRegistry = 0;
|
||||
|
||||
delete fRangeMap;
|
||||
fRangeMap = 0;
|
||||
|
||||
delete fCategories;
|
||||
fCategories = 0;
|
||||
|
||||
delete fTokenFactory;
|
||||
fTokenFactory = 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file RangeTokenMap.cpp
|
||||
*/
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RangeTokenMap.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_RANGETOKENMAP_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_RANGETOKENMAP_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/Mutexes.hpp>
|
||||
#include <xercesc/util/RefHashTableOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class RangeToken;
|
||||
class RangeFactory;
|
||||
class TokenFactory;
|
||||
class XMLStringPool;
|
||||
|
||||
class XMLUTIL_EXPORT RangeTokenElemMap : public XMemory
|
||||
{
|
||||
|
||||
public:
|
||||
RangeTokenElemMap(unsigned int categoryId);
|
||||
~RangeTokenElemMap();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
unsigned int getCategoryId() const;
|
||||
RangeToken* getRangeToken(const bool complement = false) const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setRangeToken(RangeToken* const tok, const bool complement = false);
|
||||
void setCategoryId(const unsigned int categId);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RangeTokenElemMap(const RangeTokenElemMap&);
|
||||
RangeTokenElemMap& operator=(const RangeTokenElemMap&);
|
||||
|
||||
// Data members
|
||||
unsigned int fCategoryId;
|
||||
RangeToken* fRange;
|
||||
RangeToken* fNRange;
|
||||
};
|
||||
|
||||
|
||||
class XMLUTIL_EXPORT RangeTokenMap : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Putter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void addCategory(const XMLCh* const categoryName);
|
||||
void addRangeMap(const XMLCh* const categoryName,
|
||||
RangeFactory* const rangeFactory);
|
||||
void addKeywordMap(const XMLCh* const keyword,
|
||||
const XMLCh* const categoryName);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Instance methods
|
||||
// -----------------------------------------------------------------------
|
||||
static RangeTokenMap* instance();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setRangeToken(const XMLCh* const keyword, RangeToken* const tok,
|
||||
const bool complement = false);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
TokenFactory* getTokenFactory() const;
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructor and destructors
|
||||
// -----------------------------------------------------------------------
|
||||
RangeTokenMap(MemoryManager* manager);
|
||||
~RangeTokenMap();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
/*
|
||||
* Gets a commonly used RangeToken from the token registry based on the
|
||||
* range name - Called by TokenFactory.
|
||||
*/
|
||||
RangeToken* getRange(const XMLCh* const name,
|
||||
const bool complement = false);
|
||||
|
||||
RefHashTableOf<RangeTokenElemMap>* getTokenRegistry() const;
|
||||
RefHashTableOf<RangeFactory>* getRangeMap() const;
|
||||
XMLStringPool* getCategories() const;
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RangeTokenMap(const RangeTokenMap&);
|
||||
RangeTokenMap& operator=(const RangeTokenMap&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helpers methods
|
||||
// -----------------------------------------------------------------------
|
||||
/*
|
||||
* Initializes the registry with a set of commonly used RangeToken
|
||||
* objects.
|
||||
*/
|
||||
void initializeRegistry();
|
||||
void buildTokenRanges();
|
||||
void cleanUp();
|
||||
friend class TokenFactory;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fTokenRegistry
|
||||
// Contains a set of commonly used tokens
|
||||
//
|
||||
// fRangeMap
|
||||
// Contains a map between a category name and a RangeFactory object.
|
||||
//
|
||||
// fCategories
|
||||
// Contains range categories names
|
||||
//
|
||||
// fTokenFactory
|
||||
// Token factory object
|
||||
//
|
||||
// fInstance
|
||||
// A RangeTokenMap instance
|
||||
//
|
||||
// fMutex
|
||||
// A mutex object for synchronization
|
||||
// -----------------------------------------------------------------------
|
||||
RefHashTableOf<RangeTokenElemMap>* fTokenRegistry;
|
||||
RefHashTableOf<RangeFactory>* fRangeMap;
|
||||
XMLStringPool* fCategories;
|
||||
TokenFactory* fTokenFactory;
|
||||
XMLMutex fMutex;
|
||||
static RangeTokenMap* fInstance;
|
||||
|
||||
friend class XMLInitializer;
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenElemMap: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline unsigned int RangeTokenElemMap::getCategoryId() const {
|
||||
|
||||
return fCategoryId;
|
||||
}
|
||||
|
||||
inline RangeToken* RangeTokenElemMap::getRangeToken(const bool complement) const {
|
||||
|
||||
return complement ? fNRange : fRange;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenElemMap: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void RangeTokenElemMap::setCategoryId(const unsigned int categId) {
|
||||
|
||||
fCategoryId = categId;
|
||||
}
|
||||
|
||||
inline void RangeTokenElemMap::setRangeToken(RangeToken* const tok,
|
||||
const bool complement) {
|
||||
|
||||
if (complement)
|
||||
fNRange = tok;
|
||||
else
|
||||
fRange = tok;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RangeTokenMap: Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline RefHashTableOf<RangeTokenElemMap>* RangeTokenMap::getTokenRegistry() const {
|
||||
|
||||
return fTokenRegistry;
|
||||
}
|
||||
|
||||
inline RefHashTableOf<RangeFactory>* RangeTokenMap::getRangeMap() const {
|
||||
|
||||
return fRangeMap;
|
||||
}
|
||||
|
||||
inline XMLStringPool* RangeTokenMap::getCategories() const {
|
||||
|
||||
return fCategories;
|
||||
}
|
||||
|
||||
inline TokenFactory* RangeTokenMap::getTokenFactory() const {
|
||||
|
||||
return fTokenFactory;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file RangeToken.hpp
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,772 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RegularExpression.hpp 822158 2009-10-06 07:52:59Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_REGULAREXPRESSION_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_REGULAREXPRESSION_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/RefArrayVectorOf.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/Janitor.hpp>
|
||||
#include <xercesc/util/regx/Op.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/BMPattern.hpp>
|
||||
#include <xercesc/util/regx/OpFactory.hpp>
|
||||
#include <xercesc/util/regx/RegxUtil.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class RangeToken;
|
||||
class Match;
|
||||
class RegxParser;
|
||||
|
||||
/**
|
||||
* The RegularExpression class represents a parsed executable regular expression.
|
||||
* This class is thread safe. Two similar regular expression syntaxes are
|
||||
* supported:
|
||||
*
|
||||
* <ol>
|
||||
* <li><a href="http://www.w3.org/TR/xpath-functions/#regex-syntax">The XPath 2.0 / XQuery regular expression syntax.</a>
|
||||
* <li><a href="http://www.w3.org/TR/xmlschema-2/#regexs">The XML Schema regular expression syntax.</a></li>
|
||||
* </ol>
|
||||
*
|
||||
* XPath 2.0 regular expression syntax is used unless the "X" option is specified during construction.
|
||||
*
|
||||
* Options can be specified during construction to change the way that the regular expression is handled.
|
||||
* Options are specified by a string consisting of any number of the following characters:
|
||||
*
|
||||
* <table border='1'>
|
||||
* <tr>
|
||||
* <th>Character</th>
|
||||
* <th>Meaning</th>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>i</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'><a href="http://www.w3.org/TR/xpath-functions/#flags">
|
||||
* Ignore case</a> when matching the regular expression.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>m</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'><a href="http://www.w3.org/TR/xpath-functions/#flags">
|
||||
* Multi-line mode</a>. The meta characters "^" and "$" will match the beginning and end of lines.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>s</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'><a href="http://www.w3.org/TR/xpath-functions/#flags">
|
||||
* Single-line mode</a>. The meta character "." will match a newline character.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>x</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>Allow extended comments.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>F</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>Prohibit the fixed string optimization.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>H</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>Prohibit the head character optimization.</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td valign='top' rowspan='1' colspan='1'>X</td>
|
||||
* <td valign='top' rowspan='1' colspan='1'>Parse the regular expression according to the
|
||||
* <a href="http://www.w3.org/TR/xmlschema-2/#regexs">XML Schema regular expression syntax</a>.</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*/
|
||||
class XMLUTIL_EXPORT RegularExpression : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Constructors and destructor */
|
||||
//@{
|
||||
|
||||
/** Parses the given regular expression.
|
||||
*
|
||||
* @param pattern the regular expression in the local code page
|
||||
* @param manager the memory manager to use
|
||||
*/
|
||||
RegularExpression
|
||||
(
|
||||
const char* const pattern
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/** Parses the given regular expression using the options specified.
|
||||
*
|
||||
* @param pattern the regular expression in the local code page
|
||||
* @param options the options string in the local code page
|
||||
* @param manager the memory manager to use
|
||||
*/
|
||||
RegularExpression
|
||||
(
|
||||
const char* const pattern
|
||||
, const char* const options
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/** Parses the given regular expression.
|
||||
*
|
||||
* @param pattern the regular expression
|
||||
* @param manager the memory manager to use
|
||||
*/
|
||||
RegularExpression
|
||||
(
|
||||
const XMLCh* const pattern
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
/** Parses the given regular expression using the options specified.
|
||||
*
|
||||
* @param pattern the regular expression
|
||||
* @param options the options string
|
||||
* @param manager the memory manager to use
|
||||
*/
|
||||
RegularExpression
|
||||
(
|
||||
const XMLCh* const pattern
|
||||
, const XMLCh* const options
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
|
||||
virtual ~RegularExpression();
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constants
|
||||
// -----------------------------------------------------------------------
|
||||
static const unsigned int IGNORE_CASE;
|
||||
static const unsigned int SINGLE_LINE;
|
||||
static const unsigned int MULTIPLE_LINE;
|
||||
static const unsigned int EXTENDED_COMMENT;
|
||||
static const unsigned int PROHIBIT_HEAD_CHARACTER_OPTIMIZATION;
|
||||
static const unsigned int PROHIBIT_FIXED_STRING_OPTIMIZATION;
|
||||
static const unsigned int XMLSCHEMA_MODE;
|
||||
typedef enum
|
||||
{
|
||||
wordTypeIgnore = 0,
|
||||
wordTypeLetter = 1,
|
||||
wordTypeOther = 2
|
||||
} wordType;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Public helper methods */
|
||||
//@{
|
||||
|
||||
static int getOptionValue(const XMLCh ch);
|
||||
static bool isSet(const int options, const int flag);
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Matching methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Matching methods */
|
||||
//@{
|
||||
|
||||
/** Tries to match the given null terminated string against the regular expression, returning
|
||||
* true if successful.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const char* const matchString,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given string between the specified start and end offsets
|
||||
* against the regular expression, returning true if successful.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const char* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given null terminated string against the regular expression, returning
|
||||
* true if successful.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param pMatch a Match object, which will be populated with the offsets for the
|
||||
* regular expression match and sub-matches.
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const char* const matchString, Match* const pMatch,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given string between the specified start and end offsets
|
||||
* against the regular expression, returning true if successful.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param pMatch a Match object, which will be populated with the offsets for the
|
||||
* regular expression match and sub-matches.
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const char* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given null terminated string against the regular expression, returning
|
||||
* true if successful.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const XMLCh* const matchString,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given string between the specified start and end offsets
|
||||
* against the regular expression, returning true if successful.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const XMLCh* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given null terminated string against the regular expression, returning
|
||||
* true if successful.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param pMatch a Match object, which will be populated with the offsets for the
|
||||
* regular expression match and sub-matches.
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const XMLCh* const matchString, Match* const pMatch,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given string between the specified start and end offsets
|
||||
* against the regular expression, returning true if successful.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param pMatch a Match object, which will be populated with the offsets for the
|
||||
* regular expression match and sub-matches.
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return Whether the string matched the regular expression or not.
|
||||
*/
|
||||
bool matches(const XMLCh* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
Match* const pMatch, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tries to match the given string between the specified start and end offsets
|
||||
* against the regular expression. The subEx vector is populated with the details
|
||||
* for every non-overlapping occurrence of a match in the string.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param subEx a RefVectorOf Match objects, populated with the offsets for the
|
||||
* regular expression match and sub-matches.
|
||||
* @param manager the memory manager to use
|
||||
*/
|
||||
void allMatches(const XMLCh* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
RefVectorOf<Match> *subEx, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Tokenize methods
|
||||
// -----------------------------------------------------------------------
|
||||
// Note: The caller owns the string vector that is returned, and is responsible
|
||||
// for deleting it.
|
||||
|
||||
/** @name Tokenize methods */
|
||||
//@{
|
||||
|
||||
/** Tokenizes the null terminated string according to the regular expression, returning
|
||||
* the parts of the string that do not match the regular expression.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return A RefArrayVectorOf sub-strings that do not match the regular expression allocated using the
|
||||
* given MemoryManager. The caller owns the string vector that is returned, and is responsible for
|
||||
* deleting it.
|
||||
*/
|
||||
RefArrayVectorOf<XMLCh> *tokenize(const char* const matchString,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tokenizes the string between the specified start and end offsets according to the regular
|
||||
* expression, returning the parts of the string that do not match the regular expression.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return A RefArrayVectorOf sub-strings that do not match the regular expression allocated using the
|
||||
* given MemoryManager. The caller owns the string vector that is returned, and is responsible for
|
||||
* deleting it.
|
||||
*/
|
||||
RefArrayVectorOf<XMLCh> *tokenize(const char* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tokenizes the null terminated string according to the regular expression, returning
|
||||
* the parts of the string that do not match the regular expression.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return A RefArrayVectorOf sub-strings that do not match the regular expression allocated using the
|
||||
* given MemoryManager. The caller owns the string vector that is returned, and is responsible for
|
||||
* deleting it.
|
||||
*/
|
||||
RefArrayVectorOf<XMLCh> *tokenize(const XMLCh* const matchString,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Tokenizes the string between the specified start and end offsets according to the regular
|
||||
* expression, returning the parts of the string that do not match the regular expression.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return A RefArrayVectorOf sub-strings that do not match the regular expression allocated using the
|
||||
* given MemoryManager. The caller owns the string vector that is returned, and is responsible for
|
||||
* deleting it.
|
||||
*/
|
||||
RefArrayVectorOf<XMLCh> *tokenize(const XMLCh* const matchString, const XMLSize_t start, const XMLSize_t end,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Replace methods
|
||||
// -----------------------------------------------------------------------
|
||||
// Note: The caller owns the XMLCh* that is returned, and is responsible for
|
||||
// deleting it.
|
||||
|
||||
/** @name Replace methods */
|
||||
//@{
|
||||
|
||||
/** Performs a search and replace on the given null terminated string, replacing
|
||||
* any substring that matches the regular expression with a string derived from
|
||||
* the <a href="http://www.w3.org/TR/xpath-functions/#func-replace">replacement string</a>.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param replaceString the string to replace in the local code page
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return The resulting string allocated using the given MemoryManager. The caller owns the string
|
||||
* that is returned, and is responsible for deleting it.
|
||||
*/
|
||||
XMLCh *replace(const char* const matchString, const char* const replaceString,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Performs a search and replace on the given string between the specified start and end offsets, replacing
|
||||
* any substring that matches the regular expression with a string derived from
|
||||
* the <a href="http://www.w3.org/TR/xpath-functions/#func-replace">replacement string</a>.
|
||||
*
|
||||
* @param matchString the string to match in the local code page
|
||||
* @param replaceString the string to replace in the local code page
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return The resulting string allocated using the given MemoryManager. The caller owns the string
|
||||
* that is returned, and is responsible for deleting it.
|
||||
*/
|
||||
XMLCh *replace(const char* const matchString, const char* const replaceString,
|
||||
const XMLSize_t start, const XMLSize_t end,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Performs a search and replace on the given null terminated string, replacing
|
||||
* any substring that matches the regular expression with a string derived from
|
||||
* the <a href="http://www.w3.org/TR/xpath-functions/#func-replace">replacement string</a>.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param replaceString the string to replace
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return The resulting string allocated using the given MemoryManager. The caller owns the string
|
||||
* that is returned, and is responsible for deleting it.
|
||||
*/
|
||||
XMLCh *replace(const XMLCh* const matchString, const XMLCh* const replaceString,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
/** Performs a search and replace on the given string between the specified start and end offsets, replacing
|
||||
* any substring that matches the regular expression with a string derived from
|
||||
* the <a href="http://www.w3.org/TR/xpath-functions/#func-replace">replacement string</a>.
|
||||
*
|
||||
* @param matchString the string to match
|
||||
* @param replaceString the string to replace
|
||||
* @param start the offset of the start of the string
|
||||
* @param end the offset of the end of the string
|
||||
* @param manager the memory manager to use
|
||||
*
|
||||
* @return The resulting string allocated using the given MemoryManager. The caller owns the string
|
||||
* that is returned, and is responsible for deleting it.
|
||||
*/
|
||||
XMLCh *replace(const XMLCh* const matchString, const XMLCh* const replaceString,
|
||||
const XMLSize_t start, const XMLSize_t end,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager) const;
|
||||
|
||||
//@}
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Static initialize and cleanup methods
|
||||
// -----------------------------------------------------------------------
|
||||
|
||||
/** @name Static initilize and cleanup methods */
|
||||
//@{
|
||||
|
||||
static void
|
||||
staticInitialize(MemoryManager* memoryManager);
|
||||
|
||||
static void
|
||||
staticCleanup();
|
||||
|
||||
//@}
|
||||
|
||||
protected:
|
||||
virtual RegxParser* getRegexParser(const int options, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Cleanup methods
|
||||
// -----------------------------------------------------------------------
|
||||
void cleanUp();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setPattern(const XMLCh* const pattern, const XMLCh* const options=0);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected data types
|
||||
// -----------------------------------------------------------------------
|
||||
class XMLUTIL_EXPORT Context : public XMemory
|
||||
{
|
||||
public :
|
||||
Context(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
Context(Context* src);
|
||||
~Context();
|
||||
|
||||
Context& operator= (const Context& other);
|
||||
inline const XMLCh* getString() const { return fString; }
|
||||
void reset(const XMLCh* const string, const XMLSize_t stringLen,
|
||||
const XMLSize_t start, const XMLSize_t limit, const int noClosures,
|
||||
const unsigned int options);
|
||||
bool nextCh(XMLInt32& ch, XMLSize_t& offset);
|
||||
|
||||
bool fAdoptMatch;
|
||||
XMLSize_t fStart;
|
||||
XMLSize_t fLimit;
|
||||
XMLSize_t fLength; // fLimit - fStart
|
||||
int fSize;
|
||||
XMLSize_t fStringMaxLen;
|
||||
int* fOffsets;
|
||||
Match* fMatch;
|
||||
const XMLCh* fString;
|
||||
unsigned int fOptions;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RegularExpression(const RegularExpression&);
|
||||
RegularExpression& operator=(const RegularExpression&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void prepare();
|
||||
int parseOptions(const XMLCh* const options);
|
||||
|
||||
/**
|
||||
* Matching helpers
|
||||
*/
|
||||
int match(Context* const context, const Op* const operations, XMLSize_t offset) const;
|
||||
bool matchIgnoreCase(const XMLInt32 ch1, const XMLInt32 ch2) const;
|
||||
|
||||
/**
|
||||
* Helper methods used by match(Context* ...)
|
||||
*/
|
||||
bool matchChar(Context* const context, const XMLInt32 ch, XMLSize_t& offset,
|
||||
const bool ignoreCase) const;
|
||||
bool matchDot(Context* const context, XMLSize_t& offset) const;
|
||||
bool matchRange(Context* const context, const Op* const op,
|
||||
XMLSize_t& offset, const bool ignoreCase) const;
|
||||
bool matchAnchor(Context* const context, const XMLInt32 ch,
|
||||
const XMLSize_t offset) const;
|
||||
bool matchBackReference(Context* const context, const XMLInt32 ch,
|
||||
XMLSize_t& offset, const bool ignoreCase) const;
|
||||
bool matchString(Context* const context, const XMLCh* const literal,
|
||||
XMLSize_t& offset, const bool ignoreCase) const;
|
||||
int matchUnion(Context* const context, const Op* const op, XMLSize_t offset) const;
|
||||
int matchCapture(Context* const context, const Op* const op, XMLSize_t offset) const;
|
||||
|
||||
/**
|
||||
* Replace helpers
|
||||
*/
|
||||
void subInExp(const XMLCh* const repString,
|
||||
const XMLCh* const origString,
|
||||
const Match* subEx,
|
||||
XMLBuffer &result,
|
||||
MemoryManager* const manager) const;
|
||||
/**
|
||||
* Converts a token tree into an operation tree
|
||||
*/
|
||||
void compile(const Token* const token);
|
||||
Op* compile(const Token* const token, Op* const next,
|
||||
const bool reverse);
|
||||
/**
|
||||
* Helper methods used by compile
|
||||
*/
|
||||
Op* compileUnion(const Token* const token, Op* const next,
|
||||
const bool reverse);
|
||||
Op* compileParenthesis(const Token* const token, Op* const next,
|
||||
const bool reverse);
|
||||
Op* compileConcat(const Token* const token, Op* const next,
|
||||
const bool reverse);
|
||||
Op* compileClosure(const Token* const token, Op* const next,
|
||||
const bool reverse, const Token::tokType tkType);
|
||||
|
||||
bool doTokenOverlap(const Op* op, Token* token);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected data members
|
||||
// -----------------------------------------------------------------------
|
||||
bool fHasBackReferences;
|
||||
bool fFixedStringOnly;
|
||||
int fNoGroups;
|
||||
XMLSize_t fMinLength;
|
||||
unsigned int fNoClosures;
|
||||
unsigned int fOptions;
|
||||
const BMPattern* fBMPattern;
|
||||
XMLCh* fPattern;
|
||||
XMLCh* fFixedString;
|
||||
const Op* fOperations;
|
||||
Token* fTokenTree;
|
||||
RangeToken* fFirstChar;
|
||||
static RangeToken* fWordRange;
|
||||
OpFactory fOpFactory;
|
||||
TokenFactory* fTokenFactory;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// RegularExpression: Static initialize and cleanup methods
|
||||
// -----------------------------------------------------------------------
|
||||
inline void RegularExpression::staticCleanup()
|
||||
{
|
||||
fWordRange = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegularExpression: Cleanup methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void RegularExpression::cleanUp() {
|
||||
|
||||
fMemoryManager->deallocate(fPattern);//delete [] fPattern;
|
||||
fMemoryManager->deallocate(fFixedString);//delete [] fFixedString;
|
||||
delete fBMPattern;
|
||||
delete fTokenFactory;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegularExpression: Helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline bool RegularExpression::isSet(const int options, const int flag) {
|
||||
|
||||
return (options & flag) == flag;
|
||||
}
|
||||
|
||||
|
||||
inline Op* RegularExpression::compileUnion(const Token* const token,
|
||||
Op* const next,
|
||||
const bool reverse) {
|
||||
|
||||
XMLSize_t tokSize = token->size();
|
||||
UnionOp* uniOp = fOpFactory.createUnionOp(tokSize);
|
||||
|
||||
for (XMLSize_t i=0; i<tokSize; i++) {
|
||||
|
||||
uniOp->addElement(compile(token->getChild(i), next, reverse));
|
||||
}
|
||||
|
||||
return uniOp;
|
||||
}
|
||||
|
||||
|
||||
inline Op* RegularExpression::compileParenthesis(const Token* const token,
|
||||
Op* const next,
|
||||
const bool reverse) {
|
||||
|
||||
if (token->getNoParen() == 0)
|
||||
return compile(token->getChild(0), next, reverse);
|
||||
|
||||
Op* captureOp = 0;
|
||||
|
||||
if (reverse) {
|
||||
|
||||
captureOp = fOpFactory.createCaptureOp(token->getNoParen(), next);
|
||||
captureOp = compile(token->getChild(0), captureOp, reverse);
|
||||
|
||||
return fOpFactory.createCaptureOp(-token->getNoParen(), captureOp);
|
||||
}
|
||||
|
||||
captureOp = fOpFactory.createCaptureOp(-token->getNoParen(), next);
|
||||
captureOp = compile(token->getChild(0), captureOp, reverse);
|
||||
|
||||
return fOpFactory.createCaptureOp(token->getNoParen(), captureOp);
|
||||
}
|
||||
|
||||
inline Op* RegularExpression::compileConcat(const Token* const token,
|
||||
Op* const next,
|
||||
const bool reverse) {
|
||||
|
||||
Op* ret = next;
|
||||
XMLSize_t tokSize = token->size();
|
||||
|
||||
if (!reverse) {
|
||||
|
||||
for (XMLSize_t i= tokSize; i>0; i--) {
|
||||
ret = compile(token->getChild(i-1), ret, false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
for (XMLSize_t i= 0; i< tokSize; i++) {
|
||||
ret = compile(token->getChild(i), ret, true);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline Op* RegularExpression::compileClosure(const Token* const token,
|
||||
Op* const next,
|
||||
const bool reverse,
|
||||
const Token::tokType tkType) {
|
||||
|
||||
Op* ret = 0;
|
||||
Token* childTok = token->getChild(0);
|
||||
int min = token->getMin();
|
||||
int max = token->getMax();
|
||||
|
||||
if (min >= 0 && min == max) {
|
||||
|
||||
ret = next;
|
||||
for (int i=0; i< min; i++) {
|
||||
ret = compile(childTok, ret, reverse);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (min > 0 && max > 0)
|
||||
max -= min;
|
||||
|
||||
if (max > 0) {
|
||||
|
||||
ret = next;
|
||||
for (int i=0; i<max; i++) {
|
||||
|
||||
ChildOp* childOp = fOpFactory.createQuestionOp(
|
||||
tkType == Token::T_NONGREEDYCLOSURE);
|
||||
|
||||
childOp->setNextOp(next);
|
||||
childOp->setChild(compile(childTok, ret, reverse));
|
||||
ret = childOp;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
ChildOp* childOp = 0;
|
||||
|
||||
if (tkType == Token::T_NONGREEDYCLOSURE) {
|
||||
childOp = fOpFactory.createNonGreedyClosureOp();
|
||||
}
|
||||
else {
|
||||
|
||||
if (childTok->getMinLength() == 0)
|
||||
childOp = fOpFactory.createClosureOp(fNoClosures++);
|
||||
else
|
||||
childOp = fOpFactory.createClosureOp(-1);
|
||||
}
|
||||
|
||||
childOp->setNextOp(next);
|
||||
if(next==NULL || !doTokenOverlap(next, childTok))
|
||||
{
|
||||
childOp->setOpType(tkType == Token::T_NONGREEDYCLOSURE?Op::O_FINITE_NONGREEDYCLOSURE:Op::O_FINITE_CLOSURE);
|
||||
childOp->setChild(compile(childTok, NULL, reverse));
|
||||
}
|
||||
else
|
||||
{
|
||||
childOp->setChild(compile(childTok, childOp, reverse));
|
||||
}
|
||||
ret = childOp;
|
||||
}
|
||||
|
||||
if (min > 0) {
|
||||
|
||||
for (int i=0; i< min; i++) {
|
||||
ret = compile(childTok, ret, reverse);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
/**
|
||||
* End of file RegularExpression.hpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,239 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RegxDefs.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_REGXDEFS_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_REGXDEFS_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
static const XMLCh fgXMLCategory[] =
|
||||
{
|
||||
chLatin_X, chLatin_M, chLatin_L, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgASCIICategory[] =
|
||||
{
|
||||
chLatin_A, chLatin_S, chLatin_C, chLatin_I, chLatin_I, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUnicodeCategory[] =
|
||||
{
|
||||
chLatin_U, chLatin_N, chLatin_I, chLatin_C, chLatin_O, chLatin_D,
|
||||
chLatin_E, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgBlockCategory[] =
|
||||
{
|
||||
chLatin_B, chLatin_L, chLatin_O, chLatin_C, chLatin_K, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgXMLSpace[] =
|
||||
{
|
||||
chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_i, chLatin_s, chLatin_S,
|
||||
chLatin_p, chLatin_a, chLatin_c, chLatin_e, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgXMLDigit[] =
|
||||
{
|
||||
chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_i, chLatin_s, chLatin_D,
|
||||
chLatin_i, chLatin_g, chLatin_i, chLatin_t, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgXMLWord[] =
|
||||
{
|
||||
chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_i, chLatin_s, chLatin_W,
|
||||
chLatin_o, chLatin_r, chLatin_d, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgXMLNameChar[] =
|
||||
{
|
||||
chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_i, chLatin_s, chLatin_N,
|
||||
chLatin_a, chLatin_m, chLatin_e, chLatin_C, chLatin_h, chLatin_a,
|
||||
chLatin_r, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgXMLInitialNameChar[] =
|
||||
{
|
||||
chLatin_x, chLatin_m, chLatin_l, chColon, chLatin_i, chLatin_s, chLatin_I,
|
||||
chLatin_n, chLatin_i, chLatin_t, chLatin_i, chLatin_a, chLatin_l,
|
||||
chLatin_N, chLatin_a, chLatin_m, chLatin_e, chLatin_C, chLatin_h,
|
||||
chLatin_a, chLatin_r, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgASCII[] =
|
||||
{
|
||||
chLatin_a, chLatin_s, chLatin_c, chLatin_i, chLatin_i, chColon, chLatin_i,
|
||||
chLatin_s, chLatin_A, chLatin_s, chLatin_c, chLatin_i, chLatin_i, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgASCIIDigit[] =
|
||||
{
|
||||
chLatin_a, chLatin_s, chLatin_c, chLatin_i, chLatin_i, chColon, chLatin_i,
|
||||
chLatin_s, chLatin_D, chLatin_i, chLatin_g, chLatin_i, chLatin_t, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgASCIIWord[] =
|
||||
{
|
||||
chLatin_a, chLatin_s, chLatin_c, chLatin_i, chLatin_i, chColon, chLatin_i,
|
||||
chLatin_s, chLatin_W, chLatin_o, chLatin_r, chLatin_d, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgASCIISpace[] =
|
||||
{
|
||||
chLatin_a, chLatin_s, chLatin_c, chLatin_i, chLatin_i, chColon, chLatin_i,
|
||||
chLatin_s, chLatin_S, chLatin_p, chLatin_a, chLatin_c, chLatin_e, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgASCIIXDigit[] =
|
||||
{
|
||||
chLatin_a, chLatin_s, chLatin_c, chLatin_i, chLatin_i, chColon, chLatin_i,
|
||||
chLatin_s, chLatin_X, chLatin_D, chLatin_i, chLatin_g, chLatin_i,
|
||||
chLatin_t, chNull
|
||||
};
|
||||
|
||||
|
||||
static const XMLCh fgUniAll[] =
|
||||
{
|
||||
chLatin_A, chLatin_L, chLatin_L, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsAlpha[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_A, chLatin_l, chLatin_p, chLatin_h,
|
||||
chLatin_a, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsAlnum[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_A, chLatin_l, chLatin_n, chLatin_u,
|
||||
chLatin_m, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsWord[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_W, chLatin_o, chLatin_r, chLatin_d,
|
||||
chNull
|
||||
};
|
||||
|
||||
|
||||
static const XMLCh fgUniIsDigit[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_D, chLatin_i, chLatin_g, chLatin_i,
|
||||
chLatin_t, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsUpper[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_U, chLatin_p, chLatin_p, chLatin_e,
|
||||
chLatin_r, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsLower[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_L, chLatin_o, chLatin_w, chLatin_e,
|
||||
chLatin_r, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsPunct[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_P, chLatin_u, chLatin_n, chLatin_c,
|
||||
chLatin_t, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniIsSpace[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_S, chLatin_p, chLatin_a, chLatin_c,
|
||||
chLatin_e, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniAssigned[] =
|
||||
{
|
||||
chLatin_A, chLatin_S, chLatin_S, chLatin_I, chLatin_G, chLatin_N,
|
||||
chLatin_E, chLatin_D, chNull
|
||||
};
|
||||
|
||||
|
||||
static const XMLCh fgUniDecimalDigit[] =
|
||||
{
|
||||
chLatin_N, chLatin_d, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgBlockIsSpecials[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_S, chLatin_p, chLatin_e, chLatin_c, chLatin_i, chLatin_a,
|
||||
chLatin_l, chLatin_s, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgBlockIsPrivateUse[] =
|
||||
{
|
||||
chLatin_I, chLatin_s, chLatin_P, chLatin_r, chLatin_i, chLatin_v, chLatin_a, chLatin_t, chLatin_e,
|
||||
chLatin_U, chLatin_s, chLatin_e, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniLetter[] =
|
||||
{
|
||||
chLatin_L, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniNumber[] =
|
||||
{
|
||||
chLatin_N, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniMark[] =
|
||||
{
|
||||
chLatin_M, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniSeparator[] =
|
||||
{
|
||||
chLatin_Z, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniPunctuation[] =
|
||||
{
|
||||
chLatin_P, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniControl[] =
|
||||
{
|
||||
chLatin_C, chNull
|
||||
};
|
||||
|
||||
static const XMLCh fgUniSymbol[] =
|
||||
{
|
||||
chLatin_S, chNull
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file RegxDefs.hpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,868 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RegxParser.cpp 1662882 2015-02-28 02:07:25Z scantor $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RegxParser.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
#include <xercesc/util/ParseException.hpp>
|
||||
#include <xercesc/util/regx/RegularExpression.hpp>
|
||||
#include <xercesc/util/regx/RegxUtil.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/regx/TokenInc.hpp>
|
||||
#include <xercesc/framework/XMLErrorCodes.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser::ReferencePostion: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
RegxParser::ReferencePosition::ReferencePosition(const int refNo,
|
||||
const XMLSize_t position)
|
||||
:fReferenceNo(refNo)
|
||||
, fPosition(position)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
RegxParser::RegxParser(MemoryManager* const manager)
|
||||
:fMemoryManager(manager),
|
||||
fHasBackReferences(false),
|
||||
fOptions(0),
|
||||
fOffset(0),
|
||||
fNoGroups(1),
|
||||
fParseContext(regexParserStateNormal),
|
||||
fStringLen(0),
|
||||
fState(REGX_T_EOF),
|
||||
fCharData(0),
|
||||
fString(0),
|
||||
fReferences(0),
|
||||
fTokenFactory(0)
|
||||
{
|
||||
}
|
||||
|
||||
RegxParser::~RegxParser() {
|
||||
|
||||
fMemoryManager->deallocate(fString);//delete [] fString;
|
||||
delete fReferences;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser: Parsing methods
|
||||
// ---------------------------------------------------------------------------
|
||||
Token* RegxParser::parse(const XMLCh* const regxStr, const int options) {
|
||||
|
||||
// if TokenFactory is not set do nothing.
|
||||
// REVISIT - should we throw an exception
|
||||
if (fTokenFactory == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fOptions = options;
|
||||
fOffset = 0;
|
||||
fNoGroups = 1;
|
||||
fHasBackReferences = false;
|
||||
setParseContext(regexParserStateNormal);
|
||||
if (fString)
|
||||
fMemoryManager->deallocate(fString);//delete [] fString;
|
||||
fString = XMLString::replicate(regxStr, fMemoryManager);
|
||||
|
||||
if (isSet(RegularExpression::EXTENDED_COMMENT)) {
|
||||
|
||||
if (fString)
|
||||
fMemoryManager->deallocate(fString);//delete [] fString;
|
||||
fString = RegxUtil::stripExtendedComment(regxStr, fMemoryManager);
|
||||
}
|
||||
|
||||
fStringLen = XMLString::stringLen(fString);
|
||||
processNext();
|
||||
|
||||
Token* retTok = parseRegx();
|
||||
|
||||
if (fOffset != fStringLen) {
|
||||
XMLCh value1[65];
|
||||
XMLString::sizeToText(fOffset, value1, 64, 10, fMemoryManager);
|
||||
ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_Parse1, value1, fString, fMemoryManager);
|
||||
}
|
||||
|
||||
if (fReferences != 0) {
|
||||
|
||||
XMLSize_t refSize = fReferences->size();
|
||||
for (XMLSize_t i = 0; i < refSize; i++) {
|
||||
|
||||
if (fNoGroups <= fReferences->elementAt(i)->fReferenceNo) {
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Parse2, fMemoryManager);
|
||||
}
|
||||
}
|
||||
|
||||
fReferences->removeAllElements();
|
||||
}
|
||||
|
||||
return retTok;
|
||||
}
|
||||
|
||||
|
||||
void RegxParser::processNext() {
|
||||
|
||||
if (fOffset >= fStringLen) {
|
||||
|
||||
fCharData = -1;
|
||||
fState = REGX_T_EOF;
|
||||
return;
|
||||
}
|
||||
|
||||
parserState nextState;
|
||||
XMLCh ch = fString[fOffset++];
|
||||
fCharData = ch;
|
||||
|
||||
if (fParseContext == regexParserStateInBrackets) {
|
||||
|
||||
switch (ch) {
|
||||
case chBackSlash:
|
||||
nextState = REGX_T_BACKSOLIDUS;
|
||||
|
||||
if (fOffset >= fStringLen) {
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, fMemoryManager);
|
||||
}
|
||||
|
||||
fCharData = fString[fOffset++];
|
||||
break;
|
||||
case chDash:
|
||||
if (fOffset < fStringLen && fString[fOffset] == chOpenSquare) {
|
||||
|
||||
fOffset++;
|
||||
nextState = REGX_T_XMLSCHEMA_CC_SUBTRACTION;
|
||||
}
|
||||
else {
|
||||
nextState = REGX_T_CHAR;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (RegxUtil::isHighSurrogate(ch) && fOffset < fStringLen) {
|
||||
|
||||
XMLCh lowCh = fString[fOffset];
|
||||
if (RegxUtil::isLowSurrogate(lowCh)) {
|
||||
fCharData = RegxUtil::composeFromSurrogate(ch, lowCh);
|
||||
fOffset++;
|
||||
}
|
||||
else {
|
||||
throw XMLErrs::Expected2ndSurrogateChar;
|
||||
}
|
||||
}
|
||||
|
||||
nextState = REGX_T_CHAR;
|
||||
}
|
||||
|
||||
fState = nextState;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (ch) {
|
||||
|
||||
case chPipe:
|
||||
nextState = REGX_T_OR;
|
||||
break;
|
||||
case chAsterisk:
|
||||
nextState = REGX_T_STAR;
|
||||
break;
|
||||
case chPlus:
|
||||
nextState = REGX_T_PLUS;
|
||||
break;
|
||||
case chQuestion:
|
||||
nextState = REGX_T_QUESTION;
|
||||
break;
|
||||
case chCloseParen:
|
||||
nextState = REGX_T_RPAREN;
|
||||
break;
|
||||
case chPeriod:
|
||||
nextState = REGX_T_DOT;
|
||||
break;
|
||||
case chOpenSquare:
|
||||
nextState = REGX_T_LBRACKET;
|
||||
break;
|
||||
case chCaret:
|
||||
nextState = REGX_T_CARET;
|
||||
break;
|
||||
case chDollarSign:
|
||||
nextState = REGX_T_DOLLAR;
|
||||
break;
|
||||
case chOpenParen:
|
||||
nextState = REGX_T_LPAREN;
|
||||
break;
|
||||
case chBackSlash:
|
||||
nextState = REGX_T_BACKSOLIDUS;
|
||||
if (fOffset >= fStringLen) {
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, fMemoryManager);
|
||||
}
|
||||
|
||||
fCharData = fString[fOffset++];
|
||||
break;
|
||||
default:
|
||||
nextState = REGX_T_CHAR;
|
||||
if (RegxUtil::isHighSurrogate(ch) && fOffset < fStringLen) {
|
||||
|
||||
XMLCh lowCh = fString[fOffset];
|
||||
if (RegxUtil::isLowSurrogate(lowCh)) {
|
||||
fCharData = RegxUtil::composeFromSurrogate(ch, lowCh);
|
||||
fOffset++;
|
||||
}
|
||||
else {
|
||||
throw XMLErrs::Expected2ndSurrogateChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fState = nextState;
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::parseRegx(const bool matchingRParen) {
|
||||
|
||||
Token* tok = parseTerm(matchingRParen);
|
||||
Token* parentTok = 0;
|
||||
|
||||
while (fState == REGX_T_OR) {
|
||||
|
||||
processNext();
|
||||
if (parentTok == 0) {
|
||||
|
||||
parentTok = fTokenFactory->createUnion();
|
||||
parentTok->addChild(tok, fTokenFactory);
|
||||
tok = parentTok;
|
||||
}
|
||||
|
||||
tok->addChild(parseTerm(matchingRParen), fTokenFactory);
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::parseTerm(const bool matchingRParen) {
|
||||
|
||||
parserState state = fState;
|
||||
|
||||
if (state == REGX_T_OR || state == REGX_T_EOF
|
||||
|| (state == REGX_T_RPAREN && matchingRParen)) {
|
||||
return fTokenFactory->createToken(Token::T_EMPTY);
|
||||
}
|
||||
else {
|
||||
|
||||
Token* tok = parseFactor();
|
||||
Token* concatTok = 0;
|
||||
|
||||
while ((state = fState) != REGX_T_OR && state != REGX_T_EOF
|
||||
&& (state != REGX_T_RPAREN || !matchingRParen))
|
||||
{
|
||||
if (concatTok == 0) {
|
||||
|
||||
concatTok = fTokenFactory->createUnion(true);
|
||||
concatTok->addChild(tok, fTokenFactory);
|
||||
tok = concatTok;
|
||||
}
|
||||
concatTok->addChild(parseFactor(), fTokenFactory);
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processCaret() {
|
||||
|
||||
processNext();
|
||||
return fTokenFactory->getLineBegin();
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processDollar() {
|
||||
|
||||
processNext();
|
||||
return fTokenFactory->getLineEnd();
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processStar(Token* const tok) {
|
||||
|
||||
processNext();
|
||||
|
||||
if (fState == REGX_T_QUESTION) {
|
||||
processNext();
|
||||
return fTokenFactory->createClosure(tok, true);
|
||||
}
|
||||
|
||||
return fTokenFactory->createClosure(tok);
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processPlus(Token* const tok) {
|
||||
|
||||
processNext();
|
||||
|
||||
if (fState == REGX_T_QUESTION) {
|
||||
processNext();
|
||||
return fTokenFactory->createConcat(tok,
|
||||
fTokenFactory->createClosure(tok,true));
|
||||
}
|
||||
|
||||
return fTokenFactory->createConcat(tok,
|
||||
fTokenFactory->createClosure(tok));
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processQuestion(Token* const tok) {
|
||||
|
||||
processNext();
|
||||
|
||||
Token* parentTok = fTokenFactory->createUnion();
|
||||
|
||||
if (fState == REGX_T_QUESTION) {
|
||||
processNext();
|
||||
parentTok->addChild(fTokenFactory->createToken(Token::T_EMPTY), fTokenFactory);
|
||||
parentTok->addChild(tok, fTokenFactory);
|
||||
}
|
||||
else {
|
||||
parentTok->addChild(tok, fTokenFactory);
|
||||
parentTok->addChild(fTokenFactory->createToken(Token::T_EMPTY), fTokenFactory);
|
||||
}
|
||||
|
||||
return parentTok;
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processParen() {
|
||||
|
||||
processNext();
|
||||
int num = fNoGroups++;
|
||||
Token* tok = fTokenFactory->createParenthesis(parseRegx(true),num);
|
||||
|
||||
if (fState != REGX_T_RPAREN)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Factor1, fMemoryManager);
|
||||
|
||||
processNext();
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::processBackReference() {
|
||||
|
||||
XMLSize_t position = fOffset - 2;
|
||||
|
||||
// Handle multi digit back references
|
||||
int refNo = fCharData - chDigit_0;
|
||||
while(true) {
|
||||
processNext();
|
||||
if(fState != REGX_T_CHAR || fCharData < chDigit_0 || fCharData > chDigit_9)
|
||||
break;
|
||||
|
||||
int nextRefNo = (refNo * 10) + fCharData - chDigit_0;
|
||||
if(nextRefNo >= fNoGroups)
|
||||
break;
|
||||
|
||||
refNo = nextRefNo;
|
||||
}
|
||||
|
||||
Token* tok = fTokenFactory->createBackReference(refNo);
|
||||
|
||||
fHasBackReferences = true;
|
||||
if (fReferences == 0) {
|
||||
fReferences = new (fMemoryManager) RefVectorOf<ReferencePosition>(8, true, fMemoryManager);
|
||||
}
|
||||
|
||||
fReferences->addElement(new (fMemoryManager) ReferencePosition(refNo, position));
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::parseFactor() {
|
||||
|
||||
Token* tok = parseAtom();
|
||||
|
||||
switch(fState) {
|
||||
|
||||
case REGX_T_STAR:
|
||||
return processStar(tok);
|
||||
case REGX_T_PLUS:
|
||||
return processPlus(tok);
|
||||
case REGX_T_QUESTION:
|
||||
return processQuestion(tok);
|
||||
case REGX_T_CHAR:
|
||||
if (fCharData == chOpenCurly && fOffset < fStringLen) {
|
||||
|
||||
int min = 0;
|
||||
int max = -1;
|
||||
XMLInt32 ch = fString[fOffset++];
|
||||
|
||||
if (ch >= chDigit_0 && ch <= chDigit_9) {
|
||||
|
||||
min = ch - chDigit_0;
|
||||
while (fOffset < fStringLen
|
||||
&& (ch = fString[fOffset++]) >= chDigit_0
|
||||
&& ch <= chDigit_9) {
|
||||
|
||||
min = min*10 + ch - chDigit_0;
|
||||
}
|
||||
|
||||
if (min < 0)
|
||||
ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier5, fString, fMemoryManager);
|
||||
}
|
||||
else {
|
||||
ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier1, fString, fMemoryManager);
|
||||
}
|
||||
|
||||
max = min;
|
||||
|
||||
if (ch == chComma) {
|
||||
|
||||
if (fOffset >= fStringLen) {
|
||||
ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier3, fString, fMemoryManager);
|
||||
}
|
||||
else if ((ch = fString[fOffset++]) >= chDigit_0 && ch <= chDigit_9) {
|
||||
|
||||
max = ch - chDigit_0;
|
||||
while (fOffset < fStringLen
|
||||
&& (ch = fString[fOffset++]) >= chDigit_0
|
||||
&& ch <= chDigit_9) {
|
||||
|
||||
max = max*10 + ch - chDigit_0;
|
||||
}
|
||||
|
||||
if (max < 0)
|
||||
ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier5, fString, fMemoryManager);
|
||||
else if (min > max)
|
||||
ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier4, fString, fMemoryManager);
|
||||
}
|
||||
else {
|
||||
max = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (ch != chCloseCurly) {
|
||||
ThrowXMLwithMemMgr1(ParseException, XMLExcepts::Parser_Quantifier2, fString, fMemoryManager);
|
||||
}
|
||||
|
||||
if (checkQuestion(fOffset)) {
|
||||
|
||||
tok = fTokenFactory->createClosure(tok, true);
|
||||
fOffset++;
|
||||
}
|
||||
else {
|
||||
tok = fTokenFactory->createClosure(tok);
|
||||
}
|
||||
|
||||
tok->setMin(min);
|
||||
tok->setMax(max);
|
||||
processNext();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
Token* RegxParser::parseAtom() {
|
||||
|
||||
Token* tok = 0;
|
||||
|
||||
switch(fState) {
|
||||
|
||||
case REGX_T_LPAREN:
|
||||
return processParen();
|
||||
case REGX_T_DOT:
|
||||
processNext();
|
||||
tok = fTokenFactory->getDot();
|
||||
break;
|
||||
case REGX_T_CARET:
|
||||
return processCaret();
|
||||
case REGX_T_DOLLAR:
|
||||
return processDollar();
|
||||
case REGX_T_LBRACKET:
|
||||
return parseCharacterClass(true);
|
||||
case REGX_T_BACKSOLIDUS:
|
||||
switch(fCharData) {
|
||||
|
||||
case chLatin_d:
|
||||
case chLatin_D:
|
||||
case chLatin_w:
|
||||
case chLatin_W:
|
||||
case chLatin_s:
|
||||
case chLatin_S:
|
||||
case chLatin_c:
|
||||
case chLatin_C:
|
||||
case chLatin_i:
|
||||
case chLatin_I:
|
||||
tok = getTokenForShorthand(fCharData);
|
||||
processNext();
|
||||
return tok;
|
||||
case chDigit_0:
|
||||
case chDigit_1:
|
||||
case chDigit_2:
|
||||
case chDigit_3:
|
||||
case chDigit_4:
|
||||
case chDigit_5:
|
||||
case chDigit_6:
|
||||
case chDigit_7:
|
||||
case chDigit_8:
|
||||
case chDigit_9:
|
||||
return processBackReference();
|
||||
case chLatin_p:
|
||||
case chLatin_P:
|
||||
{
|
||||
tok = processBacksolidus_pP(fCharData);
|
||||
if (tok == 0) {
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom5, fMemoryManager);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
XMLInt32 ch = decodeEscaped();
|
||||
if (ch < 0x10000) {
|
||||
tok = fTokenFactory->createChar(ch);
|
||||
}
|
||||
else {
|
||||
|
||||
XMLCh* surrogateStr = RegxUtil::decomposeToSurrogates(ch, fMemoryManager);
|
||||
ArrayJanitor<XMLCh> janSurrogate(surrogateStr, fMemoryManager);
|
||||
tok = fTokenFactory->createString(surrogateStr);
|
||||
}
|
||||
}
|
||||
break;
|
||||
} // end switch
|
||||
|
||||
processNext();
|
||||
break;
|
||||
case REGX_T_CHAR:
|
||||
if (fCharData == chOpenCurly
|
||||
|| fCharData == chCloseCurly
|
||||
|| fCharData == chCloseSquare)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom4, fMemoryManager);
|
||||
|
||||
tok = fTokenFactory->createChar(fCharData);
|
||||
processNext();
|
||||
break;
|
||||
default:
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom4, fMemoryManager);
|
||||
} //end switch
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
RangeToken* RegxParser::processBacksolidus_pP(const XMLInt32 ch) {
|
||||
|
||||
processNext();
|
||||
|
||||
if (fState != REGX_T_CHAR || fCharData != chOpenCurly)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom2, fMemoryManager);
|
||||
|
||||
XMLSize_t nameStart = fOffset;
|
||||
int nameEnd = XMLString::indexOf(fString,chCloseCurly,nameStart, fMemoryManager);
|
||||
|
||||
if (nameEnd < 0)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom3, fMemoryManager);
|
||||
|
||||
fOffset = nameEnd + 1;
|
||||
XMLCh* rangeName = (XMLCh*) fMemoryManager->allocate
|
||||
(
|
||||
(nameEnd - nameStart + 1) * sizeof(XMLCh)
|
||||
);//new XMLCh[(nameEnd - nameStart) + 1];
|
||||
ArrayJanitor<XMLCh> janRangeName(rangeName, fMemoryManager);
|
||||
XMLString::subString(rangeName, fString, nameStart, nameEnd, fMemoryManager);
|
||||
|
||||
return fTokenFactory->getRange(rangeName, !(ch == chLatin_p));
|
||||
}
|
||||
|
||||
RangeToken* RegxParser::parseCharacterClass(const bool useNRange) {
|
||||
|
||||
setParseContext(regexParserStateInBrackets);
|
||||
processNext();
|
||||
|
||||
RangeToken* tok = 0;
|
||||
bool isNRange = false;
|
||||
|
||||
if (getState() == REGX_T_CHAR && getCharData() == chCaret) {
|
||||
isNRange = true;
|
||||
processNext();
|
||||
}
|
||||
tok = fTokenFactory->createRange();
|
||||
|
||||
parserState type;
|
||||
bool firstLoop = true;
|
||||
bool wasDecoded;
|
||||
|
||||
while ( (type = getState()) != REGX_T_EOF) {
|
||||
|
||||
wasDecoded = false;
|
||||
|
||||
// single range | from-to-range | subtraction
|
||||
if (type == REGX_T_CHAR && getCharData() == chCloseSquare && !firstLoop)
|
||||
break;
|
||||
|
||||
XMLInt32 ch = getCharData();
|
||||
bool end = false;
|
||||
|
||||
if (type == REGX_T_BACKSOLIDUS) {
|
||||
|
||||
switch(ch) {
|
||||
case chLatin_d:
|
||||
case chLatin_D:
|
||||
case chLatin_w:
|
||||
case chLatin_W:
|
||||
case chLatin_s:
|
||||
case chLatin_S:
|
||||
case chLatin_i:
|
||||
case chLatin_I:
|
||||
case chLatin_c:
|
||||
case chLatin_C:
|
||||
{
|
||||
tok->mergeRanges(getTokenForShorthand(ch));
|
||||
end = true;
|
||||
}
|
||||
break;
|
||||
case chLatin_p:
|
||||
case chLatin_P:
|
||||
{
|
||||
RangeToken* tok2 = processBacksolidus_pP(ch);
|
||||
|
||||
if (tok2 == 0) {
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Atom5, getMemoryManager());
|
||||
}
|
||||
|
||||
tok->mergeRanges(tok2);
|
||||
end = true;
|
||||
}
|
||||
break;
|
||||
case chDash:
|
||||
wasDecoded = true;
|
||||
// fall thru to default.
|
||||
default:
|
||||
ch = decodeEscaped();
|
||||
}
|
||||
} // end if REGX_T_BACKSOLIDUS
|
||||
else if (type == REGX_T_XMLSCHEMA_CC_SUBTRACTION && !firstLoop) {
|
||||
|
||||
if (isNRange)
|
||||
{
|
||||
tok = RangeToken::complementRanges(tok, fTokenFactory, fMemoryManager);
|
||||
isNRange=false;
|
||||
}
|
||||
RangeToken* rangeTok = parseCharacterClass(false);
|
||||
tok->subtractRanges(rangeTok);
|
||||
|
||||
if (getState() != REGX_T_CHAR || getCharData() != chCloseSquare) {
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_CC5, getMemoryManager());
|
||||
}
|
||||
break;
|
||||
} // end if REGX_T_XMLSCHEMA...
|
||||
|
||||
processNext();
|
||||
|
||||
if (!end) {
|
||||
|
||||
if (type == REGX_T_CHAR
|
||||
&& (ch == chOpenSquare
|
||||
|| ch == chCloseSquare
|
||||
|| (ch == chDash && getCharData() == chCloseSquare && firstLoop))) {
|
||||
// if regex = [-] then invalid...
|
||||
// '[', ']', '-' not allowed and should be escaped
|
||||
XMLCh chStr[] = { (XMLCh)ch, chNull };
|
||||
ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_CC6, chStr, chStr, getMemoryManager());
|
||||
}
|
||||
if (ch == chDash && getCharData() == chDash && getState() != REGX_T_BACKSOLIDUS && !wasDecoded) {
|
||||
XMLCh chStr[] = { (XMLCh)ch, chNull };
|
||||
ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_CC6, chStr, chStr, getMemoryManager());
|
||||
}
|
||||
|
||||
if (getState() != REGX_T_CHAR || getCharData() != chDash) {
|
||||
tok->addRange(ch, ch);
|
||||
}
|
||||
else {
|
||||
|
||||
processNext();
|
||||
if ((type = getState()) == REGX_T_EOF)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_CC2, getMemoryManager());
|
||||
|
||||
if (type == REGX_T_CHAR && getCharData() == chCloseSquare) {
|
||||
tok->addRange(ch, ch);
|
||||
tok->addRange(chDash, chDash);
|
||||
}
|
||||
else if (type == REGX_T_XMLSCHEMA_CC_SUBTRACTION) {
|
||||
|
||||
static const XMLCh dashStr[] = { chDash, chNull};
|
||||
ThrowXMLwithMemMgr2(ParseException, XMLExcepts::Parser_CC6, dashStr, dashStr, getMemoryManager());
|
||||
}
|
||||
else {
|
||||
|
||||
XMLInt32 rangeEnd = getCharData();
|
||||
XMLCh rangeEndStr[] = { (XMLCh)rangeEnd, chNull };
|
||||
|
||||
if (type == REGX_T_CHAR) {
|
||||
|
||||
if (rangeEnd == chOpenSquare
|
||||
|| rangeEnd == chCloseSquare
|
||||
|| rangeEnd == chDash)
|
||||
// '[', ']', '-' not allowed and should be escaped
|
||||
ThrowXMLwithMemMgr2(ParseException, XMLExcepts::Parser_CC6, rangeEndStr, rangeEndStr, getMemoryManager());
|
||||
}
|
||||
else if (type == REGX_T_BACKSOLIDUS) {
|
||||
rangeEnd = decodeEscaped();
|
||||
}
|
||||
|
||||
processNext();
|
||||
|
||||
if (ch > rangeEnd) {
|
||||
XMLCh chStr[] = { (XMLCh)ch, chNull };
|
||||
ThrowXMLwithMemMgr2(ParseException,XMLExcepts::Parser_Ope3, rangeEndStr, chStr, getMemoryManager());
|
||||
}
|
||||
|
||||
tok->addRange(ch, rangeEnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
firstLoop = false;
|
||||
}
|
||||
|
||||
if (getState() == REGX_T_EOF)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_CC2, getMemoryManager());
|
||||
|
||||
if (isNRange)
|
||||
{
|
||||
if(useNRange)
|
||||
tok->setTokenType(Token::T_NRANGE);
|
||||
else
|
||||
tok = RangeToken::complementRanges(tok, fTokenFactory, fMemoryManager);
|
||||
}
|
||||
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
|
||||
// If the case-insensitive option is enabled, we need to
|
||||
// have the new RangeToken instance build its internal
|
||||
// case-insensitive RangeToken.
|
||||
if (RegularExpression::isSet(fOptions, RegularExpression::IGNORE_CASE))
|
||||
{
|
||||
tok->getCaseInsensitiveToken(fTokenFactory);
|
||||
}
|
||||
|
||||
setParseContext(regexParserStateNormal);
|
||||
processNext();
|
||||
|
||||
return tok;
|
||||
}
|
||||
|
||||
|
||||
RangeToken* RegxParser::getTokenForShorthand(const XMLInt32 ch) {
|
||||
|
||||
switch(ch) {
|
||||
case chLatin_d:
|
||||
return fTokenFactory->getRange(fgUniDecimalDigit);
|
||||
//return fTokenFactory->getRange(fgXMLDigit);
|
||||
case chLatin_D:
|
||||
return fTokenFactory->getRange(fgUniDecimalDigit, true);
|
||||
//return fTokenFactory->getRange(fgXMLDigit, true);
|
||||
case chLatin_w:
|
||||
return fTokenFactory->getRange(fgXMLWord);
|
||||
case chLatin_W:
|
||||
return fTokenFactory->getRange(fgXMLWord, true);
|
||||
case chLatin_s:
|
||||
return fTokenFactory->getRange(fgXMLSpace);
|
||||
case chLatin_S:
|
||||
return fTokenFactory->getRange(fgXMLSpace, true);
|
||||
case chLatin_c:
|
||||
return fTokenFactory->getRange(fgXMLNameChar);
|
||||
case chLatin_C:
|
||||
return fTokenFactory->getRange(fgXMLNameChar, true);
|
||||
case chLatin_i:
|
||||
return fTokenFactory->getRange(fgXMLInitialNameChar);
|
||||
case chLatin_I:
|
||||
return fTokenFactory->getRange(fgXMLInitialNameChar, true);
|
||||
// default:
|
||||
// ThrowXMLwithMemMgr(RuntimeException, "Invalid shorthand {0}", chAsString)
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
XMLInt32 RegxParser::decodeEscaped() {
|
||||
|
||||
if (fState != REGX_T_BACKSOLIDUS)
|
||||
ThrowXMLwithMemMgr(ParseException,XMLExcepts::Parser_Next1, getMemoryManager());
|
||||
|
||||
XMLInt32 ch = fCharData;
|
||||
|
||||
switch (ch) {
|
||||
case chLatin_n:
|
||||
ch = chLF;
|
||||
break;
|
||||
case chLatin_r:
|
||||
ch = chCR;
|
||||
break;
|
||||
case chLatin_t:
|
||||
ch = chHTab;
|
||||
break;
|
||||
case chBackSlash:
|
||||
case chPipe:
|
||||
case chPeriod:
|
||||
case chCaret:
|
||||
case chDash:
|
||||
case chQuestion:
|
||||
case chAsterisk:
|
||||
case chPlus:
|
||||
case chOpenCurly:
|
||||
case chCloseCurly:
|
||||
case chOpenParen:
|
||||
case chCloseParen:
|
||||
case chOpenSquare:
|
||||
case chCloseSquare:
|
||||
case chDollarSign:
|
||||
break;
|
||||
default:
|
||||
{
|
||||
XMLCh chString[] = {chBackSlash, (XMLCh)ch, chNull};
|
||||
ThrowXMLwithMemMgr1(ParseException,XMLExcepts::Parser_Process2, chString, getMemoryManager());
|
||||
}
|
||||
}
|
||||
|
||||
return ch;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser: Helper Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
bool RegxParser::checkQuestion(const XMLSize_t off) {
|
||||
|
||||
return ((off < fStringLen) && fString[off] == chQuestion);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End file RegxParser.cpp
|
||||
*/
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RegxParser.hpp 711369 2008-11-04 20:03:14Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_REGXPARSER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_REGXPARSER_HPP
|
||||
|
||||
/*
|
||||
* A regular expression parser
|
||||
*/
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class Token;
|
||||
class RangeToken;
|
||||
class TokenFactory;
|
||||
|
||||
class XMLUTIL_EXPORT RegxParser : public XMemory
|
||||
{
|
||||
public:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public constant data
|
||||
// -----------------------------------------------------------------------
|
||||
// Parse tokens
|
||||
typedef enum {
|
||||
REGX_T_CHAR = 0,
|
||||
REGX_T_EOF = 1,
|
||||
REGX_T_OR = 2,
|
||||
REGX_T_STAR = 3,
|
||||
REGX_T_PLUS = 4,
|
||||
REGX_T_QUESTION = 5,
|
||||
REGX_T_LPAREN = 6,
|
||||
REGX_T_RPAREN = 7,
|
||||
REGX_T_DOT = 8,
|
||||
REGX_T_LBRACKET = 9,
|
||||
REGX_T_BACKSOLIDUS = 10,
|
||||
REGX_T_CARET = 11,
|
||||
REGX_T_DOLLAR = 12,
|
||||
REGX_T_XMLSCHEMA_CC_SUBTRACTION = 13
|
||||
} parserState;
|
||||
|
||||
typedef enum {
|
||||
regexParserStateNormal = 0,
|
||||
regexParserStateInBrackets = 1
|
||||
} parserStateContext;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
RegxParser(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
virtual ~RegxParser();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
parserStateContext getParseContext() const;
|
||||
parserState getState() const;
|
||||
XMLInt32 getCharData() const;
|
||||
int getNoParen() const;
|
||||
XMLSize_t getOffset() const;
|
||||
bool hasBackReferences() const;
|
||||
TokenFactory* getTokenFactory() const;
|
||||
int getOptions() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setParseContext(const parserStateContext value);
|
||||
void setTokenFactory(TokenFactory* const tokFactory);
|
||||
void setOptions(const int options);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Parsing methods
|
||||
// -----------------------------------------------------------------------
|
||||
Token* parse(const XMLCh* const regxStr, const int options);
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
virtual bool checkQuestion(const XMLSize_t off);
|
||||
virtual XMLInt32 decodeEscaped();
|
||||
MemoryManager* getMemoryManager() const;
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected Parsing/Processing methods
|
||||
// -----------------------------------------------------------------------
|
||||
void processNext();
|
||||
|
||||
Token* parseRegx(const bool matchingRParen = false);
|
||||
virtual Token* processCaret();
|
||||
virtual Token* processDollar();
|
||||
virtual Token* processBackReference();
|
||||
virtual Token* processStar(Token* const tok);
|
||||
virtual Token* processPlus(Token* const tok);
|
||||
virtual Token* processQuestion(Token* const tok);
|
||||
virtual Token* processParen();
|
||||
|
||||
RangeToken* parseCharacterClass(const bool useNRange);
|
||||
RangeToken* processBacksolidus_pP(const XMLInt32 ch);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected PreCreated RangeToken access methods
|
||||
// -----------------------------------------------------------------------
|
||||
RangeToken* getTokenForShorthand(const XMLInt32 ch);
|
||||
|
||||
bool isSet(const int flag);
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private parsing/processing methods
|
||||
// -----------------------------------------------------------------------
|
||||
Token* parseTerm(const bool matchingRParen = false);
|
||||
Token* parseFactor();
|
||||
Token* parseAtom();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RegxParser(const RegxParser&);
|
||||
RegxParser& operator=(const RegxParser&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data types
|
||||
// -----------------------------------------------------------------------
|
||||
class ReferencePosition : public XMemory
|
||||
{
|
||||
public :
|
||||
ReferencePosition(const int refNo, const XMLSize_t position);
|
||||
|
||||
int fReferenceNo;
|
||||
XMLSize_t fPosition;
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
int hexChar(const XMLInt32 ch);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
MemoryManager* fMemoryManager;
|
||||
bool fHasBackReferences;
|
||||
int fOptions;
|
||||
XMLSize_t fOffset;
|
||||
int fNoGroups;
|
||||
parserStateContext fParseContext;
|
||||
XMLSize_t fStringLen;
|
||||
parserState fState;
|
||||
XMLInt32 fCharData;
|
||||
XMLCh* fString;
|
||||
RefVectorOf<ReferencePosition>* fReferences;
|
||||
TokenFactory* fTokenFactory;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser: Getter Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline RegxParser::parserStateContext RegxParser::getParseContext() const {
|
||||
|
||||
return fParseContext;
|
||||
}
|
||||
|
||||
inline RegxParser::parserState RegxParser::getState() const {
|
||||
|
||||
return fState;
|
||||
}
|
||||
|
||||
inline XMLInt32 RegxParser::getCharData() const {
|
||||
|
||||
return fCharData;
|
||||
}
|
||||
|
||||
inline int RegxParser::getNoParen() const {
|
||||
|
||||
return fNoGroups;
|
||||
}
|
||||
|
||||
inline XMLSize_t RegxParser::getOffset() const {
|
||||
|
||||
return fOffset;
|
||||
}
|
||||
|
||||
inline bool RegxParser::hasBackReferences() const {
|
||||
|
||||
return fHasBackReferences;
|
||||
}
|
||||
|
||||
inline TokenFactory* RegxParser::getTokenFactory() const {
|
||||
|
||||
return fTokenFactory;
|
||||
}
|
||||
|
||||
inline MemoryManager* RegxParser::getMemoryManager() const {
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
inline int RegxParser::getOptions() const {
|
||||
|
||||
return fOptions;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser: Setter Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void RegxParser::setParseContext(const RegxParser::parserStateContext value) {
|
||||
|
||||
fParseContext = value;
|
||||
}
|
||||
|
||||
inline void RegxParser::setTokenFactory(TokenFactory* const tokFactory) {
|
||||
|
||||
fTokenFactory = tokFactory;
|
||||
}
|
||||
|
||||
inline void RegxParser::setOptions(const int options) {
|
||||
|
||||
fOptions = options;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// RegxParser: Helper Methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline bool RegxParser::isSet(const int flag) {
|
||||
|
||||
return (fOptions & flag) == flag;
|
||||
}
|
||||
|
||||
|
||||
inline int RegxParser::hexChar(const XMLInt32 ch) {
|
||||
|
||||
if (ch < chDigit_0 || ch > chLatin_f)
|
||||
return -1;
|
||||
|
||||
if (ch <= chDigit_9)
|
||||
return ch - chDigit_0;
|
||||
|
||||
if (ch < chLatin_A)
|
||||
return -1;
|
||||
|
||||
if (ch <= chLatin_F)
|
||||
return ch - chLatin_A + 10;
|
||||
|
||||
if (ch < chLatin_a)
|
||||
return -1;
|
||||
|
||||
return ch - chLatin_a + 10;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file RegxParser.hpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RegxUtil.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RegxUtil.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
XMLCh* RegxUtil::decomposeToSurrogates(XMLInt32 ch,
|
||||
MemoryManager* const manager) {
|
||||
|
||||
XMLCh* pszStr = (XMLCh*) manager->allocate(3 * sizeof(XMLCh));//new XMLCh[3];
|
||||
|
||||
decomposeToSurrogates(ch, pszStr[0], pszStr[1]);
|
||||
|
||||
pszStr[2] = chNull;
|
||||
|
||||
return pszStr;
|
||||
}
|
||||
|
||||
|
||||
XMLCh* RegxUtil::stripExtendedComment(const XMLCh* const expression,
|
||||
MemoryManager* const manager) {
|
||||
|
||||
XMLCh* buffer = (manager) ? XMLString::replicate(expression, manager)
|
||||
: XMLString::replicate(expression);
|
||||
|
||||
if (buffer)
|
||||
{
|
||||
const XMLCh* inPtr = expression;
|
||||
XMLCh* outPtr = buffer;
|
||||
|
||||
while (*inPtr) {
|
||||
|
||||
XMLCh ch = *inPtr++;
|
||||
|
||||
if (ch == chFF || ch == chCR || ch == chLF
|
||||
|| ch == chSpace || ch == chHTab) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skips chracters between '#' and a line end.
|
||||
if (ch == chPound) {
|
||||
|
||||
while (*inPtr) {
|
||||
|
||||
ch = *inPtr++;
|
||||
if (ch == chLF || ch == chCR)
|
||||
break;
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ch == chBackSlash && *inPtr) {
|
||||
|
||||
if ((ch = *inPtr++) == chPound || ch == chHTab || ch == chLF
|
||||
|| ch == chFF || ch == chCR || ch == chSpace) {
|
||||
*outPtr++ = ch;
|
||||
}
|
||||
else { // Other escaped character.
|
||||
|
||||
*outPtr++ = chBackSlash;
|
||||
*outPtr++ = ch;
|
||||
}
|
||||
}
|
||||
else { // As is.
|
||||
*outPtr++ = ch;
|
||||
}
|
||||
}
|
||||
|
||||
*outPtr = chNull; // null terminate
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file RegxUtil.cpp
|
||||
*/
|
||||
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: RegxUtil.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_REGXUTIL_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_REGXUTIL_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/XMLUniDefs.hpp>
|
||||
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class MemoryManager;
|
||||
|
||||
class XMLUTIL_EXPORT RegxUtil {
|
||||
public:
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and destructors
|
||||
// -----------------------------------------------------------------------
|
||||
~RegxUtil() {}
|
||||
|
||||
static XMLInt32 composeFromSurrogate(const XMLCh high, const XMLCh low);
|
||||
static bool isEOLChar(const XMLCh);
|
||||
static bool isWordChar(const XMLCh);
|
||||
static bool isLowSurrogate(const XMLCh ch);
|
||||
static bool isHighSurrogate(const XMLCh ch);
|
||||
static void decomposeToSurrogates(XMLInt32 ch, XMLCh& high, XMLCh& low);
|
||||
|
||||
static XMLCh* decomposeToSurrogates(XMLInt32 ch,
|
||||
MemoryManager* const manager);
|
||||
static XMLCh* stripExtendedComment(const XMLCh* const expression,
|
||||
MemoryManager* const manager = 0);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
RegxUtil();
|
||||
};
|
||||
|
||||
|
||||
inline bool RegxUtil::isEOLChar(const XMLCh ch) {
|
||||
|
||||
return (ch == chLF || ch == chCR || ch == chLineSeparator
|
||||
|| ch == chParagraphSeparator);
|
||||
}
|
||||
|
||||
inline XMLInt32 RegxUtil::composeFromSurrogate(const XMLCh high, const XMLCh low) {
|
||||
// see http://unicode.org/unicode/faq/utf_bom.html#35
|
||||
const XMLInt32 SURROGATE_OFFSET = 0x10000 - (0xD800 << 10) - 0xDC00;
|
||||
return (high << 10) + low + SURROGATE_OFFSET;
|
||||
}
|
||||
|
||||
inline bool RegxUtil::isLowSurrogate(const XMLCh ch) {
|
||||
|
||||
return (ch & 0xFC00) == 0xDC00;
|
||||
}
|
||||
|
||||
inline bool RegxUtil::isHighSurrogate(const XMLCh ch) {
|
||||
|
||||
return (ch & 0xFC00) == 0xD800;
|
||||
}
|
||||
|
||||
inline void RegxUtil::decomposeToSurrogates(XMLInt32 ch, XMLCh& high, XMLCh& low) {
|
||||
// see http://unicode.org/unicode/faq/utf_bom.html#35
|
||||
const XMLInt32 LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
|
||||
high = XMLCh(LEAD_OFFSET + (ch >> 10));
|
||||
low = XMLCh(0xDC00 + (ch & 0x3FF));
|
||||
}
|
||||
|
||||
inline bool RegxUtil::isWordChar(const XMLCh ch) {
|
||||
|
||||
if ((ch == chUnderscore)
|
||||
|| (ch >= chDigit_0 && ch <= chDigit_9)
|
||||
|| (ch >= chLatin_A && ch <= chLatin_Z)
|
||||
|| (ch >= chLatin_a && ch <= chLatin_z))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file RegxUtil.hpp
|
||||
*/
|
||||
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: StringToken.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/StringToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
StringToken::StringToken(const Token::tokType tkType,
|
||||
const XMLCh* const literal,
|
||||
const int refNo,
|
||||
MemoryManager* const manager)
|
||||
: Token(tkType, manager)
|
||||
, fRefNo(refNo)
|
||||
, fString(XMLString::replicate(literal, manager))
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
StringToken::~StringToken() {
|
||||
|
||||
fMemoryManager->deallocate(fString);//delete [] fString;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file StringToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: StringToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_STRINGTOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_STRINGTOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
#include <xercesc/util/XMLString.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT StringToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
StringToken(const tokType tkType,
|
||||
const XMLCh* const literal,
|
||||
const int refNo,
|
||||
MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~StringToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
int getReferenceNo() const;
|
||||
const XMLCh* getString() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setString(const XMLCh* const literal);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
StringToken(const StringToken&);
|
||||
StringToken& operator=(const StringToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
int fRefNo;
|
||||
XMLCh* fString;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StringToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline int StringToken::getReferenceNo() const {
|
||||
|
||||
return fRefNo;
|
||||
}
|
||||
|
||||
inline const XMLCh* StringToken::getString() const {
|
||||
|
||||
return fString;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// StringToken: Setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void StringToken::setString(const XMLCh* const literal) {
|
||||
|
||||
fMemoryManager->deallocate(fString);//delete [] fString;
|
||||
fString = 0;
|
||||
fString = XMLString::replicate(literal, fMemoryManager);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file StringToken.hpp
|
||||
*/
|
||||
@@ -0,0 +1,369 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Token.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/RegularExpression.hpp>
|
||||
#include <xercesc/util/regx/RegxUtil.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Static member data initialization
|
||||
// ---------------------------------------------------------------------------
|
||||
const XMLInt32 Token::UTF16_MAX = 0x10FFFF;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
Token::Token(const Token::tokType tkType
|
||||
, MemoryManager* const manager)
|
||||
: fTokenType(tkType)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
Token::~Token() {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Getter mthods
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLSize_t Token::getMinLength() const {
|
||||
|
||||
switch (fTokenType) {
|
||||
|
||||
case T_CONCAT:
|
||||
{
|
||||
XMLSize_t sum = 0;
|
||||
XMLSize_t childSize = size();
|
||||
|
||||
for (XMLSize_t i=0; i<childSize; i++) {
|
||||
sum += getChild(i)->getMinLength();
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
case T_UNION:
|
||||
{
|
||||
XMLSize_t childSize = size();
|
||||
|
||||
if (childSize == 0) {
|
||||
return 0;
|
||||
}
|
||||
XMLSize_t ret = getChild(0)->getMinLength();
|
||||
|
||||
for (XMLSize_t i=1; i < childSize; i++) {
|
||||
|
||||
XMLSize_t min = getChild(i)->getMinLength();
|
||||
if (min < ret)
|
||||
ret = min;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
case T_CLOSURE:
|
||||
case T_NONGREEDYCLOSURE:
|
||||
if (getMin() >= 0)
|
||||
return getMin() * getChild(0)->getMinLength();
|
||||
|
||||
return 0;
|
||||
case T_EMPTY:
|
||||
case T_ANCHOR:
|
||||
return 0;
|
||||
case T_DOT:
|
||||
case T_CHAR:
|
||||
case T_RANGE:
|
||||
case T_NRANGE:
|
||||
return 1;
|
||||
case T_PAREN:
|
||||
return getChild(0)->getMinLength();
|
||||
case T_BACKREFERENCE:
|
||||
return 0; // ***** - REVISIT
|
||||
case T_STRING:
|
||||
return XMLString::stringLen(getString());
|
||||
// default:
|
||||
// throw;
|
||||
}
|
||||
|
||||
// We should not get here, but we have it to make some compilers happy
|
||||
return (XMLSize_t)-1;
|
||||
}
|
||||
|
||||
|
||||
int Token::getMaxLength() const {
|
||||
|
||||
switch (fTokenType) {
|
||||
|
||||
case T_CONCAT:
|
||||
{
|
||||
int sum = 0;
|
||||
XMLSize_t childSize = size();
|
||||
|
||||
for (XMLSize_t i=0; i<childSize; i++) {
|
||||
|
||||
int val = getChild(i)->getMaxLength();
|
||||
|
||||
if (val < 0){
|
||||
return -1;
|
||||
}
|
||||
sum += val;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
case T_UNION:
|
||||
{
|
||||
XMLSize_t childSize = size();
|
||||
|
||||
if (childSize == 0)
|
||||
return 0;
|
||||
|
||||
int ret = getChild(0)->getMaxLength();
|
||||
|
||||
for (XMLSize_t i = 1; ret > 0 && i < childSize; i++) {
|
||||
|
||||
int max = getChild(i)->getMaxLength();
|
||||
|
||||
if (max < 0) {
|
||||
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (max > ret)
|
||||
ret = max;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
case T_CLOSURE:
|
||||
case T_NONGREEDYCLOSURE:
|
||||
if (getMax() >= 0) {
|
||||
return getMax() * getChild(0)->getMaxLength();
|
||||
}
|
||||
return -1;
|
||||
case T_EMPTY:
|
||||
case T_ANCHOR:
|
||||
return 0;
|
||||
case T_CHAR:
|
||||
return 1;
|
||||
case T_DOT:
|
||||
case T_RANGE:
|
||||
case T_NRANGE:
|
||||
return 2;
|
||||
case T_PAREN:
|
||||
return getChild(0)->getMaxLength();
|
||||
case T_BACKREFERENCE:
|
||||
return -1; // REVISIT
|
||||
case T_STRING:
|
||||
return (int)XMLString::stringLen(getString());
|
||||
// default:
|
||||
// throw; //ThrowXML(RuntimeException, ...)
|
||||
} // end switch
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Helper mthods
|
||||
// ---------------------------------------------------------------------------
|
||||
Token::firstCharacterOptions Token::analyzeFirstCharacter(RangeToken* const rangeTok,
|
||||
const int options,
|
||||
TokenFactory* const tokFactory)
|
||||
{
|
||||
switch(fTokenType) {
|
||||
case T_CONCAT:
|
||||
{
|
||||
firstCharacterOptions ret = FC_CONTINUE;
|
||||
for (XMLSize_t i=0; i<size(); i++) {
|
||||
|
||||
Token* tok = getChild(i);
|
||||
if (tok
|
||||
&& (ret=tok->analyzeFirstCharacter(rangeTok,
|
||||
options, tokFactory))!= FC_CONTINUE)
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
case T_UNION:
|
||||
{
|
||||
XMLSize_t childSize = size();
|
||||
if (childSize == 0)
|
||||
return FC_CONTINUE;
|
||||
|
||||
firstCharacterOptions ret = FC_CONTINUE;
|
||||
bool hasEmpty = false;
|
||||
|
||||
for (XMLSize_t i=0; i < childSize; i++) {
|
||||
|
||||
ret = getChild(i)->analyzeFirstCharacter(rangeTok, options, tokFactory);
|
||||
|
||||
if (ret == FC_ANY)
|
||||
break;
|
||||
else
|
||||
hasEmpty = true;
|
||||
}
|
||||
return hasEmpty ? FC_CONTINUE : ret;
|
||||
}
|
||||
case T_CLOSURE:
|
||||
case T_NONGREEDYCLOSURE:
|
||||
{
|
||||
Token* tok = getChild(0);
|
||||
if (tok)
|
||||
tok->analyzeFirstCharacter(rangeTok, options, tokFactory);
|
||||
return FC_CONTINUE;
|
||||
}
|
||||
case T_DOT:
|
||||
return FC_ANY;
|
||||
case T_EMPTY:
|
||||
case T_ANCHOR:
|
||||
return FC_CONTINUE;
|
||||
case T_CHAR:
|
||||
{
|
||||
XMLInt32 ch = getChar();
|
||||
rangeTok->addRange(ch, ch);
|
||||
if (ch < 0x1000 && isSet(options,RegularExpression::IGNORE_CASE)) {
|
||||
//REVISIT
|
||||
}
|
||||
}
|
||||
return FC_TERMINAL;
|
||||
case T_RANGE:
|
||||
{
|
||||
if (isSet(options, RegularExpression::IGNORE_CASE)) {
|
||||
rangeTok->mergeRanges(((RangeToken*)
|
||||
this)->getCaseInsensitiveToken(tokFactory));
|
||||
}
|
||||
else {
|
||||
rangeTok->mergeRanges(this);
|
||||
}
|
||||
return FC_TERMINAL;
|
||||
}
|
||||
case T_NRANGE:
|
||||
{
|
||||
if (isSet(options, RegularExpression::IGNORE_CASE)) {
|
||||
|
||||
RangeToken* caseITok = (((RangeToken*)
|
||||
this)->getCaseInsensitiveToken(tokFactory));
|
||||
rangeTok->mergeRanges(RangeToken::complementRanges(caseITok, tokFactory, fMemoryManager));
|
||||
}
|
||||
else {
|
||||
rangeTok->mergeRanges(
|
||||
RangeToken::complementRanges((RangeToken*) this, tokFactory, fMemoryManager));
|
||||
}
|
||||
}
|
||||
case T_PAREN:
|
||||
{
|
||||
Token* tok = getChild(0);
|
||||
if (tok)
|
||||
return tok->analyzeFirstCharacter(rangeTok,options, tokFactory);
|
||||
}
|
||||
case T_BACKREFERENCE:
|
||||
rangeTok->addRange(0, UTF16_MAX);
|
||||
return FC_ANY;
|
||||
case T_STRING:
|
||||
{
|
||||
const XMLCh* str = getString();
|
||||
XMLInt32 ch = str[0];
|
||||
|
||||
if (RegxUtil::isHighSurrogate((XMLCh) ch)) {
|
||||
}
|
||||
|
||||
rangeTok->addRange(ch, ch);
|
||||
if (ch<0x10000 && isSet(options,RegularExpression::IGNORE_CASE)) {
|
||||
//REVISIT
|
||||
}
|
||||
}
|
||||
return FC_TERMINAL;
|
||||
// default:
|
||||
// throw;
|
||||
}
|
||||
|
||||
return FC_CONTINUE;
|
||||
}
|
||||
|
||||
|
||||
Token* Token::findFixedString(int options, int& outOptions) {
|
||||
|
||||
switch(fTokenType) {
|
||||
|
||||
case T_CHAR:
|
||||
return 0;
|
||||
case T_STRING:
|
||||
outOptions = options;
|
||||
return this;
|
||||
case T_UNION:
|
||||
case T_CLOSURE:
|
||||
case T_NONGREEDYCLOSURE:
|
||||
case T_EMPTY:
|
||||
case T_ANCHOR:
|
||||
case T_RANGE:
|
||||
case T_NRANGE:
|
||||
case T_DOT:
|
||||
case T_BACKREFERENCE:
|
||||
return 0;
|
||||
case T_PAREN:
|
||||
return getChild(0)->findFixedString(options, outOptions);
|
||||
case T_CONCAT:
|
||||
{
|
||||
Token* prevTok = 0;
|
||||
int prevOptions = 0;
|
||||
|
||||
for (XMLSize_t i=0; i<size(); i++) {
|
||||
|
||||
Token* tok = getChild(i)->findFixedString(options, outOptions);
|
||||
|
||||
if (prevTok == 0 || prevTok->isShorterThan(tok)) {
|
||||
|
||||
prevTok = tok;
|
||||
prevOptions = outOptions;
|
||||
}
|
||||
}
|
||||
|
||||
outOptions = prevOptions;
|
||||
return prevTok;
|
||||
}
|
||||
} // end switch
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool Token::isShorterThan(Token* const tok) {
|
||||
|
||||
if (tok == 0)
|
||||
return false;
|
||||
|
||||
if (getTokenType() != T_STRING && tok->getTokenType() != T_STRING)
|
||||
return false; //Should we throw an exception?
|
||||
|
||||
XMLSize_t length = XMLString::stringLen(getString());
|
||||
XMLSize_t tokLength = XMLString::stringLen(tok->getString());
|
||||
|
||||
return length < tokLength;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file Token.cpp
|
||||
*/
|
||||
@@ -0,0 +1,262 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: Token.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_TOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_TOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/RuntimeException.hpp>
|
||||
#include <xercesc/util/PlatformUtils.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class RangeToken;
|
||||
class TokenFactory;
|
||||
|
||||
|
||||
class XMLUTIL_EXPORT Token : public XMemory
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constants
|
||||
// -----------------------------------------------------------------------
|
||||
// Token types
|
||||
typedef enum {
|
||||
T_CHAR = 0,
|
||||
T_CONCAT = 1,
|
||||
T_UNION = 2,
|
||||
T_CLOSURE = 3,
|
||||
T_RANGE = 4,
|
||||
T_NRANGE = 5,
|
||||
T_PAREN = 6,
|
||||
T_EMPTY = 7,
|
||||
T_ANCHOR = 8,
|
||||
T_NONGREEDYCLOSURE = 9,
|
||||
T_STRING = 10,
|
||||
T_DOT = 11,
|
||||
T_BACKREFERENCE = 12
|
||||
} tokType;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
Token(const tokType tkType
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
||||
);
|
||||
virtual ~Token();
|
||||
|
||||
static const XMLInt32 UTF16_MAX;
|
||||
|
||||
typedef enum {
|
||||
FC_CONTINUE = 0,
|
||||
FC_TERMINAL = 1,
|
||||
FC_ANY = 2
|
||||
} firstCharacterOptions;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
tokType getTokenType() const;
|
||||
XMLSize_t getMinLength() const;
|
||||
int getMaxLength() const;
|
||||
virtual Token* getChild(const XMLSize_t index) const;
|
||||
virtual XMLSize_t size() const;
|
||||
virtual int getMin() const;
|
||||
virtual int getMax() const;
|
||||
virtual int getNoParen() const;
|
||||
virtual int getReferenceNo() const;
|
||||
virtual const XMLCh* getString() const;
|
||||
virtual XMLInt32 getChar() const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Setter methods
|
||||
// -----------------------------------------------------------------------
|
||||
void setTokenType(const tokType tokType);
|
||||
virtual void setMin(const int minVal);
|
||||
virtual void setMax(const int maxVal);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Range manipulation methods
|
||||
// -----------------------------------------------------------------------
|
||||
virtual void addRange(const XMLInt32 start, const XMLInt32 end);
|
||||
virtual void mergeRanges(const Token *const tok);
|
||||
virtual void sortRanges();
|
||||
virtual void compactRanges();
|
||||
virtual void subtractRanges(RangeToken* const tok);
|
||||
virtual void intersectRanges(RangeToken* const tok);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Putter methods
|
||||
// -----------------------------------------------------------------------
|
||||
virtual void addChild(Token* const child, TokenFactory* const tokFactory);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
firstCharacterOptions analyzeFirstCharacter(RangeToken* const rangeTok, const int options,
|
||||
TokenFactory* const tokFactory);
|
||||
Token* findFixedString(int options, int& outOptions);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
Token(const Token&);
|
||||
Token& operator=(const Token&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
bool isSet(const int options, const unsigned int flag);
|
||||
bool isShorterThan(Token* const tok);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
tokType fTokenType;
|
||||
protected:
|
||||
MemoryManager* const fMemoryManager;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline Token::tokType Token::getTokenType() const {
|
||||
|
||||
return fTokenType;
|
||||
}
|
||||
|
||||
inline XMLSize_t Token::size() const {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline Token* Token::getChild(const XMLSize_t) const {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int Token::getMin() const {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int Token::getMax() const {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int Token::getReferenceNo() const {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int Token::getNoParen() const {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline const XMLCh* Token::getString() const {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline XMLInt32 Token::getChar() const {
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void Token::setTokenType(const Token::tokType tokType) {
|
||||
|
||||
fTokenType = tokType;
|
||||
}
|
||||
|
||||
inline void Token::setMax(const int) {
|
||||
// ClosureToken
|
||||
}
|
||||
|
||||
inline void Token::setMin(const int) {
|
||||
// ClosureToken
|
||||
}
|
||||
|
||||
inline bool Token::isSet(const int options, const unsigned int flag) {
|
||||
|
||||
return (options & flag) == flag;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: setter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void Token::addChild(Token* const, TokenFactory* const) {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Token: Range manipulation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline void Token::addRange(const XMLInt32, const XMLInt32) {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void Token::mergeRanges(const Token *const) {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void Token::sortRanges() {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void Token::compactRanges() {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void Token::subtractRanges(RangeToken* const) {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
inline void Token::intersectRanges(RangeToken* const) {
|
||||
|
||||
ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_NotSupported, fMemoryManager);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file Token.hpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: TokenFactory.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/TokenInc.hpp>
|
||||
#include <xercesc/util/regx/XMLRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/ASCIIRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/UnicodeRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/BlockRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeTokenMap.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// TokenFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
TokenFactory::TokenFactory(MemoryManager* const manager) :
|
||||
fTokens(new (manager) RefVectorOf<Token> (16, true, manager))
|
||||
, fEmpty(0)
|
||||
, fLineBegin(0)
|
||||
, fLineEnd(0)
|
||||
, fDot(0)
|
||||
, fMemoryManager(manager)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
TokenFactory::~TokenFactory() {
|
||||
|
||||
delete fTokens;
|
||||
fTokens = 0;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// TokenFactory - Factory methods
|
||||
// ---------------------------------------------------------------------------
|
||||
Token* TokenFactory::createToken(const Token::tokType tkType) {
|
||||
|
||||
if (tkType == Token::T_EMPTY && fEmpty != 0)
|
||||
return fEmpty;
|
||||
|
||||
Token* tmpTok = new (fMemoryManager) Token(tkType, fMemoryManager);
|
||||
|
||||
if (tkType == Token::T_EMPTY) {
|
||||
fEmpty = tmpTok;
|
||||
}
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
|
||||
ParenToken* TokenFactory::createParenthesis(Token* const token,
|
||||
const int noGroups) {
|
||||
|
||||
ParenToken* tmpTok = new (fMemoryManager) ParenToken(Token::T_PAREN, token, noGroups, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
ClosureToken* TokenFactory::createClosure(Token* const token,
|
||||
bool isNonGreedy) {
|
||||
|
||||
ClosureToken* tmpTok = isNonGreedy ? new (fMemoryManager) ClosureToken(Token::T_NONGREEDYCLOSURE, token, fMemoryManager)
|
||||
: new (fMemoryManager) ClosureToken(Token::T_CLOSURE, token, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
ConcatToken* TokenFactory::createConcat(Token* const token1,
|
||||
Token* const token2) {
|
||||
|
||||
ConcatToken* tmpTok = new (fMemoryManager) ConcatToken(token1, token2, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
UnionToken* TokenFactory::createUnion(const bool isConcat) {
|
||||
|
||||
UnionToken* tmpTok = isConcat ? new (fMemoryManager) UnionToken(Token::T_CONCAT, fMemoryManager)
|
||||
: new (fMemoryManager) UnionToken(Token::T_UNION, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
RangeToken* TokenFactory::createRange(const bool isNegRange){
|
||||
|
||||
|
||||
RangeToken* tmpTok = isNegRange ? new (fMemoryManager) RangeToken(Token::T_NRANGE, fMemoryManager)
|
||||
: new (fMemoryManager) RangeToken(Token::T_RANGE, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
CharToken* TokenFactory::createChar(const XMLUInt32 ch, const bool isAnchor) {
|
||||
|
||||
CharToken* tmpTok = isAnchor ? new (fMemoryManager) CharToken(Token::T_ANCHOR, ch, fMemoryManager)
|
||||
: new (fMemoryManager) CharToken(Token::T_CHAR, ch, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
StringToken* TokenFactory::createBackReference(const int noRefs) {
|
||||
|
||||
StringToken* tmpTok = new (fMemoryManager) StringToken(Token::T_BACKREFERENCE, 0, noRefs, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
StringToken* TokenFactory::createString(const XMLCh* const literal) {
|
||||
|
||||
StringToken* tmpTok = new (fMemoryManager) StringToken(Token::T_STRING, literal, 0, fMemoryManager);
|
||||
|
||||
fTokens->addElement(tmpTok);
|
||||
return tmpTok;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// TokenFactory - Getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
RangeToken* TokenFactory::staticGetRange(const XMLCh* const keyword,
|
||||
const bool complement) {
|
||||
|
||||
return RangeTokenMap::instance()->getRange(keyword, complement);
|
||||
}
|
||||
|
||||
Token* TokenFactory::getLineBegin() {
|
||||
|
||||
if (fLineBegin == 0)
|
||||
fLineBegin = createChar(chCaret, true);
|
||||
|
||||
return fLineBegin;
|
||||
}
|
||||
|
||||
Token* TokenFactory::getLineEnd() {
|
||||
|
||||
if (fLineEnd == 0)
|
||||
fLineEnd = createChar(chDollarSign, true);
|
||||
|
||||
return fLineEnd;
|
||||
}
|
||||
|
||||
Token* TokenFactory::getDot() {
|
||||
|
||||
if (fDot == 0)
|
||||
fDot = createToken(Token::T_DOT);
|
||||
|
||||
return fDot;
|
||||
}
|
||||
|
||||
/*
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#if XERCES_USE_TRANSCODER_ICU
|
||||
#include <unicode/uchar.h>
|
||||
#endif
|
||||
|
||||
#include <stdio.h>
|
||||
void TokenFactory::printUnicode() {
|
||||
|
||||
#if XERCES_USE_TRANSCODER_ICU
|
||||
//
|
||||
// Write it out to a temp file to be read back into this source later.
|
||||
//
|
||||
printf("Printing\n");
|
||||
//sprintf(msg, "Printing\n");
|
||||
FILE* outFl = fopen("table.out", "wt+");
|
||||
fprintf(outFl, "const XMLByte fgUniCharsTable[0x10000] =\n{ ");
|
||||
for (unsigned int index = 0; index <= 0xFFFF; index += 16)
|
||||
{
|
||||
fprintf(outFl
|
||||
, " , 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X, 0x%02X\n"
|
||||
, (unsigned int)u_charType(index)
|
||||
, (unsigned int)u_charType(index+1)
|
||||
, (unsigned int)u_charType(index+2)
|
||||
, (unsigned int)u_charType(index+3)
|
||||
, (unsigned int)u_charType(index+4)
|
||||
, (unsigned int)u_charType(index+5)
|
||||
, (unsigned int)u_charType(index+6)
|
||||
, (unsigned int)u_charType(index+7)
|
||||
, (unsigned int)u_charType(index+8)
|
||||
, (unsigned int)u_charType(index+9)
|
||||
, (unsigned int)u_charType(index+10)
|
||||
, (unsigned int)u_charType(index+11)
|
||||
, (unsigned int)u_charType(index+12)
|
||||
, (unsigned int)u_charType(index+13)
|
||||
, (unsigned int)u_charType(index+14)
|
||||
, (unsigned int)u_charType(index+15));
|
||||
}
|
||||
fprintf(outFl, "};\n");
|
||||
|
||||
fclose(outFl);
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file TokenFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,134 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: TokenFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_TOKENFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_TOKENFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
#include <xercesc/util/Mutexes.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Forward Declaration
|
||||
// ---------------------------------------------------------------------------
|
||||
class RangeToken;
|
||||
class CharToken;
|
||||
class ClosureToken;
|
||||
class ConcatToken;
|
||||
class ParenToken;
|
||||
class StringToken;
|
||||
class UnionToken;
|
||||
|
||||
class XMLUTIL_EXPORT TokenFactory : public XMemory
|
||||
{
|
||||
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and destructors
|
||||
// -----------------------------------------------------------------------
|
||||
TokenFactory(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~TokenFactory();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Factory methods
|
||||
// -----------------------------------------------------------------------
|
||||
Token* createToken(const Token::tokType tkType);
|
||||
|
||||
ParenToken* createParenthesis(Token* const token, const int noGroups);
|
||||
ClosureToken* createClosure(Token* const token, bool isNonGreedy = false);
|
||||
ConcatToken* createConcat(Token* const token1, Token* const token2);
|
||||
UnionToken* createUnion(const bool isConcat = false);
|
||||
RangeToken* createRange(const bool isNegRange = false);
|
||||
CharToken* createChar(const XMLUInt32 ch, const bool isAnchor = false);
|
||||
StringToken* createBackReference(const int refNo);
|
||||
StringToken* createString(const XMLCh* const literal);
|
||||
|
||||
|
||||
//static void printUnicode();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
/*
|
||||
* Gets a commonly used RangeToken from the token registry based on the
|
||||
* range name.
|
||||
*/
|
||||
RangeToken* getRange(const XMLCh* const name,const bool complement=false);
|
||||
Token* getLineBegin();
|
||||
Token* getLineEnd();
|
||||
Token* getDot();
|
||||
MemoryManager* getMemoryManager() const;
|
||||
|
||||
static RangeToken* staticGetRange(const XMLCh* const name,const bool complement=false);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Notification that lazy data has been deleted
|
||||
// -----------------------------------------------------------------------
|
||||
static void reinitTokenFactoryMutex();
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
TokenFactory(const TokenFactory&);
|
||||
TokenFactory& operator=(const TokenFactory&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
//
|
||||
// fRangeInitialized
|
||||
// Indicates whether we have initialized the RangeFactory instance or
|
||||
// not
|
||||
//
|
||||
// fToken
|
||||
// Contains user created Token objects. Used for memory cleanup.
|
||||
// -----------------------------------------------------------------------
|
||||
RefVectorOf<Token>* fTokens;
|
||||
Token* fEmpty;
|
||||
Token* fLineBegin;
|
||||
Token* fLineEnd;
|
||||
Token* fDot;
|
||||
MemoryManager* fMemoryManager;
|
||||
};
|
||||
|
||||
inline RangeToken* TokenFactory::getRange(const XMLCh* const name,const bool complement)
|
||||
{
|
||||
return staticGetRange(name, complement);
|
||||
}
|
||||
|
||||
inline MemoryManager* TokenFactory::getMemoryManager() const
|
||||
{
|
||||
return fMemoryManager;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file TokenFactory
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: TokenInc.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_TOKENINC_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_TOKENINC_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/CharToken.hpp>
|
||||
#include <xercesc/util/regx/ClosureToken.hpp>
|
||||
#include <xercesc/util/regx/ConcatToken.hpp>
|
||||
#include <xercesc/util/regx/ParenToken.hpp>
|
||||
#include <xercesc/util/regx/StringToken.hpp>
|
||||
#include <xercesc/util/regx/UnionToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file TokenInc.hpp
|
||||
*/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: UnicodeRangeFactory.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/UnicodeRangeFactory.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/RangeTokenMap.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/regx/XMLUniCharacter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local data
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const XMLCh uniCategNames[][3] =
|
||||
{
|
||||
{chLatin_C, chLatin_n, chNull}, // UNASSIGNED
|
||||
{chLatin_L, chLatin_u, chNull}, // UPPERCASE_LETTER
|
||||
{chLatin_L, chLatin_l, chNull}, // LOWERCASE_LETTER
|
||||
{chLatin_L, chLatin_t, chNull}, // TITLECASE_LETTER
|
||||
{chLatin_L, chLatin_m, chNull}, // MODIFIER_LETTER
|
||||
{chLatin_L, chLatin_o, chNull}, // OTHER_LETTER
|
||||
{chLatin_M, chLatin_n, chNull}, // NON_SPACING_MARK
|
||||
{chLatin_M, chLatin_e, chNull}, // ENCLOSING_MARK
|
||||
{chLatin_M, chLatin_c, chNull}, // COMBINING_SPACING_MARK
|
||||
{chLatin_N, chLatin_d, chNull}, // DECIMAL_DIGIT_NUMBER
|
||||
{chLatin_N, chLatin_l, chNull}, // LETTER_NUMBER
|
||||
{chLatin_N, chLatin_o, chNull}, // OTHER_NUMBER
|
||||
{chLatin_Z, chLatin_s, chNull}, // SPACE_SEPARATOR
|
||||
{chLatin_Z, chLatin_l, chNull}, // LINE_SEPARATOR
|
||||
{chLatin_Z, chLatin_p, chNull}, // PARAGRAPH_SEPARATOR
|
||||
{chLatin_C, chLatin_c, chNull}, // CONTROL
|
||||
{chLatin_C, chLatin_f, chNull}, // FORMAT
|
||||
{chLatin_C, chLatin_o, chNull}, // PRIVATE_USE
|
||||
{chLatin_C, chLatin_s, chNull}, // SURROGATE
|
||||
{chLatin_P, chLatin_d, chNull}, // DASH_PUNCTUATION
|
||||
{chLatin_P, chLatin_s, chNull}, // START_PUNCTUATION
|
||||
{chLatin_P, chLatin_e, chNull}, // END_PUNCTUATION
|
||||
{chLatin_P, chLatin_c, chNull}, // CONNECTOR_PUNCTUATION
|
||||
{chLatin_P, chLatin_o, chNull}, // OTHER_PUNCTUATION
|
||||
{chLatin_S, chLatin_m, chNull}, // MATH_SYMBOL
|
||||
{chLatin_S, chLatin_c, chNull}, // CURRENCY_SYMBOL
|
||||
{chLatin_S, chLatin_k, chNull}, // MODIFIER_SYMBOL
|
||||
{chLatin_S, chLatin_o, chNull}, // OTHER_SYMBOL
|
||||
{chLatin_P, chLatin_i, chNull}, // INITIAL_PUNCTUATION
|
||||
{chLatin_P, chLatin_f, chNull}, // FINAL_PUNCTUATION
|
||||
{chLatin_L, chNull}, // CHAR_LETTER
|
||||
{chLatin_M, chNull}, // CHAR_MARK
|
||||
{chLatin_N, chNull}, // CHAR_NUMBER
|
||||
{chLatin_Z, chNull}, // CHAR_SEPARATOR
|
||||
{chLatin_C, chNull}, // CHAR_OTHER
|
||||
{chLatin_P, chNull}, // CHAR_PUNCTUATION
|
||||
{chLatin_S, chNull}, // CHAR_SYMBOL
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnicodeRangeFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
UnicodeRangeFactory::UnicodeRangeFactory()
|
||||
{
|
||||
}
|
||||
|
||||
UnicodeRangeFactory::~UnicodeRangeFactory() {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnicodeRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void UnicodeRangeFactory::buildRanges(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fRangesCreated)
|
||||
return;
|
||||
|
||||
if (!fKeywordsInitialized) {
|
||||
initializeKeywordMap(rangeTokMap);
|
||||
}
|
||||
|
||||
TokenFactory* tokFactory = rangeTokMap->getTokenFactory();
|
||||
RangeToken* ranges[UNICATEGSIZE];
|
||||
RangeToken* tok;
|
||||
|
||||
for (int i=0; i < UNICATEGSIZE; i++) {
|
||||
ranges[i] = tokFactory->createRange();
|
||||
}
|
||||
|
||||
for (int j=0; j < 0x10000; j++) {
|
||||
|
||||
unsigned short charType = XMLUniCharacter::getType(j);
|
||||
|
||||
ranges[charType]->addRange(j, j);
|
||||
charType = getUniCategory(charType);
|
||||
ranges[charType]->addRange(j, j);
|
||||
}
|
||||
|
||||
ranges[XMLUniCharacter::UNASSIGNED]->addRange(0x10000, Token::UTF16_MAX);
|
||||
|
||||
for (int k=0; k < UNICATEGSIZE; k++) {
|
||||
tok = RangeToken::complementRanges(ranges[k], tokFactory);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(uniCategNames[k], ranges[k]);
|
||||
rangeTokMap->setRangeToken(uniCategNames[k], tok , true);
|
||||
}
|
||||
|
||||
// Create all range
|
||||
tok = tokFactory->createRange();
|
||||
tok->addRange(0, Token::UTF16_MAX);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniAll, tok);
|
||||
|
||||
// Create alpha range
|
||||
tok = tokFactory->createRange();
|
||||
tok->mergeRanges(ranges[XMLUniCharacter::UPPERCASE_LETTER]);
|
||||
tok->mergeRanges(ranges[XMLUniCharacter::LOWERCASE_LETTER]);
|
||||
tok->mergeRanges(ranges[XMLUniCharacter::OTHER_LETTER]);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniIsAlpha, tok);
|
||||
|
||||
// Create alpha-num range
|
||||
RangeToken* alnumTok = tokFactory->createRange();
|
||||
alnumTok->mergeRanges(tok);
|
||||
alnumTok->mergeRanges(ranges[XMLUniCharacter::DECIMAL_DIGIT_NUMBER]);
|
||||
// build the internal map.
|
||||
alnumTok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniIsAlnum, alnumTok);
|
||||
|
||||
// Create word range
|
||||
tok = tokFactory->createRange();
|
||||
tok->mergeRanges(alnumTok);
|
||||
tok->addRange(chUnderscore, chUnderscore);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniIsWord, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniIsWord, tok , true);
|
||||
|
||||
// Create assigned range
|
||||
tok = RangeToken::complementRanges(
|
||||
ranges[XMLUniCharacter::UNASSIGNED],
|
||||
tokFactory,
|
||||
tokFactory->getMemoryManager());
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniAssigned,tok);
|
||||
|
||||
// Create space range
|
||||
tok = tokFactory->createRange();
|
||||
tok->mergeRanges(ranges[XMLUniCharacter::SPACE_SEPARATOR]);
|
||||
tok->mergeRanges(ranges[XMLUniCharacter::LINE_SEPARATOR]);
|
||||
//tok->mergeRanges(ranges[XMLUniCharacter::PARAGRAPH_SEPARATOR]);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniIsSpace, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgUniIsSpace, tok , true);
|
||||
|
||||
RangeToken* const dummyToken =
|
||||
tokFactory->createRange();
|
||||
|
||||
dummyToken->addRange(-1, -2);
|
||||
dummyToken->createMap();
|
||||
|
||||
// build the internal maps.
|
||||
for (int l=0; l < UNICATEGSIZE; l++) {
|
||||
ranges[l]->createMap();
|
||||
ranges[l]->setCaseInsensitiveToken(dummyToken);
|
||||
}
|
||||
|
||||
fRangesCreated = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnicodeRangeFactory: Initialization methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void UnicodeRangeFactory::initializeKeywordMap(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fKeywordsInitialized)
|
||||
return;
|
||||
|
||||
for (int k=0; k < UNICATEGSIZE; k++) {
|
||||
rangeTokMap->addKeywordMap(uniCategNames[k], fgUnicodeCategory);
|
||||
}
|
||||
|
||||
rangeTokMap->addKeywordMap(fgUniAll, fgUnicodeCategory);
|
||||
rangeTokMap->addKeywordMap(fgUniIsAlpha, fgUnicodeCategory);
|
||||
rangeTokMap->addKeywordMap(fgUniIsAlnum, fgUnicodeCategory);
|
||||
rangeTokMap->addKeywordMap(fgUniIsWord, fgUnicodeCategory);
|
||||
rangeTokMap->addKeywordMap(fgUniAssigned, fgUnicodeCategory);
|
||||
rangeTokMap->addKeywordMap(fgUniIsSpace, fgUnicodeCategory);
|
||||
|
||||
fKeywordsInitialized = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnicodeRangeFactory: Helper methods
|
||||
// ---------------------------------------------------------------------------
|
||||
unsigned short UnicodeRangeFactory::getUniCategory(const unsigned short type)
|
||||
{
|
||||
switch(type) {
|
||||
case XMLUniCharacter::UPPERCASE_LETTER:
|
||||
case XMLUniCharacter::LOWERCASE_LETTER:
|
||||
case XMLUniCharacter::TITLECASE_LETTER:
|
||||
case XMLUniCharacter::MODIFIER_LETTER:
|
||||
case XMLUniCharacter::OTHER_LETTER:
|
||||
return CHAR_LETTER;
|
||||
case XMLUniCharacter::NON_SPACING_MARK:
|
||||
case XMLUniCharacter::COMBINING_SPACING_MARK:
|
||||
case XMLUniCharacter::ENCLOSING_MARK:
|
||||
return CHAR_MARK;
|
||||
case XMLUniCharacter::DECIMAL_DIGIT_NUMBER:
|
||||
case XMLUniCharacter::LETTER_NUMBER:
|
||||
case XMLUniCharacter::OTHER_NUMBER:
|
||||
return CHAR_NUMBER;
|
||||
case XMLUniCharacter::SPACE_SEPARATOR:
|
||||
case XMLUniCharacter::LINE_SEPARATOR:
|
||||
case XMLUniCharacter::PARAGRAPH_SEPARATOR:
|
||||
return CHAR_SEPARATOR;
|
||||
case XMLUniCharacter::CONTROL:
|
||||
case XMLUniCharacter::FORMAT:
|
||||
case XMLUniCharacter::SURROGATE:
|
||||
case XMLUniCharacter::PRIVATE_USE:
|
||||
case XMLUniCharacter::UNASSIGNED:
|
||||
return CHAR_OTHER;
|
||||
case XMLUniCharacter::CONNECTOR_PUNCTUATION:
|
||||
case XMLUniCharacter::DASH_PUNCTUATION:
|
||||
case XMLUniCharacter::START_PUNCTUATION:
|
||||
case XMLUniCharacter::END_PUNCTUATION:
|
||||
case XMLUniCharacter::OTHER_PUNCTUATION:
|
||||
case XMLUniCharacter::INITIAL_PUNCTUATION:
|
||||
case XMLUniCharacter::FINAL_PUNCTUATION:
|
||||
return CHAR_PUNCTUATION;
|
||||
case XMLUniCharacter::MATH_SYMBOL:
|
||||
case XMLUniCharacter::CURRENCY_SYMBOL:
|
||||
case XMLUniCharacter::MODIFIER_SYMBOL:
|
||||
case XMLUniCharacter::OTHER_SYMBOL:
|
||||
return CHAR_SYMBOL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file UnicodeRangeFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: UnicodeRangeFactory.hpp 671870 2008-06-26 12:19:31Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_UNICODERANGEFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_UNICODERANGEFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeFactory.hpp>
|
||||
#include <xercesc/util/regx/XMLUniCharacter.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT UnicodeRangeFactory: public RangeFactory {
|
||||
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constants
|
||||
// -----------------------------------------------------------------------
|
||||
// Unicode categories
|
||||
enum {
|
||||
CHAR_LETTER = XMLUniCharacter::FINAL_PUNCTUATION+1,
|
||||
CHAR_MARK,
|
||||
CHAR_NUMBER,
|
||||
CHAR_SEPARATOR,
|
||||
CHAR_OTHER,
|
||||
CHAR_PUNCTUATION,
|
||||
CHAR_SYMBOL,
|
||||
UNICATEGSIZE
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
UnicodeRangeFactory();
|
||||
~UnicodeRangeFactory();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Initialization methods
|
||||
// -----------------------------------------------------------------------
|
||||
void initializeKeywordMap(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
static unsigned short getUniCategory(const unsigned short type);
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void buildRanges(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
UnicodeRangeFactory(const UnicodeRangeFactory&);
|
||||
UnicodeRangeFactory& operator=(const UnicodeRangeFactory&);
|
||||
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file UnicodeRangeFactory.hpp
|
||||
*/
|
||||
@@ -0,0 +1,149 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: UnionToken.cpp 678395 2008-07-21 11:40:41Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/UnionToken.hpp>
|
||||
#include <xercesc/framework/XMLBuffer.hpp>
|
||||
#include <xercesc/util/regx/RegxUtil.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/StringToken.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Static member data initialization
|
||||
// ---------------------------------------------------------------------------
|
||||
const unsigned short UnionToken::INITIALSIZE = 8;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnionToken: Constructors and Destructors
|
||||
// ---------------------------------------------------------------------------
|
||||
UnionToken::UnionToken(const Token::tokType tkType, MemoryManager* const manager)
|
||||
: Token(tkType, manager)
|
||||
, fChildren(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
UnionToken::~UnionToken() {
|
||||
|
||||
delete fChildren;
|
||||
}
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnionToken: Children manipulation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void UnionToken::addChild(Token* const child, TokenFactory* const tokFactory) {
|
||||
|
||||
if (child == 0)
|
||||
return;
|
||||
|
||||
if (fChildren == 0)
|
||||
fChildren = new (tokFactory->getMemoryManager()) RefVectorOf<Token>(INITIALSIZE, false, tokFactory->getMemoryManager());
|
||||
|
||||
if (getTokenType() == T_UNION) {
|
||||
|
||||
fChildren->addElement(child);
|
||||
return;
|
||||
}
|
||||
|
||||
Token::tokType childType = child->getTokenType();
|
||||
if (childType == T_CONCAT) {
|
||||
|
||||
XMLSize_t childSize = child->size();
|
||||
for (XMLSize_t i = 0; i < childSize; i++) {
|
||||
|
||||
addChild(child->getChild(i), tokFactory);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
XMLSize_t childrenSize = fChildren->size();
|
||||
if (childrenSize == 0) {
|
||||
|
||||
fChildren->addElement(child);
|
||||
return;
|
||||
}
|
||||
|
||||
Token* previousTok = fChildren->elementAt(childrenSize - 1);
|
||||
Token::tokType previousType = previousTok->getTokenType();
|
||||
|
||||
if (!((previousType == T_CHAR || previousType == T_STRING)
|
||||
&& (childType == T_CHAR || childType == T_STRING))) {
|
||||
|
||||
fChildren->addElement(child);
|
||||
return;
|
||||
}
|
||||
|
||||
// Continue
|
||||
XMLBuffer stringBuf(1023, tokFactory->getMemoryManager());
|
||||
|
||||
if (previousType == T_CHAR) {
|
||||
|
||||
XMLInt32 ch = previousTok->getChar();
|
||||
|
||||
if (ch >= 0x10000) {
|
||||
|
||||
XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager());
|
||||
stringBuf.append(chSurrogate);
|
||||
tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate;
|
||||
}
|
||||
else {
|
||||
stringBuf.append((XMLCh) ch);
|
||||
}
|
||||
|
||||
previousTok = tokFactory->createString(0);
|
||||
fChildren->setElementAt(previousTok, childrenSize - 1);
|
||||
}
|
||||
else {
|
||||
stringBuf.append(previousTok->getString());
|
||||
}
|
||||
|
||||
if (childType == T_CHAR) {
|
||||
|
||||
XMLInt32 ch = child->getChar();
|
||||
|
||||
if (ch >= 0x10000) {
|
||||
|
||||
XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager());
|
||||
stringBuf.append(chSurrogate);
|
||||
tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate;
|
||||
}
|
||||
else {
|
||||
stringBuf.append((XMLCh) ch);
|
||||
}
|
||||
}
|
||||
else {
|
||||
stringBuf.append(child->getString());
|
||||
}
|
||||
|
||||
((StringToken*) previousTok)->setString(stringBuf.getRawBuffer());
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file UnionToken.cpp
|
||||
*/
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: UnionToken.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_UNIONTOKEN_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_UNIONTOKEN_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/Token.hpp>
|
||||
#include <xercesc/util/RefVectorOf.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT UnionToken : public Token {
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constructors and Destructor
|
||||
// -----------------------------------------------------------------------
|
||||
UnionToken(const tokType tkType
|
||||
, MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
||||
~UnionToken();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Getter methods
|
||||
// -----------------------------------------------------------------------
|
||||
XMLSize_t size() const;
|
||||
Token* getChild(const XMLSize_t index) const;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Children manipulation methods
|
||||
// -----------------------------------------------------------------------
|
||||
void addChild(Token* const child, TokenFactory* const tokFactory);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
UnionToken(const UnionToken&);
|
||||
UnionToken& operator=(const UnionToken&);
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private Constants
|
||||
// -----------------------------------------------------------------------
|
||||
static const unsigned short INITIALSIZE;
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Private data members
|
||||
// -----------------------------------------------------------------------
|
||||
RefVectorOf<Token>* fChildren;
|
||||
};
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// UnionToken: getter methods
|
||||
// ---------------------------------------------------------------------------
|
||||
inline XMLSize_t UnionToken::size() const {
|
||||
|
||||
return fChildren == 0 ? 0 : fChildren->size();
|
||||
}
|
||||
|
||||
inline Token* UnionToken::getChild(const XMLSize_t index) const {
|
||||
|
||||
return fChildren->elementAt(index);
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file UnionToken.hpp
|
||||
*/
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: XMLRangeFactory.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/XMLRangeFactory.hpp>
|
||||
#include <xercesc/internal/CharTypeTables.hpp>
|
||||
#include <xercesc/util/regx/RegxDefs.hpp>
|
||||
#include <xercesc/util/regx/TokenFactory.hpp>
|
||||
#include <xercesc/util/regx/RangeToken.hpp>
|
||||
#include <xercesc/util/regx/RangeTokenMap.hpp>
|
||||
#include <xercesc/util/regx/UnicodeRangeFactory.hpp>
|
||||
#include <xercesc/util/Janitor.hpp>
|
||||
#include <string.h>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Local static functions
|
||||
// ---------------------------------------------------------------------------
|
||||
static void setupRange(XMLInt32* const rangeMap,
|
||||
const XMLCh* const theTable,
|
||||
unsigned int startingIndex) {
|
||||
|
||||
const XMLCh* pchCur = theTable;
|
||||
|
||||
// Do the ranges first
|
||||
while (*pchCur)
|
||||
{
|
||||
rangeMap[startingIndex++] = *pchCur++;
|
||||
}
|
||||
|
||||
// Skip the range terminator
|
||||
pchCur++;
|
||||
|
||||
// And then the singles until we hit its terminator
|
||||
while (*pchCur) {
|
||||
|
||||
const XMLCh chSingle = *pchCur++;
|
||||
rangeMap[startingIndex++] = chSingle;
|
||||
rangeMap[startingIndex++] = chSingle;
|
||||
}
|
||||
}
|
||||
|
||||
static unsigned int getTableLen(const XMLCh* const theTable) {
|
||||
|
||||
XMLSize_t rangeLen = XMLString::stringLen(theTable);
|
||||
|
||||
return (unsigned int)(rangeLen + 2*XMLString::stringLen(theTable + rangeLen + 1));
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRangeFactory: Constructors and Destructor
|
||||
// ---------------------------------------------------------------------------
|
||||
XMLRangeFactory::XMLRangeFactory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
XMLRangeFactory::~XMLRangeFactory() {
|
||||
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLRangeFactory::buildRanges(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fRangesCreated)
|
||||
return;
|
||||
|
||||
if (!fKeywordsInitialized) {
|
||||
initializeKeywordMap(rangeTokMap);
|
||||
}
|
||||
|
||||
TokenFactory* tokFactory = rangeTokMap->getTokenFactory();
|
||||
|
||||
// Create space ranges
|
||||
unsigned int wsTblLen = getTableLen(gWhitespaceChars);
|
||||
RangeToken* tok = tokFactory->createRange();
|
||||
XMLInt32* wsRange = (XMLInt32*) XMLPlatformUtils::fgMemoryManager->allocate
|
||||
(
|
||||
wsTblLen * sizeof(XMLInt32)
|
||||
);//new XMLInt32[wsTblLen];
|
||||
|
||||
tok->setRangeValues(wsRange, wsTblLen);
|
||||
setupRange(wsRange, gWhitespaceChars, 0);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLSpace, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLSpace, tok , true);
|
||||
|
||||
// Create digits ranges
|
||||
tok = tokFactory->createRange();
|
||||
unsigned int digitTblLen = getTableLen(gDigitChars);
|
||||
XMLInt32* digitRange = (XMLInt32*) XMLPlatformUtils::fgMemoryManager->allocate
|
||||
(
|
||||
digitTblLen * sizeof(XMLInt32)
|
||||
);//new XMLInt32[digitTblLen];
|
||||
|
||||
tok->setRangeValues(digitRange, digitTblLen);
|
||||
setupRange(digitRange, gDigitChars, 0);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLDigit, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLDigit, tok , true);
|
||||
|
||||
// Build word ranges
|
||||
unsigned int baseTblLen = getTableLen(gBaseChars);
|
||||
unsigned int ideoTblLen = getTableLen(gIdeographicChars);
|
||||
unsigned int wordRangeLen = baseTblLen + ideoTblLen + digitTblLen;
|
||||
XMLInt32* wordRange = (XMLInt32*) XMLPlatformUtils::fgMemoryManager->allocate
|
||||
(
|
||||
wordRangeLen * sizeof(XMLInt32)
|
||||
);//new XMLInt32[wordRangeLen];
|
||||
ArrayJanitor<XMLInt32> janWordRange(wordRange, XMLPlatformUtils::fgMemoryManager);
|
||||
|
||||
setupRange(wordRange, gBaseChars, 0);
|
||||
setupRange(wordRange, gIdeographicChars, baseTblLen);
|
||||
memcpy(wordRange + baseTblLen + ideoTblLen, digitRange, digitTblLen * sizeof(XMLInt32));
|
||||
|
||||
// Create NameChar ranges
|
||||
tok = tokFactory->createRange();
|
||||
unsigned int combTblLen = getTableLen(gCombiningChars);
|
||||
unsigned int extTblLen = getTableLen(gExtenderChars);
|
||||
unsigned int nameTblLen = wordRangeLen + combTblLen + extTblLen;
|
||||
XMLInt32* nameRange = (XMLInt32*) XMLPlatformUtils::fgMemoryManager->allocate
|
||||
(
|
||||
(nameTblLen + 8) * sizeof(XMLInt32)
|
||||
);//new XMLInt32[nameTblLen + 8];
|
||||
|
||||
tok->setRangeValues(nameRange, nameTblLen + 8);
|
||||
memcpy(nameRange, wordRange, wordRangeLen * sizeof(XMLInt32));
|
||||
setupRange(nameRange, gCombiningChars, wordRangeLen);
|
||||
setupRange(nameRange, gExtenderChars, wordRangeLen + combTblLen);
|
||||
nameRange[nameTblLen++] = chDash;
|
||||
nameRange[nameTblLen++] = chDash;
|
||||
nameRange[nameTblLen++] = chColon;
|
||||
nameRange[nameTblLen++] = chColon;
|
||||
nameRange[nameTblLen++] = chPeriod;
|
||||
nameRange[nameTblLen++] = chPeriod;
|
||||
nameRange[nameTblLen++] = chUnderscore;
|
||||
nameRange[nameTblLen++] = chUnderscore;
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLNameChar, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLNameChar, tok , true);
|
||||
|
||||
// Create initialNameChar ranges
|
||||
tok = tokFactory->createRange();
|
||||
unsigned int initialNameTblLen = baseTblLen + ideoTblLen;
|
||||
XMLInt32* initialNameRange = (XMLInt32*) XMLPlatformUtils::fgMemoryManager->allocate
|
||||
(
|
||||
(initialNameTblLen + 4) * sizeof(XMLInt32)
|
||||
);//new XMLInt32[initialNameTblLen + 4];
|
||||
|
||||
tok->setRangeValues(initialNameRange, initialNameTblLen + 4);
|
||||
memcpy(initialNameRange, wordRange, initialNameTblLen * sizeof(XMLInt32));
|
||||
initialNameRange[initialNameTblLen++] = chColon;
|
||||
initialNameRange[initialNameTblLen++] = chColon;
|
||||
initialNameRange[initialNameTblLen++] = chUnderscore;
|
||||
initialNameRange[initialNameTblLen++] = chUnderscore;
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLInitialNameChar, tok);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLInitialNameChar, tok , true);
|
||||
|
||||
// Create word range
|
||||
// \w = [#x0000-#x10FFFF]-[\p{P}\p{Z}\p{C}] (all characters except the set of "punctuation", "separator" and "other" characters)
|
||||
tok = tokFactory->createRange();
|
||||
for(int i=0; i<=0xFFFF; i++)
|
||||
{
|
||||
unsigned short chType=UnicodeRangeFactory::getUniCategory(XMLUniCharacter::getType(i));
|
||||
if(chType == UnicodeRangeFactory::CHAR_PUNCTUATION ||
|
||||
chType == UnicodeRangeFactory::CHAR_SEPARATOR ||
|
||||
chType == UnicodeRangeFactory::CHAR_OTHER)
|
||||
tok->addRange(i, i);
|
||||
}
|
||||
tok->sortRanges();
|
||||
tok->compactRanges();
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLWord, tok , true);
|
||||
|
||||
tok = RangeToken::complementRanges(tok, tokFactory);
|
||||
// Build the internal map.
|
||||
tok->createMap();
|
||||
rangeTokMap->setRangeToken(fgXMLWord, tok);
|
||||
|
||||
|
||||
fRangesCreated = true;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLRangeFactory: Range creation methods
|
||||
// ---------------------------------------------------------------------------
|
||||
void XMLRangeFactory::initializeKeywordMap(RangeTokenMap *rangeTokMap) {
|
||||
|
||||
if (fKeywordsInitialized)
|
||||
return;
|
||||
|
||||
rangeTokMap->addKeywordMap(fgXMLSpace, fgXMLCategory);
|
||||
rangeTokMap->addKeywordMap(fgXMLDigit, fgXMLCategory);
|
||||
rangeTokMap->addKeywordMap(fgXMLWord, fgXMLCategory);
|
||||
rangeTokMap->addKeywordMap(fgXMLNameChar, fgXMLCategory);
|
||||
rangeTokMap->addKeywordMap(fgXMLInitialNameChar, fgXMLCategory);
|
||||
|
||||
fKeywordsInitialized = true;
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file XMLRangeFactory.cpp
|
||||
*/
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: XMLRangeFactory.hpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLRANGEFACTORY_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLRANGEFACTORY_HPP
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#include <xercesc/util/regx/RangeFactory.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
class XMLUTIL_EXPORT XMLRangeFactory: public RangeFactory {
|
||||
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLRangeFactory();
|
||||
~XMLRangeFactory();
|
||||
|
||||
// -----------------------------------------------------------------------
|
||||
// Initialization methods
|
||||
// -----------------------------------------------------------------------
|
||||
void initializeKeywordMap(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
protected:
|
||||
// -----------------------------------------------------------------------
|
||||
// Protected Helper methods
|
||||
// -----------------------------------------------------------------------
|
||||
void buildRanges(RangeTokenMap *rangeTokMap = 0);
|
||||
|
||||
private:
|
||||
// -----------------------------------------------------------------------
|
||||
// Unimplemented constructors and operators
|
||||
// -----------------------------------------------------------------------
|
||||
XMLRangeFactory(const XMLRangeFactory&);
|
||||
XMLRangeFactory& operator=(const XMLRangeFactory&);
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End file XMLRangeFactory.hpp
|
||||
*/
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: XMLUniCharacter.cpp 678879 2008-07-22 20:05:05Z amassari $
|
||||
*/
|
||||
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Includes
|
||||
// ---------------------------------------------------------------------------
|
||||
#if HAVE_CONFIG_H
|
||||
# include <config.h>
|
||||
#endif
|
||||
|
||||
#include <xercesc/util/regx/XMLUniCharacter.hpp>
|
||||
|
||||
#if XERCES_USE_TRANSCODER_ICU
|
||||
#include <unicode/uchar.h>
|
||||
#else
|
||||
#include <xercesc/util/regx/UniCharTable.hpp>
|
||||
#endif
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// XMLUniCharacter: Public static methods
|
||||
// ---------------------------------------------------------------------------
|
||||
unsigned short XMLUniCharacter::getType(const XMLCh ch) {
|
||||
|
||||
#if XERCES_USE_TRANSCODER_ICU
|
||||
return (unsigned short) u_charType(ch);
|
||||
#else
|
||||
return (unsigned short) fgUniCharsTable[ch];
|
||||
#endif
|
||||
}
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
/**
|
||||
* End of file XMLUniCharacter.cpp
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You under the Apache License, Version 2.0
|
||||
* (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/*
|
||||
* $Id: XMLUniCharacter.hpp 671870 2008-06-26 12:19:31Z amassari $
|
||||
*/
|
||||
|
||||
#if !defined(XERCESC_INCLUDE_GUARD_XMLUNICHARACTER_HPP)
|
||||
#define XERCESC_INCLUDE_GUARD_XMLUNICHARACTER_HPP
|
||||
|
||||
#include <xercesc/util/XercesDefs.hpp>
|
||||
|
||||
XERCES_CPP_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* Class for representing unicode characters
|
||||
*/
|
||||
class XMLUTIL_EXPORT XMLUniCharacter
|
||||
{
|
||||
public:
|
||||
// -----------------------------------------------------------------------
|
||||
// Public Constants
|
||||
// -----------------------------------------------------------------------
|
||||
// Unicode char types
|
||||
enum {
|
||||
UNASSIGNED = 0,
|
||||
UPPERCASE_LETTER = 1,
|
||||
LOWERCASE_LETTER = 2,
|
||||
TITLECASE_LETTER = 3,
|
||||
MODIFIER_LETTER = 4,
|
||||
OTHER_LETTER = 5,
|
||||
NON_SPACING_MARK = 6,
|
||||
ENCLOSING_MARK = 7,
|
||||
COMBINING_SPACING_MARK = 8,
|
||||
DECIMAL_DIGIT_NUMBER = 9,
|
||||
LETTER_NUMBER = 10,
|
||||
OTHER_NUMBER = 11,
|
||||
SPACE_SEPARATOR = 12,
|
||||
LINE_SEPARATOR = 13,
|
||||
PARAGRAPH_SEPARATOR = 14,
|
||||
CONTROL = 15,
|
||||
FORMAT = 16,
|
||||
PRIVATE_USE = 17,
|
||||
SURROGATE = 18,
|
||||
DASH_PUNCTUATION = 19,
|
||||
START_PUNCTUATION = 20,
|
||||
END_PUNCTUATION = 21,
|
||||
CONNECTOR_PUNCTUATION = 22,
|
||||
OTHER_PUNCTUATION = 23,
|
||||
MATH_SYMBOL = 24,
|
||||
CURRENCY_SYMBOL = 25,
|
||||
MODIFIER_SYMBOL = 26,
|
||||
OTHER_SYMBOL = 27,
|
||||
INITIAL_PUNCTUATION = 28,
|
||||
FINAL_PUNCTUATION = 29
|
||||
};
|
||||
|
||||
/** destructor */
|
||||
~XMLUniCharacter() {}
|
||||
|
||||
/* Static methods for getting unicode character type */
|
||||
/** @name Getter functions */
|
||||
//@{
|
||||
|
||||
/** Gets the unicode type of a given character
|
||||
*
|
||||
* @param ch The character we want to get its unicode type
|
||||
*/
|
||||
static unsigned short getType(const XMLCh ch);
|
||||
//@}
|
||||
|
||||
private :
|
||||
|
||||
/** @name Constructors and Destructor */
|
||||
//@{
|
||||
/** Unimplemented default constructor */
|
||||
XMLUniCharacter();
|
||||
//@}
|
||||
};
|
||||
|
||||
XERCES_CPP_NAMESPACE_END
|
||||
|
||||
#endif
|
||||
|
||||
/**
|
||||
* End of file XMLUniCharacter.hpp
|
||||
*/
|
||||
Reference in New Issue
Block a user