nsgmls: remove register keyword
[oweals/cde.git] / cde / programs / nsgmls / SdText.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these libraries and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 /* $XConsortium: SdText.C /main/1 1996/07/29 17:03:53 cde-hp $ */
24 // Copyright (c) 1995 James Clark
25 // See the file COPYING for copying permission.
26
27 #ifdef __GNUG__
28 #pragma implementation
29 #endif
30 #include "splib.h"
31 #include "SdText.h"
32
33 #ifdef SP_NAMESPACE
34 namespace SP_NAMESPACE {
35 #endif
36
37 SdText::SdText()
38 : lita_(false)
39 {
40 }
41
42 SdText::SdText(const Location &loc, Boolean lita)
43 : lita_(lita)
44 {
45   items_.resize(items_.size() + 1);
46   items_.back().loc = loc;
47   items_.back().index = 0;
48 }
49
50 void SdText::addChar(SyntaxChar c, const Location &loc)
51 {
52   if (items_.size() == 0
53       || loc.origin().pointer() != items_.back().loc.origin().pointer()
54       || loc.index() != (items_.back().loc.index()
55                          + (chars_.size() - items_.back().index))) {
56     items_.resize(items_.size() + 1);
57     items_.back().loc = loc;
58     items_.back().index = chars_.size();
59   }
60   chars_ += c;
61 }
62
63 void SdText::swap(SdText &to)
64 {
65   items_.swap(to.items_);
66   chars_.swap(to.chars_);
67   {
68     Boolean tem = to.lita_;
69     to.lita_ = lita_;
70     lita_ = tem;
71   }
72 }
73
74 Location SdText::endDelimLocation() const
75 {
76   Location loc(items_.back().loc);
77   loc += chars_.size() - items_.back().index;
78   return loc;
79 }
80
81 SdTextItem::SdTextItem()
82 : index(0)
83 {
84 }
85
86 SdTextIter::SdTextIter(const SdText &text)
87 : ptr_(&text),
88   itemIndex_(0)
89 {
90 }
91
92 Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
93 {
94   const Vector<SdTextItem> &items = ptr_->items_;
95   if (itemIndex_ >= items.size())
96     return 0;
97   loc = items[itemIndex_].loc;
98   const String<SyntaxChar> &chars = ptr_->chars_;
99   size_t charsIndex = items[itemIndex_].index;
100   ptr = chars.data() + charsIndex;
101   if (itemIndex_ + 1 < items.size())
102     length = items[itemIndex_ + 1].index - charsIndex;
103   else
104     length = chars.size() - charsIndex;
105   itemIndex_++;
106   return 1;
107 }
108
109 #ifdef SP_NAMESPACE
110 }
111 #endif