/src/xerces-c/src/xercesc/util/regx/UnionToken.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
3 | | * contributor license agreements. See the NOTICE file distributed with |
4 | | * this work for additional information regarding copyright ownership. |
5 | | * The ASF licenses this file to You under the Apache License, Version 2.0 |
6 | | * (the "License"); you may not use this file except in compliance with |
7 | | * the License. You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | * limitations under the License. |
16 | | */ |
17 | | |
18 | | /* |
19 | | * $Id: UnionToken.cpp 678395 2008-07-21 11:40:41Z amassari $ |
20 | | */ |
21 | | |
22 | | // --------------------------------------------------------------------------- |
23 | | // Includes |
24 | | // --------------------------------------------------------------------------- |
25 | | #include <xercesc/util/regx/UnionToken.hpp> |
26 | | #include <xercesc/framework/XMLBuffer.hpp> |
27 | | #include <xercesc/util/regx/RegxUtil.hpp> |
28 | | #include <xercesc/util/regx/TokenFactory.hpp> |
29 | | #include <xercesc/util/regx/StringToken.hpp> |
30 | | |
31 | | XERCES_CPP_NAMESPACE_BEGIN |
32 | | |
33 | | // --------------------------------------------------------------------------- |
34 | | // Static member data initialization |
35 | | // --------------------------------------------------------------------------- |
36 | | const unsigned short UnionToken::INITIALSIZE = 8; |
37 | | |
38 | | // --------------------------------------------------------------------------- |
39 | | // UnionToken: Constructors and Destructors |
40 | | // --------------------------------------------------------------------------- |
41 | | UnionToken::UnionToken(const Token::tokType tkType, MemoryManager* const manager) |
42 | | : Token(tkType, manager) |
43 | | , fChildren(0) |
44 | 12 | { |
45 | | |
46 | 12 | } |
47 | | |
48 | 0 | UnionToken::~UnionToken() { |
49 | |
|
50 | 0 | delete fChildren; |
51 | 0 | } |
52 | | |
53 | | |
54 | | // --------------------------------------------------------------------------- |
55 | | // UnionToken: Children manipulation methods |
56 | | // --------------------------------------------------------------------------- |
57 | 28 | void UnionToken::addChild(Token* const child, TokenFactory* const tokFactory) { |
58 | | |
59 | 28 | if (child == 0) |
60 | 0 | return; |
61 | | |
62 | 28 | if (fChildren == 0) |
63 | 12 | fChildren = new (tokFactory->getMemoryManager()) RefVectorOf<Token>(INITIALSIZE, false, tokFactory->getMemoryManager()); |
64 | | |
65 | 28 | if (getTokenType() == T_UNION) { |
66 | | |
67 | 4 | fChildren->addElement(child); |
68 | 4 | return; |
69 | 4 | } |
70 | | |
71 | 24 | Token::tokType childType = child->getTokenType(); |
72 | 24 | if (childType == T_CONCAT) { |
73 | | |
74 | 2 | XMLSize_t childSize = child->size(); |
75 | 6 | for (XMLSize_t i = 0; i < childSize; i++) { |
76 | | |
77 | 4 | addChild(child->getChild(i), tokFactory); |
78 | 4 | } |
79 | | |
80 | 2 | return; |
81 | 2 | } |
82 | | |
83 | 22 | XMLSize_t childrenSize = fChildren->size(); |
84 | 22 | if (childrenSize == 0) { |
85 | | |
86 | 10 | fChildren->addElement(child); |
87 | 10 | return; |
88 | 10 | } |
89 | | |
90 | 12 | Token* previousTok = fChildren->elementAt(childrenSize - 1); |
91 | 12 | Token::tokType previousType = previousTok->getTokenType(); |
92 | | |
93 | 12 | if (!((previousType == T_CHAR || previousType == T_STRING) |
94 | 12 | && (childType == T_CHAR || childType == T_STRING))) { |
95 | | |
96 | 12 | fChildren->addElement(child); |
97 | 12 | return; |
98 | 12 | } |
99 | | |
100 | | // Continue |
101 | 0 | XMLBuffer stringBuf(1023, tokFactory->getMemoryManager()); |
102 | |
|
103 | 0 | if (previousType == T_CHAR) { |
104 | |
|
105 | 0 | XMLInt32 ch = previousTok->getChar(); |
106 | |
|
107 | 0 | if (ch >= 0x10000) { |
108 | |
|
109 | 0 | XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager()); |
110 | 0 | stringBuf.append(chSurrogate); |
111 | 0 | tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate; |
112 | 0 | } |
113 | 0 | else { |
114 | 0 | stringBuf.append((XMLCh) ch); |
115 | 0 | } |
116 | |
|
117 | 0 | previousTok = tokFactory->createString(0); |
118 | 0 | fChildren->setElementAt(previousTok, childrenSize - 1); |
119 | 0 | } |
120 | 0 | else { |
121 | 0 | stringBuf.append(previousTok->getString()); |
122 | 0 | } |
123 | |
|
124 | 0 | if (childType == T_CHAR) { |
125 | |
|
126 | 0 | XMLInt32 ch = child->getChar(); |
127 | |
|
128 | 0 | if (ch >= 0x10000) { |
129 | |
|
130 | 0 | XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager()); |
131 | 0 | stringBuf.append(chSurrogate); |
132 | 0 | tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate; |
133 | 0 | } |
134 | 0 | else { |
135 | 0 | stringBuf.append((XMLCh) ch); |
136 | 0 | } |
137 | 0 | } |
138 | 0 | else { |
139 | 0 | stringBuf.append(child->getString()); |
140 | 0 | } |
141 | |
|
142 | 0 | ((StringToken*) previousTok)->setString(stringBuf.getRawBuffer()); |
143 | 0 | } |
144 | | |
145 | | XERCES_CPP_NAMESPACE_END |
146 | | |
147 | | /** |
148 | | * End of file UnionToken.cpp |
149 | | */ |