summaryrefslogtreecommitdiffstats
path: root/khtml/misc/stringit.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitce4a32fe52ef09d8f5ff1dd22c001110902b60a2 (patch)
tree5ac38a06f3dde268dc7927dc155896926aaf7012 /khtml/misc/stringit.cpp
downloadtdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.tar.gz
tdelibs-ce4a32fe52ef09d8f5ff1dd22c001110902b60a2.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'khtml/misc/stringit.cpp')
-rw-r--r--khtml/misc/stringit.cpp138
1 files changed, 138 insertions, 0 deletions
diff --git a/khtml/misc/stringit.cpp b/khtml/misc/stringit.cpp
new file mode 100644
index 000000000..5dbe857be
--- /dev/null
+++ b/khtml/misc/stringit.cpp
@@ -0,0 +1,138 @@
+/*
+ This file is part of the KDE libraries
+
+ Copyright (C) 2004 Apple Computer
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "stringit.h"
+
+namespace khtml {
+
+uint TokenizerString::length() const
+{
+ uint length = m_currentString.m_length;
+ if (!m_pushedChar1.isNull()) {
+ ++length;
+ if (!m_pushedChar2.isNull())
+ ++length;
+ }
+ if (m_composite) {
+ QValueListConstIterator<TokenizerSubstring> i = m_substrings.begin();
+ QValueListConstIterator<TokenizerSubstring> e = m_substrings.end();
+ for (; i != e; ++i)
+ length += (*i).m_length;
+ }
+ return length;
+}
+
+void TokenizerString::clear()
+{
+ m_pushedChar1 = 0;
+ m_pushedChar2 = 0;
+ m_currentChar = 0;
+ m_currentString.clear();
+ m_substrings.clear();
+ m_lines = 0;
+ m_composite = false;
+}
+
+void TokenizerString::append(const TokenizerSubstring &s)
+{
+ if (s.m_length) {
+ if (!m_currentString.m_length) {
+ m_currentString = s;
+ } else {
+ m_substrings.append(s);
+ m_composite = true;
+ }
+ }
+}
+
+void TokenizerString::prepend(const TokenizerSubstring &s)
+{
+ assert(!escaped());
+ if (s.m_length) {
+ if (!m_currentString.m_length)
+ m_currentString = s;
+ else {
+ // Shift our m_currentString into our list.
+ m_substrings.prepend(m_currentString);
+ m_currentString = s;
+ m_composite = true;
+ }
+ }
+}
+
+void TokenizerString::append(const TokenizerString &s)
+{
+ assert(!s.escaped());
+ append(s.m_currentString);
+ if (s.m_composite) {
+ QValueListConstIterator<TokenizerSubstring> i = s.m_substrings.begin();
+ QValueListConstIterator<TokenizerSubstring> e = s.m_substrings.end();
+ for (; i != e; ++i)
+ append(*i);
+ }
+ m_currentChar = m_pushedChar1.isNull() ? m_currentString.m_current : &m_pushedChar1;
+}
+
+void TokenizerString::prepend(const TokenizerString &s)
+{
+ assert(!escaped());
+ assert(!s.escaped());
+ if (s.m_composite) {
+ QValueListConstIterator<TokenizerSubstring> i = s.m_substrings.fromLast();
+ QValueListConstIterator<TokenizerSubstring> e = s.m_substrings.end();
+ for (; i != e; --i)
+ prepend(*i);
+ }
+ prepend(s.m_currentString);
+ m_currentChar = m_pushedChar1.isNull() ? m_currentString.m_current : &m_pushedChar1;
+}
+
+void TokenizerString::advanceSubstring()
+{
+ if (m_composite) {
+ m_currentString = m_substrings.first();
+ m_substrings.remove(m_substrings.begin());
+ if (m_substrings.isEmpty())
+ m_composite = false;
+ } else {
+ m_currentString.clear();
+ }
+}
+
+QString TokenizerString::toString() const
+{
+ QString result;
+ if (!m_pushedChar1.isNull()) {
+ result.append(m_pushedChar1);
+ if (!m_pushedChar2.isNull())
+ result.append(m_pushedChar2);
+ }
+ m_currentString.appendTo(result);
+ if (m_composite) {
+ QValueListConstIterator<TokenizerSubstring> i = m_substrings.begin();
+ QValueListConstIterator<TokenizerSubstring> e = m_substrings.end();
+ for (; i != e; ++i)
+ (*i).appendTo(result);
+ }
+ return result;
+}
+
+}