File: SdText.cxx

package info (click to toggle)
opensp 1.5.2-15.2
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,168 kB
  • sloc: cpp: 65,784; ansic: 17,124; sh: 11,193; xml: 2,704; makefile: 895; perl: 561; yacc: 288; sed: 16
file content (100 lines) | stat: -rw-r--r-- 1,939 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 1995 James Clark
// See the file COPYING for copying permission.

#ifdef __GNUG__
#pragma implementation
#endif
#include "splib.h"
#include "SdText.h"

#ifdef SP_NAMESPACE
namespace SP_NAMESPACE {
#endif

SdText::SdText()
{
}

SdText::SdText(const Location &loc, Boolean lita)
: lita_(lita)
{
  items_.resize(items_.size() + 1);
  items_.back().loc = loc;
  items_.back().index = 0;
}

void SdText::addChar(SyntaxChar c, const Location &loc)
{
  if (items_.size() == 0
      || loc.origin().pointer() != items_.back().loc.origin().pointer()
      || loc.index() != (items_.back().loc.index()
			 + (chars_.size() - items_.back().index))) {
    items_.resize(items_.size() + 1);
    items_.back().loc = loc;
    items_.back().index = chars_.size();
  }
  chars_ += c;
}

void SdText::swap(SdText &to)
{
  items_.swap(to.items_);
  chars_.swap(to.chars_);
  {
    Boolean tem = to.lita_;
    to.lita_ = lita_;
    lita_ = tem;
  }
}

Location SdText::endDelimLocation() const
{
  Location loc(items_.back().loc);
  loc += chars_.size() - items_.back().index;
  return loc;
}

SdTextItem::SdTextItem()
{
}

SdTextItem::SdTextItem(const SdTextItem& x)
: loc(x.loc),
  index(x.index)
{
}

void SdTextItem::operator=(const SdTextItem& x)
{
  loc = x.loc;
  index = x.index;
}

SdTextItem::~SdTextItem() {}

SdTextIter::SdTextIter(const SdText &text)
: ptr_(&text),
  itemIndex_(0)
{
}

Boolean SdTextIter::next(const SyntaxChar *&ptr, size_t &length, Location &loc)
{
  const Vector<SdTextItem> &items = ptr_->items_;
  if (itemIndex_ >= items.size())
    return 0;
  loc = items[itemIndex_].loc;
  const String<SyntaxChar> &chars = ptr_->chars_;
  size_t charsIndex = items[itemIndex_].index;
  ptr = chars.data() + charsIndex;
  if (itemIndex_ + 1 < items.size())
    length = items[itemIndex_ + 1].index - charsIndex;
  else
    length = chars.size() - charsIndex;
  itemIndex_++;
  return 1;
}

#ifdef SP_NAMESPACE
}
#endif