diff options
author | Tom Sepez <tsepez@chromium.org> | 2017-05-03 12:37:07 -0700 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-05-03 19:50:58 +0000 |
commit | 0578244a1a68b413e0843b0ecb9c434bd7b6c8af (patch) | |
tree | 624b1b24759a825e72fc7bf94996d068d86ae497 /core/fpdfapi/parser/cpdf_syntax_parser.cpp | |
parent | 746babded81e9de3fc132fd670386382c031fa74 (diff) | |
download | pdfium-0578244a1a68b413e0843b0ecb9c434bd7b6c8af.tar.xz |
CPDF_SyntaxParser::SearchWord() is always backwards and for whole-words
Change-Id: Ic31d9cda5e919a754162e14e69cb63671a3fe8b9
Reviewed-on: https://pdfium-review.googlesource.com/4794
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_syntax_parser.cpp')
-rw-r--r-- | core/fpdfapi/parser/cpdf_syntax_parser.cpp | 74 |
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, |