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 librararies 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 {
41 SdText::SdText(const Location &loc, Boolean lita)
44 items_.resize(items_.size() + 1);
45 items_.back().loc = loc;
46 items_.back().index = 0;
49 void SdText::addChar(SyntaxChar c, const Location &loc)
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();
62 void SdText::swap(SdText &to)
64 items_.swap(to.items_);
65 chars_.swap(to.chars_);
67 Boolean tem = to.lita_;
73 Location SdText::endDelimLocation() const
75 Location loc(items_.back().loc);
76 loc += chars_.size() - items_.back().index;
80 SdTextItem::SdTextItem()
84 SdTextIter::SdTextIter(const SdText &text)
90 Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
92 const Vector<SdTextItem> &items = ptr_->items_;
93 if (itemIndex_ >= items.size())
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;
102 length = chars.size() - charsIndex;