GME
13
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 00018 /* 00019 * $Id: ASCIIRangeFactory.cpp 678879 2008-07-22 20:05:05Z amassari $ 00020 */ 00021 00022 // --------------------------------------------------------------------------- 00023 // Includes 00024 // --------------------------------------------------------------------------- 00025 #include <xercesc/util/regx/ASCIIRangeFactory.hpp> 00026 #include <xercesc/util/regx/RegxDefs.hpp> 00027 #include <xercesc/util/regx/TokenFactory.hpp> 00028 #include <xercesc/util/regx/RangeToken.hpp> 00029 #include <xercesc/util/regx/RangeTokenMap.hpp> 00030 00031 XERCES_CPP_NAMESPACE_BEGIN 00032 00033 // --------------------------------------------------------------------------- 00034 // ASCIIRangeFactory: Constructors and Destructor 00035 // --------------------------------------------------------------------------- 00036 ASCIIRangeFactory::ASCIIRangeFactory() 00037 { 00038 } 00039 00040 ASCIIRangeFactory::~ASCIIRangeFactory() { 00041 00042 } 00043 00044 // --------------------------------------------------------------------------- 00045 // ASCIIRangeFactory: Range creation methods 00046 // --------------------------------------------------------------------------- 00047 void ASCIIRangeFactory::buildRanges(RangeTokenMap *rangeTokMap) { 00048 00049 if (fRangesCreated) 00050 return; 00051 00052 if (!fKeywordsInitialized) { 00053 initializeKeywordMap(rangeTokMap); 00054 } 00055 00056 TokenFactory* tokFactory = rangeTokMap->getTokenFactory(); 00057 00058 // Create space ranges 00059 RangeToken* tok = tokFactory->createRange(); 00060 tok->addRange(chHTab, chHTab); 00061 tok->addRange(chLF, chLF); 00062 tok->addRange(chFF, chFF); 00063 tok->addRange(chCR, chCR); 00064 tok->addRange(chSpace, chSpace); 00065 00066 // Build the internal map. 00067 tok->createMap(); 00068 00069 rangeTokMap->setRangeToken(fgASCIISpace, tok); 00070 00071 tok = RangeToken::complementRanges(tok, tokFactory); 00072 00073 // Build the internal map. 00074 tok->createMap(); 00075 00076 rangeTokMap->setRangeToken(fgASCIISpace, tok , true); 00077 00078 // Create digits ranges 00079 tok = tokFactory->createRange(); 00080 tok->addRange(chDigit_0, chDigit_9); 00081 00082 // Build the internal map. 00083 tok->createMap(); 00084 00085 rangeTokMap->setRangeToken(fgASCIIDigit, tok); 00086 00087 tok = RangeToken::complementRanges(tok, tokFactory); 00088 00089 // Build the internal map. 00090 tok->createMap(); 00091 00092 rangeTokMap->setRangeToken(fgASCIIDigit, tok , true); 00093 00094 // Create word ranges 00095 tok = tokFactory->createRange(); 00096 tok->addRange(chDigit_0, chDigit_9); 00097 tok->addRange(chLatin_A, chLatin_Z); 00098 tok->addRange(chUnderscore, chUnderscore); 00099 tok->addRange(chLatin_a, chLatin_z); 00100 // Build the internal map. 00101 tok->createMap(); 00102 rangeTokMap->setRangeToken(fgASCIIWord, tok); 00103 00104 tok = RangeToken::complementRanges(tok, tokFactory); 00105 // Build the internal map. 00106 tok->createMap(); 00107 rangeTokMap->setRangeToken(fgASCIIWord, tok , true); 00108 00109 // Create xdigit ranges 00110 tok = tokFactory->createRange(); 00111 tok->addRange(chDigit_0, chDigit_9); 00112 tok->addRange(chLatin_A, chLatin_F); 00113 tok->addRange(chLatin_a, chLatin_a); 00114 // Build the internal map. 00115 tok->createMap(); 00116 00117 rangeTokMap->setRangeToken(fgASCIIXDigit, tok); 00118 00119 tok = RangeToken::complementRanges(tok, tokFactory); 00120 // Build the internal map. 00121 tok->createMap(); 00122 rangeTokMap->setRangeToken(fgASCIIXDigit, tok , true); 00123 00124 // Create ascii ranges 00125 tok = tokFactory->createRange(); 00126 tok->addRange(0x00, 0x7F); 00127 // Build the internal map. 00128 tok->createMap(); 00129 rangeTokMap->setRangeToken(fgASCII, tok); 00130 00131 tok = RangeToken::complementRanges(tok, tokFactory); 00132 // Build the internal map. 00133 tok->createMap(); 00134 rangeTokMap->setRangeToken(fgASCII, tok , true); 00135 00136 fRangesCreated = true; 00137 } 00138 00139 // --------------------------------------------------------------------------- 00140 // ASCIIRangeFactory: Range creation methods 00141 // --------------------------------------------------------------------------- 00142 void ASCIIRangeFactory::initializeKeywordMap(RangeTokenMap *rangeTokMap) { 00143 00144 if (fKeywordsInitialized) 00145 return; 00146 00147 rangeTokMap->addKeywordMap(fgASCIISpace, fgASCIICategory); 00148 rangeTokMap->addKeywordMap(fgASCIIDigit, fgASCIICategory); 00149 rangeTokMap->addKeywordMap(fgASCIIWord, fgASCIICategory); 00150 rangeTokMap->addKeywordMap(fgASCIIXDigit, fgASCIICategory); 00151 rangeTokMap->addKeywordMap(fgASCII, fgASCIICategory); 00152 00153 fKeywordsInitialized = true; 00154 } 00155 00156 XERCES_CPP_NAMESPACE_END 00157