Commit e78c3d4f authored by abarth@webkit.org's avatar abarth@webkit.org

2010-08-13 Adam Barth <abarth@webkit.org>

        Reviewed by Eric Seidel.

        Rename some concepts in HTML entity search to be more self-documenting
        https://bugs.webkit.org/show_bug.cgi?id=44004

        Start and end are now first and last, which lets us use some better
        names for the statics in HTMLEntityTable.

        * html/HTMLEntityParser.cpp:
        (WebCore::consumeHTMLEntity):
        * html/HTMLEntitySearch.cpp:
        (WebCore::HTMLEntitySearch::HTMLEntitySearch):
        (WebCore::HTMLEntitySearch::findFirst):
        (WebCore::HTMLEntitySearch::findLast):
        (WebCore::HTMLEntitySearch::advance):
        * html/HTMLEntitySearch.h:
        (WebCore::HTMLEntitySearch::isEntityPrefix):
        (WebCore::HTMLEntitySearch::mostRecentMatch):
        (WebCore::HTMLEntitySearch::fail):
        * html/HTMLEntityTable.h:
2010-08-13  Adam Barth  <abarth@webkit.org>

        Reviewed by Eric Seidel.

        Rename some concepts in HTML entity search to be more self-documenting
        https://bugs.webkit.org/show_bug.cgi?id=44004

        Reflect name change in generator script.

        * Scripts/create-html-entity-table:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65358 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d61d7c0b
