KHtml

stringit.cpp
1 /*
2  This file is part of the KDE libraries
3 
4  Copyright (C) 2004 Apple Computer
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License as published by the Free Software Foundation; either
9  version 2 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Library General Public License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to
18  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  Boston, MA 02110-1301, USA.
20 */
21 
22 #include "stringit.h"
23 
24 namespace khtml
25 {
26 
27 uint TokenizerString::length() const
28 {
29  uint length = m_currentString.m_length;
30  if (!m_pushedChar1.isNull()) {
31  ++length;
32  if (!m_pushedChar2.isNull()) {
33  ++length;
34  }
35  }
36  if (m_composite) {
39  for (; i != e; ++i) {
40  length += (*i).m_length;
41  }
42  }
43  return length;
44 }
45 
46 void TokenizerString::clear()
47 {
48  m_pushedChar1 = 0;
49  m_pushedChar2 = 0;
50  m_currentChar = nullptr;
51  m_currentString.clear();
52  m_substrings.clear();
53  m_lines = 0;
54  m_composite = false;
55 }
56 
57 void TokenizerString::append(const TokenizerSubstring &s)
58 {
59  if (s.m_length) {
60  if (!m_currentString.m_length) {
61  m_currentString = s;
62  } else {
63  m_substrings.append(s);
64  m_composite = true;
65  }
66  }
67 }
68 
69 void TokenizerString::prepend(const TokenizerSubstring &s)
70 {
71  assert(!escaped());
72  if (s.m_length) {
73  if (!m_currentString.m_length) {
74  m_currentString = s;
75  } else {
76  // Shift our m_currentString into our list.
77  m_substrings.prepend(m_currentString);
78  m_currentString = s;
79  m_composite = true;
80  }
81  }
82 }
83 
84 void TokenizerString::append(const TokenizerString &s)
85 {
86  assert(!s.escaped());
87  append(s.m_currentString);
88  if (s.m_composite) {
90  QList<TokenizerSubstring>::ConstIterator e = s.m_substrings.end();
91  for (; i != e; ++i) {
92  append(*i);
93  }
94  }
95  m_currentChar = m_pushedChar1.isNull() ? m_currentString.m_current : &m_pushedChar1;
96 }
97 
98 void TokenizerString::prepend(const TokenizerString &s)
99 {
100  assert(!escaped());
101  assert(!s.escaped());
102  if (s.m_composite) {
103  QList<TokenizerSubstring>::ConstIterator e = s.m_substrings.end();
104  while (e != s.m_substrings.begin()) {
105  --e;
106  prepend(*e);
107  }
108  }
109  prepend(s.m_currentString);
110  m_currentChar = m_pushedChar1.isNull() ? m_currentString.m_current : &m_pushedChar1;
111 }
112 
113 void TokenizerString::advanceSubstring()
114 {
115  if (m_composite) {
116  m_currentString = m_substrings.first();
117  m_substrings.removeFirst();
118  if (m_substrings.isEmpty()) {
119  m_composite = false;
120  }
121  } else {
122  m_currentString.clear();
123  }
124 }
125 
126 QString TokenizerString::toString() const
127 {
128  QString result;
129  if (!m_pushedChar1.isNull()) {
130  result.append(m_pushedChar1);
131  if (!m_pushedChar2.isNull()) {
132  result.append(m_pushedChar2);
133  }
134  }
135  m_currentString.appendTo(result);
136  if (m_composite) {
139  for (; i != e; ++i) {
140  (*i).appendTo(result);
141  }
142  }
143  return result;
144 }
145 
146 }
QString & append(QChar ch)
This file is part of the HTML rendering engine for KDE.
QList::iterator end()
QList::iterator begin()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Oct 15 2021 22:48:13 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.