summaryrefslogtreecommitdiff
path: root/xfa/fxfa
diff options
context:
space:
mode:
authorRyan Harrison <rharrison@chromium.org>2017-07-24 15:53:33 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-07-24 20:20:13 +0000
commit275f180ad871ad75600c810056acea57c1077611 (patch)
treead7004bb5973c56851fbf7cc71d3157f4960ebef /xfa/fxfa
parentfc90e851f862be65eb05051437344975f3855a43 (diff)
downloadpdfium-275f180ad871ad75600c810056acea57c1077611.tar.xz
Rename FMLexer methods to be more descriptive
The existing methods had either very bare passive or in some cases misleading names, so this CL changes them active names that describe what they do. This also extracts the IsKeyword method into a helper function since it is actually static. BUG=pdfium:816 Change-Id: I47a113bc9ea8d88a77822a4441266ec56e6b4cbc Reviewed-on: https://pdfium-review.googlesource.com/8730 Commit-Queue: Ryan Harrison <rharrison@chromium.org> Reviewed-by: Tom Sepez <tsepez@chromium.org> Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fxfa')
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmlexer.cpp55
-rw-r--r--xfa/fxfa/fm2js/cxfa_fmlexer.h10
2 files changed, 33 insertions, 32 deletions
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp
index 0b94cde944..04db1dbe1c 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer.cpp
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer.cpp
@@ -95,6 +95,20 @@ const XFA_FMKeyword keyWords[] = {
const XFA_FM_TOKEN KEYWORD_START = TOKdo;
const XFA_FM_TOKEN KEYWORD_END = TOKendif;
+XFA_FM_TOKEN TokenizeIdentifier(const CFX_WideStringC& str) {
+ uint32_t key = FX_HashCode_GetW(str, true);
+
+ const XFA_FMKeyword* result =
+ std::lower_bound(std::begin(keyWords) + KEYWORD_START, std::end(keyWords),
+ key, [](const XFA_FMKeyword& iter, const uint32_t& val) {
+ return iter.m_uHash < val;
+ });
+ if (result != std::end(keyWords) && result->m_uHash == key) {
+ return result->m_type;
+ }
+ return TOKidentifier;
+}
+
} // namespace
const wchar_t* XFA_FM_KeywordToString(XFA_FM_TOKEN op) {
@@ -136,12 +150,12 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() {
++m_ptr;
break;
case ';': {
- m_ptr = Comment(m_ptr);
+ m_ptr = AdvanceForComment(m_ptr);
break;
}
case '"': {
m_pToken->m_type = TOKstring;
- m_ptr = String(m_pToken.get(), m_ptr);
+ m_ptr = AdvanceForString(m_pToken.get(), m_ptr);
return m_pToken.get();
}
case '0':
@@ -155,7 +169,7 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() {
case '8':
case '9': {
m_pToken->m_type = TOKnumber;
- m_ptr = Number(m_pToken.get(), m_ptr);
+ m_ptr = AdvanceForNumber(m_pToken.get(), m_ptr);
return m_pToken.get();
}
case '=':
@@ -270,7 +284,7 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() {
m_pToken->m_type = TOKdiv;
return m_pToken.get();
}
- m_ptr = Comment(m_ptr);
+ m_ptr = AdvanceForComment(m_ptr);
break;
}
case '.':
@@ -293,7 +307,7 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() {
} else if (*m_ptr <= '9' && *m_ptr >= '0') {
m_pToken->m_type = TOKnumber;
--m_ptr;
- m_ptr = Number(m_pToken.get(), m_ptr);
+ m_ptr = AdvanceForNumber(m_pToken.get(), m_ptr);
} else {
m_pToken->m_type = TOKdot;
}
@@ -312,7 +326,7 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() {
m_LexerError = true;
return m_pToken.get();
}
- m_ptr = Identifiers(m_pToken.get(), m_ptr);
+ m_ptr = AdvanceForIdentifier(m_pToken.get(), m_ptr);
return m_pToken.get();
}
}
@@ -324,8 +338,9 @@ CXFA_FMToken* CXFA_FMLexer::NextToken() {
return m_pToken.get();
}
-const wchar_t* CXFA_FMLexer::Number(CXFA_FMToken* t, const wchar_t* p) {
- // This will set pEnd to the character after the end of the number.
+const wchar_t* CXFA_FMLexer::AdvanceForNumber(CXFA_FMToken* t,
+ const wchar_t* p) {
+ // This will set pEnd to the character after the end of the AdvanceForNumber.
wchar_t* pEnd = nullptr;
if (p)
wcstod(const_cast<wchar_t*>(p), &pEnd);
@@ -338,7 +353,8 @@ const wchar_t* CXFA_FMLexer::Number(CXFA_FMToken* t, const wchar_t* p) {
return pEnd;
}
-const wchar_t* CXFA_FMLexer::String(CXFA_FMToken* t, const wchar_t* p) {
+const wchar_t* CXFA_FMLexer::AdvanceForString(CXFA_FMToken* t,
+ const wchar_t* p) {
const wchar_t* start = p;
++p;
while (p <= m_end && *p) {
@@ -372,7 +388,8 @@ const wchar_t* CXFA_FMLexer::String(CXFA_FMToken* t, const wchar_t* p) {
return p;
}
-const wchar_t* CXFA_FMLexer::Identifiers(CXFA_FMToken* t, const wchar_t* p) {
+const wchar_t* CXFA_FMLexer::AdvanceForIdentifier(CXFA_FMToken* t,
+ const wchar_t* p) {
const wchar_t* pStart = p;
++p;
while (p <= m_end && *p) {
@@ -388,11 +405,11 @@ const wchar_t* CXFA_FMLexer::Identifiers(CXFA_FMToken* t, const wchar_t* p) {
++p;
}
t->m_wstring = CFX_WideStringC(pStart, (p - pStart));
- t->m_type = IsKeyword(t->m_wstring);
+ t->m_type = TokenizeIdentifier(t->m_wstring);
return p;
}
-const wchar_t* CXFA_FMLexer::Comment(const wchar_t* p) {
+const wchar_t* CXFA_FMLexer::AdvanceForComment(const wchar_t* p) {
p++;
while (p <= m_end && *p) {
if (*p == L'\r')
@@ -405,17 +422,3 @@ const wchar_t* CXFA_FMLexer::Comment(const wchar_t* p) {
}
return p;
}
-
-XFA_FM_TOKEN CXFA_FMLexer::IsKeyword(const CFX_WideStringC& str) {
- uint32_t key = FX_HashCode_GetW(str, true);
- auto cmpFunc = [](const XFA_FMKeyword& iter, const uint32_t& val) {
- return iter.m_uHash < val;
- };
-
- const XFA_FMKeyword* result = std::lower_bound(
- std::begin(keyWords) + KEYWORD_START, std::end(keyWords), key, cmpFunc);
- if (result <= keyWords + KEYWORD_END && result->m_uHash == key) {
- return result->m_type;
- }
- return TOKidentifier;
-}
diff --git a/xfa/fxfa/fm2js/cxfa_fmlexer.h b/xfa/fxfa/fm2js/cxfa_fmlexer.h
index 11076f8d72..b1f0552b40 100644
--- a/xfa/fxfa/fm2js/cxfa_fmlexer.h
+++ b/xfa/fxfa/fm2js/cxfa_fmlexer.h
@@ -119,12 +119,10 @@ class CXFA_FMLexer {
void SetPos(const wchar_t* pPos) { m_ptr = pPos; }
private:
- const wchar_t* Number(CXFA_FMToken* t, const wchar_t* p);
- const wchar_t* String(CXFA_FMToken* t, const wchar_t* p);
- const wchar_t* Identifiers(CXFA_FMToken* t, const wchar_t* p);
- const wchar_t* Comment(const wchar_t* p);
-
- XFA_FM_TOKEN IsKeyword(const CFX_WideStringC& p);
+ const wchar_t* AdvanceForNumber(CXFA_FMToken* t, const wchar_t* p);
+ const wchar_t* AdvanceForString(CXFA_FMToken* t, const wchar_t* p);
+ const wchar_t* AdvanceForIdentifier(CXFA_FMToken* t, const wchar_t* p);
+ const wchar_t* AdvanceForComment(const wchar_t* p);
const wchar_t* m_ptr;
const wchar_t* const m_end;