source: icXML/icXML-devel/src/xercesc/util/XMLStringTokenizer.cpp @ 2732

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

Original Xerces files with import mods for icxercesc

File size: 4.8 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: XMLStringTokenizer.cpp 555320 2007-07-11 16:05:13Z amassari $
20 */
21
22// ---------------------------------------------------------------------------
23//  Includes
24// ---------------------------------------------------------------------------
25#include <xercesc/util/Janitor.hpp>
26#include <xercesc/util/XMLStringTokenizer.hpp>
27#include <xercesc/util/XMLUniDefs.hpp>
28#include <xercesc/util/OutOfMemoryException.hpp>
29
30XERCES_CPP_NAMESPACE_BEGIN
31
32// ---------------------------------------------------------------------------
33//  XMLStringTokenizer: Local const data
34// ---------------------------------------------------------------------------
35const XMLCh fgDelimeters[] =
36{
37    chSpace, chHTab, chCR, chLF, chNull
38};
39
40// ---------------------------------------------------------------------------
41//  XMLStringTokenizer: Constructors and Destructor
42// ---------------------------------------------------------------------------
43
44typedef JanitorMemFunCall<XMLStringTokenizer>   CleanupType;
45
46XMLStringTokenizer::XMLStringTokenizer( const XMLCh* const srcStr
47                                      , MemoryManager* const manager)
48    : fOffset(0)
49    , fStringLen(XMLString::stringLen(srcStr))
50    , fString(XMLString::replicate(srcStr, manager))
51    , fDelimeters(fgDelimeters)
52    , fTokens(0)
53    , fMemoryManager(manager)
54{
55    CleanupType cleanup(this, &XMLStringTokenizer::cleanUp);
56
57        try {
58        if (fStringLen > 0) {
59            fTokens = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
60        }
61    }
62    catch(const OutOfMemoryException&)
63    {
64        cleanup.release();
65
66        throw;
67    }
68
69    cleanup.release();
70}
71
72XMLStringTokenizer::XMLStringTokenizer(const XMLCh* const srcStr,
73                                       const XMLCh* const delim,
74                                       MemoryManager* const manager)
75    : fOffset(0)
76    , fStringLen(XMLString::stringLen(srcStr))
77    , fString(XMLString::replicate(srcStr, manager))
78    , fDelimeters(XMLString::replicate(delim, manager))
79    , fTokens(0)
80    , fMemoryManager(manager)
81{
82    CleanupType cleanup(this, &XMLStringTokenizer::cleanUp);
83
84        try {
85        if (fStringLen > 0) {
86            fTokens = new (fMemoryManager) RefArrayVectorOf<XMLCh>(4, true, fMemoryManager);
87        }
88    }
89    catch(const OutOfMemoryException&)
90    {
91        cleanup.release();
92
93        throw;
94    }
95
96    cleanup.release();
97}
98
99XMLStringTokenizer::~XMLStringTokenizer()
100{
101        cleanUp();
102}
103
104// ---------------------------------------------------------------------------
105//  XMLStringTokenizer: CleanUp methods
106// ---------------------------------------------------------------------------
107void XMLStringTokenizer::cleanUp() {
108
109        fMemoryManager->deallocate(fString);//delete [] fString;
110    if (fDelimeters != fgDelimeters) {
111        fMemoryManager->deallocate((void*)fDelimeters);//delete [] fDelimeters;
112    }
113    delete fTokens;
114}
115
116
117// ---------------------------------------------------------------------------
118//  XMLStringTokenizer: Management methods
119// ---------------------------------------------------------------------------
120XMLCh* XMLStringTokenizer::nextToken() {
121
122    if (fOffset >= fStringLen) {
123        return 0;
124    }
125
126    bool tokFound = false;
127    XMLSize_t startIndex = fOffset;
128    XMLSize_t endIndex = fOffset;
129
130    for (; endIndex < fStringLen; endIndex++) {
131
132        if (isDelimeter(fString[endIndex])) {
133
134                        if (tokFound) {
135                break;
136            }
137
138                        startIndex++;
139                        continue;
140        }
141
142        tokFound = true;
143    }
144
145    fOffset = endIndex;
146
147    if (tokFound) {
148
149        XMLCh* tokStr = (XMLCh*) fMemoryManager->allocate
150        (
151            (endIndex - startIndex + 1) * sizeof(XMLCh)
152        );//new XMLCh[(endIndex - startIndex) + 1];
153
154        XMLString::subString(tokStr, fString, startIndex, endIndex, fMemoryManager);
155        fTokens->addElement(tokStr);
156
157        return tokStr;
158        }
159
160    return 0;
161}
162
163
164bool XMLStringTokenizer::hasMoreTokens() {
165
166    if (countTokens() > 0)
167        return true;
168
169        return false;
170}
171
172XERCES_CPP_NAMESPACE_END
173
174/**
175  * End of file XMLStringTokenizer.cpp
176  */
177
Note: See TracBrowser for help on using the repository browser.