source: icXML/icXML-devel/src/xercesc/util/regx/UnionToken.cpp @ 2722

Last change on this file since 2722 was 2722, checked in by cameron, 6 years ago

Original Xerces files with import mods for icxercesc

File size: 4.5 KB
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 <icxercesc/util/regx/UnionToken.hpp>
26#include <icxercesc/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
31XERCES_CPP_NAMESPACE_BEGIN
32
33// ---------------------------------------------------------------------------
34//  Static member data initialization
35// ---------------------------------------------------------------------------
36const unsigned short UnionToken::INITIALSIZE = 8;
37
38// ---------------------------------------------------------------------------
39//  UnionToken: Constructors and Destructors
40// ---------------------------------------------------------------------------
41UnionToken::UnionToken(const Token::tokType tkType, MemoryManager* const manager)
42    : Token(tkType, manager)
43    , fChildren(0)
44{
45
46}
47
48UnionToken::~UnionToken() {
49
50    delete fChildren;
51}
52
53
54// ---------------------------------------------------------------------------
55//  UnionToken: Children manipulation methods
56// ---------------------------------------------------------------------------
57void UnionToken::addChild(Token* const child, TokenFactory* const tokFactory) {
58
59    if (child == 0)
60        return;
61
62    if (fChildren == 0)
63        fChildren = new (tokFactory->getMemoryManager()) RefVectorOf<Token>(INITIALSIZE, false, tokFactory->getMemoryManager());
64
65    if (getTokenType() == T_UNION) {
66
67        fChildren->addElement(child);
68        return;
69    }
70
71    Token::tokType childType = child->getTokenType();
72    if (childType == T_CONCAT) {
73
74        XMLSize_t childSize = child->size();
75        for (XMLSize_t i = 0; i < childSize; i++) {
76
77            addChild(child->getChild(i), tokFactory);
78        }
79
80        return;
81    }
82
83    XMLSize_t childrenSize = fChildren->size();
84    if (childrenSize == 0) {
85
86        fChildren->addElement(child);
87        return;
88    }
89
90    Token* previousTok = fChildren->elementAt(childrenSize - 1);
91    Token::tokType previousType = previousTok->getTokenType();
92
93    if (!((previousType == T_CHAR || previousType == T_STRING)
94          && (childType == T_CHAR || childType == T_STRING))) {
95
96        fChildren->addElement(child);
97        return;
98    }
99
100    // Continue
101    XMLBuffer stringBuf(1023, tokFactory->getMemoryManager());
102
103    if (previousType == T_CHAR) {
104
105        XMLInt32 ch = previousTok->getChar();
106
107        if (ch >= 0x10000) {
108
109            XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager());
110            stringBuf.append(chSurrogate);
111            tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate;
112        }
113        else {
114            stringBuf.append((XMLCh) ch);
115        }
116
117        previousTok = tokFactory->createString(0);
118        fChildren->setElementAt(previousTok, childrenSize - 1);
119    }
120    else {
121        stringBuf.append(previousTok->getString());
122    }
123
124    if (childType == T_CHAR) {
125
126        XMLInt32 ch = child->getChar();
127
128        if (ch >= 0x10000) {
129
130            XMLCh* chSurrogate = RegxUtil::decomposeToSurrogates(ch, tokFactory->getMemoryManager());
131            stringBuf.append(chSurrogate);
132            tokFactory->getMemoryManager()->deallocate(chSurrogate);//delete [] chSurrogate;
133        }
134        else {
135            stringBuf.append((XMLCh) ch);
136        }
137    }
138    else {
139        stringBuf.append(child->getString());
140    }
141
142    ((StringToken*) previousTok)->setString(stringBuf.getRawBuffer());
143}
144
145XERCES_CPP_NAMESPACE_END
146
147/**
148  * End of file UnionToken.cpp
149  */
Note: See TracBrowser for help on using the repository browser.