summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_syntax_parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi/parser/cpdf_syntax_parser.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp74
1 files changed, 19 insertions, 55 deletions
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 45a5a8a709..e41736dd86 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -90,7 +90,7 @@ bool CPDF_SyntaxParser::GetNextChar(uint8_t& ch) {
return true;
}
-bool CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch) {
+bool CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, uint8_t* ch) {
pos += m_HeaderOffset;
if (pos >= m_FileLen)
return false;
@@ -105,7 +105,7 @@ bool CPDF_SyntaxParser::GetCharAtBackward(FX_FILESIZE pos, uint8_t& ch) {
if (!ReadChar(read_pos, read_size))
return false;
}
- ch = m_pFileBuf[pos - m_BufOffset];
+ *ch = m_pFileBuf[pos - m_BufOffset];
return true;
}
@@ -814,74 +814,38 @@ bool CPDF_SyntaxParser::IsWholeWord(FX_FILESIZE startpos,
return true;
}
-// TODO(dsinclair): Split into a SearchWordForward and SearchWordBackwards
-// and drop the bool.
-bool CPDF_SyntaxParser::SearchWord(const CFX_ByteStringC& tag,
- bool bWholeWord,
- bool bForward,
- FX_FILESIZE limit) {
+bool CPDF_SyntaxParser::BackwardsSearchToWord(const CFX_ByteStringC& tag,
+ FX_FILESIZE limit) {
int32_t taglen = tag.GetLength();
if (taglen == 0)
return false;
FX_FILESIZE pos = m_Pos;
- int32_t offset = 0;
- if (!bForward)
- offset = taglen - 1;
-
- const uint8_t* tag_data = tag.raw_str();
- uint8_t byte;
+ int32_t offset = taglen - 1;
while (1) {
- if (bForward) {
- if (limit && pos >= m_Pos + limit)
- return false;
-
- if (!GetCharAt(pos, byte))
- return false;
-
- } else {
- if (limit && pos <= m_Pos - limit)
- return false;
+ if (limit && pos <= m_Pos - limit)
+ return false;
- if (!GetCharAtBackward(pos, byte))
- return false;
- }
+ uint8_t byte;
+ if (!GetCharAtBackward(pos, &byte))
+ return false;
- if (byte == tag_data[offset]) {
- if (bForward) {
- offset++;
- if (offset < taglen) {
- pos++;
- continue;
- }
- } else {
- offset--;
- if (offset >= 0) {
- pos--;
- continue;
- }
+ if (byte == tag[offset]) {
+ offset--;
+ if (offset >= 0) {
+ pos--;
+ continue;
}
-
- FX_FILESIZE startpos = bForward ? pos - taglen + 1 : pos;
- if (!bWholeWord || IsWholeWord(startpos, limit, tag, false)) {
- m_Pos = startpos;
+ if (IsWholeWord(pos, limit, tag, false)) {
+ m_Pos = pos;
return true;
}
}
-
- if (bForward) {
- offset = byte == tag_data[0] ? 1 : 0;
- pos++;
- } else {
- offset = byte == tag_data[taglen - 1] ? taglen - 2 : taglen - 1;
- pos--;
- }
-
+ offset = byte == tag[taglen - 1] ? taglen - 2 : taglen - 1;
+ pos--;
if (pos < 0)
return false;
}
-
- return false;
}
FX_FILESIZE CPDF_SyntaxParser::FindTag(const CFX_ByteStringC& tag,