nsgmls: fix up some gcc 4.8 warnings.
[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 librararies 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 {
39 }
40
41 SdText::SdText(const Location &loc, Boolean lita)
42 : lita_(lita)
43 {
44   items_.resize(items_.size() + 1);
45   items_.back().loc = loc;
46   items_.back().index = 0;
47 }
48
49 void SdText::addChar(SyntaxChar c, const Location &loc)
50 {
51   if (items_.size() == 0
52       || loc.origin().pointer() != items_.back().loc.origin().pointer()
53       || loc.index() != (items_.back().loc.index()
54                          + (chars_.size() - items_.back().index))) {
55     items_.resize(items_.size() + 1);
56     items_.back().loc = loc;
57     items_.back().index = chars_.size();
58   }
59   chars_ += c;
60 }
61
62 void SdText::swap(SdText &to)
63 {
64   items_.swap(to.items_);
65   chars_.swap(to.chars_);
66   {
67     Boolean tem = to.lita_;
68     to.lita_ = lita_;
69     lita_ = tem;
70   }
71 }
72
73 Location SdText::endDelimLocation() const
74 {
75   Location loc(items_.back().loc);
76   loc += chars_.size() - items_.back().index;
77   return loc;
78 }
79
80 SdTextItem::SdTextItem()
81 {
82 }
83
84 SdTextIter::SdTextIter(const SdText &text)
85 : ptr_(&text),
86   itemIndex_(0)
87 {
88 }
89
90 Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
91 {
92   const Vector<SdTextItem> &items = ptr_->items_;
93   if (itemIndex_ >= items.size())
94     return 0;
95   loc = items[itemIndex_].loc;
96   const String<SyntaxChar> &chars = ptr_->chars_;
97   size_t charsIndex = items[itemIndex_].index;
98   ptr = chars.data() + charsIndex;
99   if (itemIndex_ + 1 < items.size())
100     length = items[itemIndex_ + 1].index - charsIndex;
101   else
102     length = chars.size() - charsIndex;
103   itemIndex_++;
104   return 1;
105 }
106
107 #ifdef SP_NAMESPACE
108 }
109 #endif