2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
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)
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
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
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.
28 #pragma implementation
34 namespace SP_NAMESPACE {
42 SdText::SdText(const Location &loc, Boolean lita)
45 items_.resize(items_.size() + 1);
46 items_.back().loc = loc;
47 items_.back().index = 0;
50 void SdText::addChar(SyntaxChar c, const Location &loc)
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();
63 void SdText::swap(SdText &to)
65 items_.swap(to.items_);
66 chars_.swap(to.chars_);
68 Boolean tem = to.lita_;
74 Location SdText::endDelimLocation() const
76 Location loc(items_.back().loc);
77 loc += chars_.size() - items_.back().index;
81 SdTextItem::SdTextItem()
86 SdTextIter::SdTextIter(const SdText &text)
92 Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
94 const Vector<SdTextItem> &items = ptr_->items_;
95 if (itemIndex_ >= items.size())
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;
104 length = chars.size() - charsIndex;