1 | /*
|
---|
2 | * Copyright 2001,2004 The Apache Software Foundation.
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 |
|
---|
17 | /*
|
---|
18 | * $Id: Match.hpp,v 1.8 2004/09/08 13:56:47 peiyongz Exp $
|
---|
19 | */
|
---|
20 |
|
---|
21 | #if !defined(MATCH_HPP)
|
---|
22 | #define MATCH_HPP
|
---|
23 |
|
---|
24 | // ---------------------------------------------------------------------------
|
---|
25 | // Includes
|
---|
26 | // ---------------------------------------------------------------------------
|
---|
27 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
28 | #include <xercesc/util/ArrayIndexOutOfBoundsException.hpp>
|
---|
29 | #include <xercesc/util/RuntimeException.hpp>
|
---|
30 |
|
---|
31 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * An instance of this class has ranges captured in matching
|
---|
35 | */
|
---|
36 | class XMLUTIL_EXPORT Match : public XMemory
|
---|
37 | {
|
---|
38 | public:
|
---|
39 |
|
---|
40 | // -----------------------------------------------------------------------
|
---|
41 | // Public Constructors and Destructor
|
---|
42 | // -----------------------------------------------------------------------
|
---|
43 | Match(MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Copy constructor
|
---|
47 | */
|
---|
48 | Match(const Match& toCopy);
|
---|
49 | Match& operator=(const Match& toAssign);
|
---|
50 |
|
---|
51 | virtual ~Match();
|
---|
52 |
|
---|
53 | // -----------------------------------------------------------------------
|
---|
54 | // Getter functions
|
---|
55 | // -----------------------------------------------------------------------
|
---|
56 | int getNoGroups() const;
|
---|
57 | int getStartPos(int index) const;
|
---|
58 | int getEndPos(int index) const;
|
---|
59 |
|
---|
60 | // -----------------------------------------------------------------------
|
---|
61 | // Setter functions
|
---|
62 | // -----------------------------------------------------------------------
|
---|
63 | void setNoGroups(const int n);
|
---|
64 | void setStartPos(const int index, const int value);
|
---|
65 | void setEndPos(const int index, const int value);
|
---|
66 |
|
---|
67 | private:
|
---|
68 | // -----------------------------------------------------------------------
|
---|
69 | // Initialize/Clean up methods
|
---|
70 | // -----------------------------------------------------------------------
|
---|
71 | void initialize(const Match& toCopy);
|
---|
72 | void cleanUp();
|
---|
73 |
|
---|
74 | // -----------------------------------------------------------------------
|
---|
75 | // Private data members
|
---|
76 | //
|
---|
77 | // fNoGroups
|
---|
78 | // Represents no of regular expression groups
|
---|
79 | //
|
---|
80 | // fStartPositions
|
---|
81 | // Array of start positions in the target text matched to specific
|
---|
82 | // regular expression group
|
---|
83 | //
|
---|
84 | // fEndPositions
|
---|
85 | // Array of end positions in the target text matched to specific
|
---|
86 | // regular expression group
|
---|
87 | //
|
---|
88 | // fPositionsSize
|
---|
89 | // Actual size of Start/EndPositions array.
|
---|
90 | // -----------------------------------------------------------------------
|
---|
91 | int fNoGroups;
|
---|
92 | int fPositionsSize;
|
---|
93 | int* fStartPositions;
|
---|
94 | int* fEndPositions;
|
---|
95 | MemoryManager* fMemoryManager;
|
---|
96 | };
|
---|
97 |
|
---|
98 | /**
|
---|
99 | * Inline Methods
|
---|
100 | */
|
---|
101 |
|
---|
102 | // ---------------------------------------------------------------------------
|
---|
103 | // Match: getter methods
|
---|
104 | // ---------------------------------------------------------------------------
|
---|
105 | inline int Match::getNoGroups() const {
|
---|
106 |
|
---|
107 | if (fNoGroups < 0)
|
---|
108 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
---|
109 |
|
---|
110 | return fNoGroups;
|
---|
111 | }
|
---|
112 |
|
---|
113 | inline int Match::getStartPos(int index) const {
|
---|
114 |
|
---|
115 | if (!fStartPositions)
|
---|
116 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
---|
117 |
|
---|
118 | if (index < 0 || fNoGroups <= index)
|
---|
119 | ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
---|
120 |
|
---|
121 | return fStartPositions[index];
|
---|
122 | }
|
---|
123 |
|
---|
124 | inline int Match::getEndPos(int index) const {
|
---|
125 |
|
---|
126 | if (!fEndPositions)
|
---|
127 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
---|
128 |
|
---|
129 | if (index < 0 || fNoGroups <= index)
|
---|
130 | ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
---|
131 |
|
---|
132 | return fEndPositions[index];
|
---|
133 | }
|
---|
134 |
|
---|
135 | // ---------------------------------------------------------------------------
|
---|
136 | // Match: setter methods
|
---|
137 | // ---------------------------------------------------------------------------
|
---|
138 | inline void Match::setStartPos(const int index, const int value) {
|
---|
139 |
|
---|
140 | if (!fStartPositions)
|
---|
141 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
---|
142 |
|
---|
143 | if (index < 0 || fNoGroups <= index)
|
---|
144 | ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
---|
145 |
|
---|
146 | fStartPositions[index] = value;
|
---|
147 | }
|
---|
148 |
|
---|
149 | inline void Match::setEndPos(const int index, const int value) {
|
---|
150 |
|
---|
151 | if (!fEndPositions)
|
---|
152 | ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Regex_Result_Not_Set, fMemoryManager);
|
---|
153 |
|
---|
154 | if (index < 0 || fNoGroups <= index)
|
---|
155 | ThrowXMLwithMemMgr(ArrayIndexOutOfBoundsException, XMLExcepts::Array_BadIndex, fMemoryManager);
|
---|
156 |
|
---|
157 | fEndPositions[index] = value;
|
---|
158 | }
|
---|
159 |
|
---|
160 | XERCES_CPP_NAMESPACE_END
|
---|
161 |
|
---|
162 | #endif
|
---|