diff options
author | Lei Zhang <thestig@chromium.org> | 2017-11-21 22:07:50 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-11-21 22:07:50 +0000 |
commit | 56e04d2656bdd5f2b9448d857e8e73ab16aadf8e (patch) | |
tree | 57ed8ebed62f498bdd1fe010b0909f162bbcd29c /core/fpdfapi/parser | |
parent | ebe865db548f768038186054fc0f1eb024565c43 (diff) | |
download | pdfium-56e04d2656bdd5f2b9448d857e8e73ab16aadf8e.tar.xz |
Avoid passing pointers by reference in core.
This gets rid of most core/ non-const ref passing, either by passing by
pointer-to-pointer instead, or by returning std::pair.
Change-Id: Id7bdc355a1a725a05f9fa2f1e982ca8c975beef1
Reviewed-on: https://pdfium-review.googlesource.com/19030
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'core/fpdfapi/parser')
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser.cpp | 27 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser.h | 4 |
2 files changed, 17 insertions, 14 deletions
diff --git a/core/fpdfapi/parser/cpdf_simple_parser.cpp b/core/fpdfapi/parser/cpdf_simple_parser.cpp index 5358b183d8..b49f8423c3 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser.cpp +++ b/core/fpdfapi/parser/cpdf_simple_parser.cpp @@ -14,17 +14,17 @@ CPDF_SimpleParser::CPDF_SimpleParser(const uint8_t* pData, uint32_t dwSize) CPDF_SimpleParser::CPDF_SimpleParser(const ByteStringView& str) : m_pData(str.raw_str()), m_dwSize(str.GetLength()), m_dwCurPos(0) {} -void CPDF_SimpleParser::ParseWord(const uint8_t*& pStart, uint32_t& dwSize) { - pStart = nullptr; - dwSize = 0; +std::pair<const uint8_t*, uint32_t> CPDF_SimpleParser::ParseWord() { + const uint8_t* pStart = nullptr; + uint8_t dwSize = 0; uint8_t ch; while (1) { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; while (PDFCharIsWhitespace(ch)) { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; } @@ -33,7 +33,7 @@ void CPDF_SimpleParser::ParseWord(const uint8_t*& pStart, uint32_t& dwSize) { while (1) { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; if (PDFCharIsLineEnding(ch)) break; @@ -46,19 +46,19 @@ void CPDF_SimpleParser::ParseWord(const uint8_t*& pStart, uint32_t& dwSize) { if (ch == '/') { while (1) { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; if (!PDFCharIsOther(ch) && !PDFCharIsNumeric(ch)) { m_dwCurPos--; dwSize = m_dwCurPos - start_pos; - return; + return std::make_pair(pStart, dwSize); } } } else { dwSize = 1; if (ch == '<') { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; if (ch == '<') dwSize = 2; @@ -66,7 +66,7 @@ void CPDF_SimpleParser::ParseWord(const uint8_t*& pStart, uint32_t& dwSize) { m_dwCurPos--; } else if (ch == '>') { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; if (ch == '>') dwSize = 2; @@ -74,13 +74,13 @@ void CPDF_SimpleParser::ParseWord(const uint8_t*& pStart, uint32_t& dwSize) { m_dwCurPos--; } } - return; + return std::make_pair(pStart, dwSize); } dwSize = 1; while (1) { if (m_dwSize <= m_dwCurPos) - return; + return std::make_pair(pStart, dwSize); ch = m_pData[m_dwCurPos++]; if (PDFCharIsDelimiter(ch) || PDFCharIsWhitespace(ch)) { @@ -89,12 +89,13 @@ void CPDF_SimpleParser::ParseWord(const uint8_t*& pStart, uint32_t& dwSize) { } dwSize++; } + return std::make_pair(pStart, dwSize); } ByteStringView CPDF_SimpleParser::GetWord() { const uint8_t* pStart; uint32_t dwSize; - ParseWord(pStart, dwSize); + std::tie(pStart, dwSize) = ParseWord(); if (dwSize == 1 && pStart[0] == '<') { while (m_dwCurPos < m_dwSize && m_pData[m_dwCurPos] != '>') { m_dwCurPos++; diff --git a/core/fpdfapi/parser/cpdf_simple_parser.h b/core/fpdfapi/parser/cpdf_simple_parser.h index 72cf700f60..659039e6fa 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser.h +++ b/core/fpdfapi/parser/cpdf_simple_parser.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFAPI_PARSER_CPDF_SIMPLE_PARSER_H_ #define CORE_FPDFAPI_PARSER_CPDF_SIMPLE_PARSER_H_ +#include <utility> + #include "core/fxcrt/fx_string.h" #include "core/fxcrt/fx_system.h" @@ -25,7 +27,7 @@ class CPDF_SimpleParser { uint32_t GetCurPos() const { return m_dwCurPos; } private: - void ParseWord(const uint8_t*& pStart, uint32_t& dwSize); + std::pair<const uint8_t*, uint32_t> ParseWord(); const uint8_t* m_pData; uint32_t m_dwSize; |