2
This file is part of the KDE libraries
4
Copyright (C) 2004, 2005, 2006 Apple Computer
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.
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.
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., 59 Temple Place - Suite 330,
19
Boston, MA 02111-1307, USA.
22
#ifndef SegmentedString_h
23
#define SegmentedString_h
25
#include "DeprecatedValueList.h"
26
#include "PlatformString.h"
30
class SegmentedString;
32
class SegmentedSubstring {
34
friend class SegmentedString;
36
SegmentedSubstring() : m_length(0), m_current(0), m_excludeLineNumbers(false) {}
37
SegmentedSubstring(const String& str) : m_string(str), m_length(str.length()), m_excludeLineNumbers(false) {
38
m_current = m_length == 0 ? 0 : m_string.characters();
41
SegmentedSubstring(const UChar* str, int length) : m_length(length), m_current(length == 0 ? 0 : str), m_excludeLineNumbers(false) {}
43
void clear() { m_length = 0; m_current = 0; }
45
bool excludeLineNumbers() const { return m_excludeLineNumbers; }
46
void setExcludeLineNumbers() { m_excludeLineNumbers = true; }
48
void appendTo(String& str) const {
49
if (m_string.characters() == m_current) {
55
str.append(String(m_current, m_length));
61
const UChar* m_current;
62
bool m_excludeLineNumbers;
65
class SegmentedString {
68
: m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0), m_composite(false) {}
69
SegmentedString(const UChar* str, int length) : m_pushedChar1(0), m_pushedChar2(0)
70
, m_currentString(str, length), m_currentChar(m_currentString.m_current), m_composite(false) {}
71
SegmentedString(const String& str)
72
: m_pushedChar1(0), m_pushedChar2(0), m_currentString(str)
73
, m_currentChar(m_currentString.m_current), m_composite(false) {}
74
SegmentedString(const SegmentedString&);
76
const SegmentedString& operator=(const SegmentedString&);
80
void append(const SegmentedString &);
81
void prepend(const SegmentedString &);
83
bool excludeLineNumbers() const { return m_currentString.excludeLineNumbers(); }
84
void setExcludeLineNumbers();
89
m_currentChar = m_pushedChar1 ? &m_pushedChar1 : m_currentString.m_current;
91
ASSERT(!m_pushedChar2);
96
bool isEmpty() const { return !current(); }
97
unsigned length() const;
99
void advance(int* lineNumber = 0) {
101
m_pushedChar1 = m_pushedChar2;
103
} else if (m_currentString.m_current) {
104
if (*m_currentString.m_current++ == '\n' && lineNumber && !m_currentString.excludeLineNumbers())
105
*lineNumber = *lineNumber + 1;
106
if (--m_currentString.m_length == 0)
109
m_currentChar = m_pushedChar1 ? &m_pushedChar1 : m_currentString.m_current;
112
bool escaped() const { return m_pushedChar1; }
114
String toString() const;
116
const UChar& operator*() const { return *current(); }
117
const UChar* operator->() const { return current(); }
120
void append(const SegmentedSubstring &);
121
void prepend(const SegmentedSubstring &);
123
void advanceSubstring();
124
const UChar* current() const { return m_currentChar; }
128
SegmentedSubstring m_currentString;
129
const UChar* m_currentChar;
130
DeprecatedValueList<SegmentedSubstring> m_substrings;