3065 some functions in the tcp module can be static
[unleashed.git] / usr / src / cmd / man / src / util / nsgmls.src / lib / SdText.cxx
blob98bbeb59f9f31dda13487167c0c064d338a33eb0
1 // Copyright (c) 1995 James Clark
2 // See the file COPYING for copying permission.
3 #pragma ident "%Z%%M% %I% %E% SMI"
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8 #include "splib.h"
9 #include "SdText.h"
11 #ifdef SP_NAMESPACE
12 namespace SP_NAMESPACE {
13 #endif
15 SdText::SdText()
19 SdText::SdText(const Location &loc, Boolean lita)
20 : lita_(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();
37 chars_ += c;
40 void SdText::swap(SdText &to)
42 items_.swap(to.items_);
43 chars_.swap(to.chars_);
45 Boolean tem = to.lita_;
46 to.lita_ = lita_;
47 lita_ = tem;
51 Location SdText::endDelimLocation() const
53 Location loc(items_.back().loc);
54 loc += chars_.size() - items_.back().index;
55 return loc;
58 SdTextItem::SdTextItem()
62 SdTextIter::SdTextIter(const SdText &text)
63 : ptr_(&text),
64 itemIndex_(0)
68 Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
70 const Vector<SdTextItem> &items = ptr_->items_;
71 if (itemIndex_ >= items.size())
72 return 0;
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;
79 else
80 length = chars.size() - charsIndex;
81 itemIndex_++;
82 return 1;
85 #ifdef SP_NAMESPACE
87 #endif