summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/text/SegmentedString.h
diff options
context:
space:
mode:
authorLeon Clarke <leonclarke@google.com>2010-06-03 14:33:32 +0100
committerLeon Clarke <leonclarke@google.com>2010-06-08 12:24:51 +0100
commit5af96e2c7b73ebc627c6894727826a7576d31758 (patch)
treef9d5e6f6175ccd7e3d14de9b290f08937a0d17ba /WebCore/platform/text/SegmentedString.h
parent8cc4fcf4f6adcbc0e0aebfc24fbad9a4cddf2cfb (diff)
downloadexternal_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.zip
external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.gz
external_webkit-5af96e2c7b73ebc627c6894727826a7576d31758.tar.bz2
Merge webkit.org at r60469 : Initial merge by git.
Change-Id: I66a0047aa2af802f66bb0c7f2a8b02247a596234
Diffstat (limited to 'WebCore/platform/text/SegmentedString.h')
-rw-r--r--WebCore/platform/text/SegmentedString.h72
1 files changed, 53 insertions, 19 deletions
diff --git a/WebCore/platform/text/SegmentedString.h b/WebCore/platform/text/SegmentedString.h
index c5daaaa..21eae14 100644
--- a/WebCore/platform/text/SegmentedString.h
+++ b/WebCore/platform/text/SegmentedString.h
@@ -71,21 +71,22 @@ private:
class SegmentedString {
public:
SegmentedString()
- : m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0), m_composite(false) {}
+ : m_pushedChar1(0), m_pushedChar2(0), m_currentChar(0), m_composite(false), m_closed(false) {}
SegmentedString(const UChar* str, int length) : m_pushedChar1(0), m_pushedChar2(0)
- , m_currentString(str, length), m_currentChar(m_currentString.m_current), m_composite(false) {}
+ , m_currentString(str, length), m_currentChar(m_currentString.m_current), m_composite(false), m_closed(false) {}
SegmentedString(const String& str)
: m_pushedChar1(0), m_pushedChar2(0), m_currentString(str)
- , m_currentChar(m_currentString.m_current), m_composite(false) {}
+ , m_currentChar(m_currentString.m_current), m_composite(false), m_closed(false) {}
SegmentedString(const SegmentedString&);
const SegmentedString& operator=(const SegmentedString&);
void clear();
+ void close() { m_closed = true; }
void append(const SegmentedString&);
void prepend(const SegmentedString&);
-
+
bool excludeLineNumbers() const { return m_currentString.excludeLineNumbers(); }
void setExcludeLineNumbers();
@@ -99,28 +100,20 @@ public:
m_pushedChar2 = c;
}
}
-
+
bool isEmpty() const { return !current(); }
unsigned length() const;
+ bool isClosed() const { return m_closed; }
+
enum LookAheadResult {
DidNotMatch,
DidMatch,
NotEnoughCharacters,
};
- // WARNING: This method is currently used only by the HTML5 parser and is incomplete.
- LookAheadResult lookAhead(const String& string)
- {
- if (!m_pushedChar1 && string.length() <= (unsigned) m_currentString.m_length) {
- if (memcmp(string.characters(), m_currentString.m_current, string.length() * sizeof(UChar)))
- return DidNotMatch;
- return DidMatch;
- }
- // We haven't implemented the slow case yet.
- ASSERT_NOT_REACHED();
- return DidNotMatch;
- }
+ LookAheadResult lookAhead(const String& string) { return lookAheadInline<SegmentedString::equalsLiterally>(string); }
+ LookAheadResult lookAheadIgnoringCase(const String& string) { return lookAheadInline<SegmentedString::equalsIgnoringCase>(string); }
void advance()
{
@@ -138,6 +131,12 @@ public:
advance();
}
+ void advanceAndASSERTIgnoringCase(UChar expectedCharacter)
+ {
+ ASSERT_UNUSED(expectedCharacter, WTF::Unicode::foldCase(*current()) == WTF::Unicode::foldCase(expectedCharacter));
+ advance();
+ }
+
void advancePastNewline(int& lineNumber)
{
ASSERT(*current() == '\n');
@@ -171,9 +170,13 @@ public:
}
advanceSlowCase(lineNumber);
}
-
+
+ // Writes the consumed characters into consumedCharacters, which must
+ // have space for at least |count| characters.
+ void advance(unsigned count, UChar* consumedCharacters);
+
bool escaped() const { return m_pushedChar1; }
-
+
String toString() const;
const UChar& operator*() const { return *current(); }
@@ -188,12 +191,43 @@ private:
void advanceSubstring();
const UChar* current() const { return m_currentChar; }
+ static bool equalsLiterally(const UChar* str1, const UChar* str2, size_t count) { return !memcmp(str1, str2, count * sizeof(UChar)); }
+ static bool equalsIgnoringCase(const UChar* str1, const UChar* str2, size_t count) { return !WTF::Unicode::umemcasecmp(str1, str2, count); }
+
+ template<bool equals(const UChar* str1, const UChar* str2, size_t count)>
+ inline LookAheadResult lookAheadInline(const String& string)
+ {
+ if (!m_pushedChar1 && string.length() <= static_cast<unsigned>(m_currentString.m_length)) {
+ if (equals(string.characters(), m_currentString.m_current, string.length()))
+ return DidMatch;
+ return DidNotMatch;
+ }
+ return lookAheadSlowCase<equals>(string);
+ }
+
+ template<bool equals(const UChar* str1, const UChar* str2, size_t count)>
+ LookAheadResult lookAheadSlowCase(const String& string)
+ {
+ unsigned count = string.length();
+ if (count > length())
+ return NotEnoughCharacters;
+ UChar* consumedCharacters;
+ String consumedString = String::createUninitialized(count, consumedCharacters);
+ advance(count, consumedCharacters);
+ LookAheadResult result = DidNotMatch;
+ if (equals(string.characters(), consumedCharacters, count))
+ result = DidMatch;
+ prepend(SegmentedString(consumedString));
+ return result;
+ }
+
UChar m_pushedChar1;
UChar m_pushedChar2;
SegmentedSubstring m_currentString;
const UChar* m_currentChar;
Deque<SegmentedSubstring> m_substrings;
bool m_composite;
+ bool m_closed;
};
}