1 /* $XConsortium: SdText.C /main/1 1996/07/29 17:03:53 cde-hp $ */
2 // Copyright (c) 1995 James Clark
3 // See the file COPYING for copying permission.
12 namespace SP_NAMESPACE {
19 SdText::SdText(const Location &loc, Boolean lita)
22 items_.resize(items_.size() + 1);
23 items_.back().loc = loc;
24 items_.back().index = 0;
27 void SdText::addChar(SyntaxChar c, const Location &loc)
29 if (items_.size() == 0
30 || loc.origin().pointer() != items_.back().loc.origin().pointer()
31 || loc.index() != (items_.back().loc.index()
32 + (chars_.size() - items_.back().index))) {
33 items_.resize(items_.size() + 1);
34 items_.back().loc = loc;
35 items_.back().index = chars_.size();
40 void SdText::swap(SdText &to)
42 items_.swap(to.items_);
43 chars_.swap(to.chars_);
45 Boolean tem = to.lita_;
51 Location SdText::endDelimLocation() const
53 Location loc(items_.back().loc);
54 loc += chars_.size() - items_.back().index;
58 SdTextItem::SdTextItem()
62 SdTextIter::SdTextIter(const SdText &text)
68 Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
70 const Vector<SdTextItem> &items = ptr_->items_;
71 if (itemIndex_ >= items.size())
73 loc = items[itemIndex_].loc;
74 const String<SyntaxChar> &chars = ptr_->chars_;
75 size_t charsIndex = items[itemIndex_].index;
76 ptr = chars.data() + charsIndex;
77 if (itemIndex_ + 1 < items.size())
78 length = items[itemIndex_ + 1].index - charsIndex;
80 length = chars.size() - charsIndex;