diff options
Diffstat (limited to 'core/fpdfapi')
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser.cpp | 34 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser.h | 7 | ||||
-rw-r--r-- | core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp | 36 |
3 files changed, 2 insertions, 75 deletions
diff --git a/core/fpdfapi/parser/cpdf_simple_parser.cpp b/core/fpdfapi/parser/cpdf_simple_parser.cpp index 47ce1ad55e..45ea0d4528 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser.cpp +++ b/core/fpdfapi/parser/cpdf_simple_parser.cpp @@ -6,8 +6,6 @@ #include "core/fpdfapi/parser/cpdf_simple_parser.h" -#include <vector> - #include "core/fpdfapi/parser/fpdf_parser_utility.h" CPDF_SimpleParser::CPDF_SimpleParser(const ByteStringView& str) : data_(str) {} @@ -129,35 +127,3 @@ ByteStringView CPDF_SimpleParser::GetWord() { } return data_.Mid(start_pos, dwSize); } - -bool CPDF_SimpleParser::FindTagParamFromStart(const ByteStringView& token, - int nParams) { - nParams++; - - std::vector<uint32_t> pBuf(nParams); - int buf_index = 0; - int buf_count = 0; - cur_pos_ = 0; - while (1) { - pBuf[buf_index++] = cur_pos_; - if (buf_index == nParams) - buf_index = 0; - - buf_count++; - if (buf_count > nParams) - buf_count = nParams; - - ByteStringView word = GetWord(); - if (word.IsEmpty()) - return false; - - if (word == token) { - if (buf_count < nParams) - continue; - - cur_pos_ = pBuf[buf_index]; - return true; - } - } - return false; -} diff --git a/core/fpdfapi/parser/cpdf_simple_parser.h b/core/fpdfapi/parser/cpdf_simple_parser.h index f02a58c98b..8a07323a69 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser.h +++ b/core/fpdfapi/parser/cpdf_simple_parser.h @@ -19,11 +19,8 @@ class CPDF_SimpleParser { ByteStringView GetWord(); - // Find the token and its |nParams| parameters from the start of data, - // and move the current position to the start of those parameters. - bool FindTagParamFromStart(const ByteStringView& token, int nParams); - - uint32_t GetCurPosForTest() const { return cur_pos_; } + void SetCurPos(uint32_t pos) { cur_pos_ = pos; } + uint32_t GetCurPos() const { return cur_pos_; } private: const ByteStringView data_; diff --git a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp index b53b6c6c7f..2fb50f1ff3 100644 --- a/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_simple_parser_unittest.cpp @@ -59,39 +59,3 @@ TEST(SimpleParserTest, GetWord) { << " for case " << i; } } - -TEST(SimpleParserTest, FindTagParamFromStart) { - static const struct FindTagTestStruct { - const unsigned char* input; - unsigned int input_size; - const char* token; - int num_params; - bool result; - unsigned int result_pos; - } test_data[] = { - // Empty strings. - STR_IN_TEST_CASE("", "Tj", 1, false, 0), - STR_IN_TEST_CASE("", "", 1, false, 0), - // Empty token. - STR_IN_TEST_CASE(" T j", "", 1, false, 5), - // No parameter. - STR_IN_TEST_CASE("Tj", "Tj", 1, false, 2), - STR_IN_TEST_CASE("(Tj", "Tj", 1, false, 3), - // Partial token match. - STR_IN_TEST_CASE("\r12\t34 56 78Tj", "Tj", 1, false, 15), - // Regular cases with various parameters. - STR_IN_TEST_CASE("\r\0abd Tj", "Tj", 1, true, 0), - STR_IN_TEST_CASE("12 4 Tj 3 46 Tj", "Tj", 1, true, 2), - STR_IN_TEST_CASE("er^ 2 (34) (5667) Tj", "Tj", 2, true, 5), - STR_IN_TEST_CASE("<344> (232)\t343.4\n12 45 Tj", "Tj", 3, true, 11), - STR_IN_TEST_CASE("1 2 3 4 5 6 7 8 cm", "cm", 6, true, 3), - }; - for (size_t i = 0; i < FX_ArraySize(test_data); ++i) { - const FindTagTestStruct& data = test_data[i]; - CPDF_SimpleParser parser(ByteStringView(data.input, data.input_size)); - EXPECT_EQ(data.result, - parser.FindTagParamFromStart(data.token, data.num_params)) - << " for case " << i; - EXPECT_EQ(data.result_pos, parser.GetCurPosForTest()) << " for case " << i; - } -} |