2010-08-13 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
Rename some concepts in HTML entity search to be more self-documenting
https://bugs.webkit.org/show_bug.cgi?id=44004
Start and end are now first and last, which lets us use some better
names for the statics in HTMLEntityTable.
* html/HTMLEntityParser.cpp:
(WebCore::consumeHTMLEntity):
* html/HTMLEntitySearch.cpp:
(WebCore::HTMLEntitySearch::HTMLEntitySearch):
(WebCore::HTMLEntitySearch::findFirst):
(WebCore::HTMLEntitySearch::findLast):
(WebCore::HTMLEntitySearch::advance):
* html/HTMLEntitySearch.h:
(WebCore::HTMLEntitySearch::isEntityPrefix):
(WebCore::HTMLEntitySearch::mostRecentMatch):
(WebCore::HTMLEntitySearch::fail):
* html/HTMLEntityTable.h:
2010-08-13 Adam Barth <abarth@webkit.org>
Fix ASSERT in XML entity parsing. You can't advance the entity search
......@@ -196,19 +196,19 @@ unsigned consumeHTMLEntity(SegmentedString& source, bool& notEnoughCharacters, U
unconsumeCharacters(source, consumedCharacters);
return 0;
}
if (!entitySearch.lastMatch()) {
if (!entitySearch.mostRecentMatch()) {
ASSERT(!entitySearch.currentValue());
unconsumeCharacters(source, consumedCharacters);
return 0;
}
if (entitySearch.lastMatch()->length != entitySearch.currentLength()) {
if (entitySearch.mostRecentMatch()->length != entitySearch.currentLength()) {
// We've consumed too many characters. We need to walk the
// source back to the point at which we had consumed an
// actual entity.
unconsumeCharacters(source, consumedCharacters);
consumedCharacters.clear();
const int length = entitySearch.lastMatch()->length;
const UChar* reference = entitySearch.lastMatch()->entity;
const int length = entitySearch.mostRecentMatch()->length;
const UChar* reference = entitySearch.mostRecentMatch()->entity;
for (int i = 0; i < length; ++i) {
cc = *source;
ASSERT_UNUSED(reference, cc == *reference++);
......@@ -218,10 +218,10 @@ unsigned consumeHTMLEntity(SegmentedString& source, bool& notEnoughCharacters, U
}
cc = *source;
}
if (entitySearch.lastMatch()->lastCharacter() == ';')
return entitySearch.lastMatch()->value;
if (entitySearch.mostRecentMatch()->lastCharacter() == ';')
return entitySearch.mostRecentMatch()->value;
if (!additionalAllowedCharacter || !(isAlphaNumeric(cc) || cc == '='))
return entitySearch.lastMatch()->value;
return entitySearch.mostRecentMatch()->value;
unconsumeCharacters(source, consumedCharacters);
return 0;
}
......
......@@ -42,9 +42,9 @@ const HTMLEntityTableEntry* halfway(const HTMLEntityTableEntry* left, const HTML
HTMLEntitySearch::HTMLEntitySearch()
: m_currentLength(0)
, m_currentValue(0)
, m_lastMatch(0)
, m_start(HTMLEntityTable::start())
, m_end(HTMLEntityTable::end())
, m_mostRecentMatch(0)
, m_first(HTMLEntityTable::firstEntry())
, m_last(HTMLEntityTable::lastEntry())
{
}
......@@ -58,10 +58,10 @@ HTMLEntitySearch::CompareResult HTMLEntitySearch::compare(const HTMLEntityTableE
return entryNextCharacter < nextCharacter ? Before : After;
}
const HTMLEntityTableEntry* HTMLEntitySearch::findStart(UChar nextCharacter) const
const HTMLEntityTableEntry* HTMLEntitySearch::findFirst(UChar nextCharacter) const
{
const HTMLEntityTableEntry* left = m_start;
const HTMLEntityTableEntry* right = m_end;
const HTMLEntityTableEntry* left = m_first;
const HTMLEntityTableEntry* right = m_last;
if (left == right)
return left;
CompareResult result = compare(left, nextCharacter);
......@@ -83,10 +83,10 @@ const HTMLEntityTableEntry* HTMLEntitySearch::findStart(UChar nextCharacter) con
return right;
}
const HTMLEntityTableEntry* HTMLEntitySearch::findEnd(UChar nextCharacter) const
const HTMLEntityTableEntry* HTMLEntitySearch::findLast(UChar nextCharacter) const
{
const HTMLEntityTableEntry* left = m_start;
const HTMLEntityTableEntry* right = m_end;
const HTMLEntityTableEntry* left = m_first;
const HTMLEntityTableEntry* right = m_last;
if (left == right)
return right;
CompareResult result = compare(right, nextCharacter);
......@@ -112,21 +112,21 @@ void HTMLEntitySearch::advance(UChar nextCharacter)
{
ASSERT(isEntityPrefix());
if (!m_currentLength) {
m_start = HTMLEntityTable::start(nextCharacter);
m_end = HTMLEntityTable::end(nextCharacter);
m_first = HTMLEntityTable::firstEntryStartingWith(nextCharacter);
m_last = HTMLEntityTable::lastEntryStartingWith(nextCharacter);
} else {
m_start = findStart(nextCharacter);
m_end = findEnd(nextCharacter);
if (m_start == m_end && compare(m_start, nextCharacter) != Prefix)
m_first = findFirst(nextCharacter);
m_last = findLast(nextCharacter);
if (m_first == m_last && compare(m_first, nextCharacter) != Prefix)
return fail();
}
++m_currentLength;
if (m_start->length != m_currentLength) {
if (m_first->length != m_currentLength) {
m_currentValue = 0;
return;
}
m_lastMatch = m_start;
m_currentValue = m_lastMatch->value;
m_mostRecentMatch = m_first;
m_currentValue = m_mostRecentMatch->value;
}
}
......@@ -38,11 +38,11 @@ public:
void advance(UChar);
bool isEntityPrefix() const { return !!m_start; }
bool isEntityPrefix() const { return !!m_first; }
int currentValue() const { return m_currentValue; }
int currentLength() const { return m_currentLength; }
const HTMLEntityTableEntry* lastMatch() const { return m_lastMatch; }
const HTMLEntityTableEntry* mostRecentMatch() const { return m_mostRecentMatch; }
private:
enum CompareResult {
......@@ -52,22 +52,22 @@ private:
};
CompareResult compare(const HTMLEntityTableEntry*, UChar) const;
const HTMLEntityTableEntry* findStart(UChar) const;
const HTMLEntityTableEntry* findEnd(UChar) const;
const HTMLEntityTableEntry* findFirst(UChar) const;
const HTMLEntityTableEntry* findLast(UChar) const;
void fail()
{
m_currentValue = 0;
m_start = 0;
m_end = 0;
m_first = 0;
m_last = 0;
}
int m_currentLength;
int m_currentValue;
const HTMLEntityTableEntry* m_lastMatch;
const HTMLEntityTableEntry* m_start;
const HTMLEntityTableEntry* m_end;
const HTMLEntityTableEntry* m_mostRecentMatch;
const HTMLEntityTableEntry* m_first;
const HTMLEntityTableEntry* m_last;
};
}
......
......@@ -40,11 +40,11 @@ struct HTMLEntityTableEntry {
class HTMLEntityTable {
public:
static const HTMLEntityTableEntry* start();
static const HTMLEntityTableEntry* end();
static const HTMLEntityTableEntry* firstEntry();
static const HTMLEntityTableEntry* lastEntry();
static const HTMLEntityTableEntry* start(UChar);
static const HTMLEntityTableEntry* end(UChar);
static const HTMLEntityTableEntry* firstEntryStartingWith(UChar);
static const HTMLEntityTableEntry* lastEntryStartingWith(UChar);
};
}
......
2010-08-13 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
Rename some concepts in HTML entity search to be more self-documenting
https://bugs.webkit.org/show_bug.cgi?id=44004
Reflect name change in generator script.
* Scripts/create-html-entity-table:
2010-08-12 Adam Barth <abarth@webkit.org>
Reviewed by Eric Seidel.
......
......@@ -145,7 +145,7 @@ print >> output_file, """};
}
const HTMLEntityTableEntry* HTMLEntityTable::start(UChar c)
const HTMLEntityTableEntry* HTMLEntityTable::firstEntryStartingWith(UChar c)
{
if (c >= 'A' && c <= 'Z')
return uppercaseOffset[c - 'A'];
......@@ -154,7 +154,7 @@ const HTMLEntityTableEntry* HTMLEntityTable::start(UChar c)
return 0;
}
const HTMLEntityTableEntry* HTMLEntityTable::end(UChar c)
const HTMLEntityTableEntry* HTMLEntityTable::lastEntryStartingWith(UChar c)
{
if (c >= 'A' && c <= 'Z')
return uppercaseOffset[c - 'A' + 1] - 1;
......@@ -163,12 +163,12 @@ const HTMLEntityTableEntry* HTMLEntityTable::end(UChar c)
return 0;
}
const HTMLEntityTableEntry* HTMLEntityTable::start()
const HTMLEntityTableEntry* HTMLEntityTable::firstEntry()
{
return &staticEntityTable[0];
}
const HTMLEntityTableEntry* HTMLEntityTable::end()
const HTMLEntityTableEntry* HTMLEntityTable::lastEntry()
{
return &staticEntityTable[%s - 1];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment