Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:15:01

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one or more
0003  * contributor license agreements.  See the NOTICE file distributed with
0004  * this work for additional information regarding copyright ownership.
0005  * The ASF licenses this file to You under the Apache License, Version 2.0
0006  * (the "License"); you may not use this file except in compliance with
0007  * the License.  You may obtain a copy of the License at
0008  * 
0009  *      http://www.apache.org/licenses/LICENSE-2.0
0010  * 
0011  * Unless required by applicable law or agreed to in writing, software
0012  * distributed under the License is distributed on an "AS IS" BASIS,
0013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0014  * See the License for the specific language governing permissions and
0015  * limitations under the License.
0016  */
0017 
0018 /*
0019  * $Id$
0020  */
0021 
0022 #if !defined(XERCESC_INCLUDE_GUARD_MATCH_HPP)
0023 #define XERCESC_INCLUDE_GUARD_MATCH_HPP
0024 
0025 // ---------------------------------------------------------------------------
0026 //  Includes
0027 // ---------------------------------------------------------------------------
0028 #include <xercesc/util/PlatformUtils.hpp>
0029 #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
0030 #include <xercesc/util/RuntimeException.hpp>
0031 
0032 XERCES_CPP_NAMESPACE_BEGIN
0033 
0034 /**
0035   * An instance of this class has ranges captured in matching
0036   */
0037   class XMLUTIL_EXPORT Match : public XMemory
0038 {
0039 public:
0040 
0041     // -----------------------------------------------------------------------
0042     //  Public Constructors and Destructor
0043     // -----------------------------------------------------------------------
0044     Match(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
0045     
0046     /**
0047     * Copy constructor
0048     */
0049     Match(const Match& toCopy);
0050     Match& operator=(const Match& toAssign);
0051 
0052     virtual ~Match();
0053 
0054     // -----------------------------------------------------------------------
0055     // Getter functions
0056     // -----------------------------------------------------------------------
0057     int getNoGroups() const;
0058     int getStartPos(int index) const;
0059     int getEndPos(int index) const;
0060 
0061     // -----------------------------------------------------------------------
0062     // Setter functions
0063     // -----------------------------------------------------------------------
0064     void setNoGroups(const int n);
0065     void setStartPos(const int index, const int value);
0066     void setEndPos(const int index, const int value);
0067 
0068 private:
0069     // -----------------------------------------------------------------------
0070     // Initialize/Clean up methods
0071     // -----------------------------------------------------------------------
0072     void initialize(const Match& toCopy);
0073     void cleanUp();
0074 
0075     // -----------------------------------------------------------------------
0076     //  Private data members
0077     //
0078     //  fNoGroups
0079     //  Represents no of regular expression groups
0080     //        
0081     //  fStartPositions
0082     //  Array of start positions in the target text matched to specific
0083     //        regular expression group
0084     //
0085     //    fEndPositions
0086     //        Array of end positions in the target text matched to specific
0087     //        regular expression group
0088     //
0089     //    fPositionsSize
0090     //        Actual size of Start/EndPositions array.
0091     // -----------------------------------------------------------------------
0092     int fNoGroups;
0093     int fPositionsSize;
0094     int* fStartPositions;
0095     int* fEndPositions;
0096     MemoryManager* fMemoryManager;
0097 };
0098 
0099 /**
0100   * Inline Methods
0101   */
0102 
0103 // ---------------------------------------------------------------------------
0104 //  Match: getter methods
0105 // ---------------------------------------------------------------------------
0106 inline int Match::getNoGroups() const {
0107 
0108     if (fNoGroups < 0)
0109         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
0110 
0111     return fNoGroups;
0112 }
0113 
0114 inline int Match::getStartPos(int index) const {
0115 
0116     if (!fStartPositions)
0117         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
0118 
0119     if (index < 0 || fNoGroups <= index)
0120         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0121 
0122     return fStartPositions[index];
0123 }
0124 
0125 inline int Match::getEndPos(int index) const {
0126 
0127     if (!fEndPositions)
0128         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
0129 
0130     if (index < 0 || fNoGroups <= index)
0131         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0132 
0133     return fEndPositions[index];
0134 }
0135 
0136 // ---------------------------------------------------------------------------
0137 //  Match: setter methods
0138 // ---------------------------------------------------------------------------
0139 inline void Match::setStartPos(const int index, const int value) {
0140 
0141     if (!fStartPositions)
0142         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
0143 
0144     if (index < 0 || fNoGroups <= index)
0145         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0146 
0147     fStartPositions[index] = value;
0148 }
0149 
0150 inline void Match::setEndPos(const int index, const int value) {
0151 
0152     if (!fEndPositions)
0153         ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
0154 
0155     if (index < 0 || fNoGroups <= index)
0156         ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
0157 
0158     fEndPositions[index] = value;
0159 }
0160 
0161 XERCES_CPP_NAMESPACE_END
0162 
0163 #endif