summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 22:44:25 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-08-11 22:44:25 +0000
commit67b69ebfe95f945fa7f4176dd8c7e89c4ad2e024 (patch)
treea5040784ff78458f5cda7db48cbee0f665a057b4 /base
parent7559b66f2befe412db72cc072c187892b0486aae (diff)
downloadchromium_src-67b69ebfe95f945fa7f4176dd8c7e89c4ad2e024.zip
chromium_src-67b69ebfe95f945fa7f4176dd8c7e89c4ad2e024.tar.gz
chromium_src-67b69ebfe95f945fa7f4176dd8c7e89c4ad2e024.tar.bz2
Move ini_parser from base to chrome/common
This was moved to base apparently thinking it could be shared with a media gallery thing that seems not to have panned out. Review URL: https://codereview.chromium.org/453703002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@288814 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/BUILD.gn3
-rw-r--r--base/base.gyp1
-rw-r--r--base/base.gypi2
-rw-r--r--base/ini_parser.cc66
-rw-r--r--base/ini_parser.h69
-rw-r--r--base/ini_parser_unittest.cc131
6 files changed, 0 insertions, 272 deletions
diff --git a/base/BUILD.gn b/base/BUILD.gn
index 97588b6..3c0597b 100644
--- a/base/BUILD.gn
+++ b/base/BUILD.gn
@@ -231,8 +231,6 @@ component("base") {
"hash.cc",
"hash.h",
"id_map.h",
- "ini_parser.cc",
- "ini_parser.h",
"ios/device_util.h",
"ios/device_util.mm",
"ios/ios_util.h",
@@ -1108,7 +1106,6 @@ test("base_unittests") {
"i18n/string_search_unittest.cc",
"i18n/time_formatting_unittest.cc",
"i18n/timezone_unittest.cc",
- "ini_parser_unittest.cc",
"ios/device_util_unittest.mm",
"json/json_parser_unittest.cc",
"json/json_reader_unittest.cc",
diff --git a/base/base.gyp b/base/base.gyp
index 831681f..2eaa614 100644
--- a/base/base.gyp
+++ b/base/base.gyp
@@ -481,7 +481,6 @@
'i18n/string_search_unittest.cc',
'i18n/time_formatting_unittest.cc',
'i18n/timezone_unittest.cc',
- 'ini_parser_unittest.cc',
'ios/device_util_unittest.mm',
'json/json_parser_unittest.cc',
'json/json_reader_unittest.cc',
diff --git a/base/base.gypi b/base/base.gypi
index d5eb0ca..7560e8f 100644
--- a/base/base.gypi
+++ b/base/base.gypi
@@ -236,8 +236,6 @@
'hash.cc',
'hash.h',
'id_map.h',
- 'ini_parser.cc',
- 'ini_parser.h',
'ios/device_util.h',
'ios/device_util.mm',
'ios/ios_util.h',
diff --git a/base/ini_parser.cc b/base/ini_parser.cc
deleted file mode 100644
index 7a2bd1c..0000000
--- a/base/ini_parser.cc
+++ /dev/null
@@ -1,66 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "base/ini_parser.h"
-
-#include "base/logging.h"
-#include "base/strings/string_tokenizer.h"
-
-namespace base {
-
-INIParser::INIParser() : used_(false) {}
-
-INIParser::~INIParser() {}
-
-void INIParser::Parse(const std::string& content) {
- DCHECK(!used_);
- used_ = true;
- base::StringTokenizer tokenizer(content, "\r\n");
-
- std::string current_section;
- while (tokenizer.GetNext()) {
- std::string line = tokenizer.token();
- if (line.empty()) {
- // Skips the empty line.
- continue;
- }
- if (line[0] == '#' || line[0] == ';') {
- // This line is a comment.
- continue;
- }
- if (line[0] == '[') {
- // It is a section header.
- current_section = line.substr(1);
- size_t end = current_section.rfind(']');
- if (end != std::string::npos)
- current_section.erase(end);
- } else {
- std::string key, value;
- size_t equal = line.find('=');
- if (equal != std::string::npos) {
- key = line.substr(0, equal);
- value = line.substr(equal + 1);
- HandleTriplet(current_section, key, value);
- }
- }
- }
-}
-
-DictionaryValueINIParser::DictionaryValueINIParser() {}
-
-DictionaryValueINIParser::~DictionaryValueINIParser() {}
-
-void DictionaryValueINIParser::HandleTriplet(const std::string& section,
- const std::string& key,
- const std::string& value) {
-
- // Checks whether the section and key contain a '.' character.
- // Those sections and keys break DictionaryValue's path format when not
- // using the *WithoutPathExpansion methods.
- if (section.find('.') == std::string::npos &&
- key.find('.') == std::string::npos)
- root_.SetString(section + "." + key, value);
-}
-
-} // namespace base
diff --git a/base/ini_parser.h b/base/ini_parser.h
deleted file mode 100644
index 0aa7754..0000000
--- a/base/ini_parser.h
+++ /dev/null
@@ -1,69 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef BASE_INI_PARSER_H_
-#define BASE_INI_PARSER_H_
-
-#include <string>
-
-#include "base/base_export.h"
-#include "base/basictypes.h"
-#include "base/values.h"
-
-namespace base {
-
-// Parses INI files in a string. Users should in inherit from this class.
-// This is a very basic INI parser with these characteristics:
-// - Ignores blank lines.
-// - Ignores comment lines beginning with '#' or ';'.
-// - Duplicate key names in the same section will simply cause repeated calls
-// to HandleTriplet with the same |section| and |key| parameters.
-// - No escape characters supported.
-// - Global properties result in calls to HandleTriplet with an empty string in
-// the |section| argument.
-// - Section headers begin with a '[' character. It is recommended, but
-// not required to close the header bracket with a ']' character. All
-// characters after a closing ']' character is ignored.
-// - Key value pairs are indicated with an '=' character. Whitespace is not
-// ignored. Quoting is not supported. Everything before the first '='
-// is considered the |key|, and everything after is the |value|.
-class BASE_EXPORT INIParser {
- public:
- INIParser();
- virtual ~INIParser();
-
- // May only be called once per instance.
- void Parse(const std::string& content);
-
- private:
- virtual void HandleTriplet(const std::string& section,
- const std::string& key,
- const std::string& value) = 0;
-
- bool used_;
-};
-
-// Parsed values are stored as strings at the "section.key" path. Triplets with
-// |section| or |key| parameters containing '.' are ignored.
-class BASE_EXPORT DictionaryValueINIParser : public INIParser {
- public:
- DictionaryValueINIParser();
- virtual ~DictionaryValueINIParser();
-
- const DictionaryValue& root() const { return root_; }
-
- private:
- // INIParser implementation.
- virtual void HandleTriplet(const std::string& section,
- const std::string& key,
- const std::string& value) OVERRIDE;
-
- DictionaryValue root_;
-
- DISALLOW_COPY_AND_ASSIGN(DictionaryValueINIParser);
-};
-
-} // namespace base
-
-#endif // BASE_INI_PARSER_H_
diff --git a/base/ini_parser_unittest.cc b/base/ini_parser_unittest.cc
deleted file mode 100644
index ff90f6c..0000000
--- a/base/ini_parser_unittest.cc
+++ /dev/null
@@ -1,131 +0,0 @@
-// Copyright 2013 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include <string>
-#include <vector>
-
-#include "base/ini_parser.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace base {
-
-namespace {
-
-struct TestTriplet {
- TestTriplet(const std::string& section,
- const std::string& key,
- const std::string& value)
- : section(section),
- key(key),
- value(value) {
- }
-
- std::string section;
- std::string key;
- std::string value;
-};
-
-class TestINIParser : public INIParser {
- public:
- explicit TestINIParser(
- const std::vector<TestTriplet>& expected_triplets)
- : expected_triplets_(expected_triplets),
- pair_i_(0) {
- }
- virtual ~TestINIParser() {}
-
- size_t pair_i() {
- return pair_i_;
- }
-
- private:
- virtual void HandleTriplet(const std::string& section, const std::string& key,
- const std::string& value) OVERRIDE {
- EXPECT_EQ(expected_triplets_[pair_i_].section, section);
- EXPECT_EQ(expected_triplets_[pair_i_].key, key);
- EXPECT_EQ(expected_triplets_[pair_i_].value, value);
- ++pair_i_;
- }
-
- std::vector<TestTriplet> expected_triplets_;
- size_t pair_i_;
-};
-
-TEST(INIParserTest, BasicValid) {
- std::vector<TestTriplet> expected_triplets;
- expected_triplets.push_back(TestTriplet("section1", "key1", "value1"));
- expected_triplets.push_back(TestTriplet("section1", "key2", "value2"));
- expected_triplets.push_back(TestTriplet("section1", "key3", "value3"));
- expected_triplets.push_back(TestTriplet("section2", "key4", "value4"));
- expected_triplets.push_back(TestTriplet("section2", "key5",
- "value=with=equals"));
- expected_triplets.push_back(TestTriplet("section2", "key6", "value6"));
- TestINIParser test_parser(expected_triplets);
-
- test_parser.Parse(
- "[section1]\n"
- "key1=value1\n"
- "key2=value2\r\n" // Testing DOS "\r\n" line endings.
- "key3=value3\n"
- "[section2\n" // Testing omitted closing bracket.
- "key4=value4\r" // Testing "\r" line endings.
- "key5=value=with=equals\n"
- "key6=value6"); // Testing omitted final line ending.
-}
-
-TEST(INIParserTest, IgnoreBlankLinesAndComments) {
- std::vector<TestTriplet> expected_triplets;
- expected_triplets.push_back(TestTriplet("section1", "key1", "value1"));
- expected_triplets.push_back(TestTriplet("section1", "key2", "value2"));
- expected_triplets.push_back(TestTriplet("section1", "key3", "value3"));
- expected_triplets.push_back(TestTriplet("section2", "key4", "value4"));
- expected_triplets.push_back(TestTriplet("section2", "key5", "value5"));
- expected_triplets.push_back(TestTriplet("section2", "key6", "value6"));
- TestINIParser test_parser(expected_triplets);
-
- test_parser.Parse(
- "\n"
- "[section1]\n"
- "key1=value1\n"
- "\n"
- "\n"
- "key2=value2\n"
- "key3=value3\n"
- "\n"
- ";Comment1"
- "\n"
- "[section2]\n"
- "key4=value4\n"
- "#Comment2\n"
- "key5=value5\n"
- "\n"
- "key6=value6\n");
-}
-
-TEST(INIParserTest, DictionaryValueINIParser) {
- DictionaryValueINIParser test_parser;
-
- test_parser.Parse(
- "[section1]\n"
- "key1=value1\n"
- "key.2=value2\n"
- "key3=va.lue3\n"
- "[se.ction2]\n"
- "key.4=value4\n"
- "key5=value5\n");
-
- const DictionaryValue& root = test_parser.root();
- std::string value;
- EXPECT_TRUE(root.GetString("section1.key1", &value));
- EXPECT_EQ("value1", value);
- EXPECT_FALSE(root.GetString("section1.key.2", &value));
- EXPECT_TRUE(root.GetString("section1.key3", &value));
- EXPECT_EQ("va.lue3", value);
- EXPECT_FALSE(root.GetString("se.ction2.key.4", &value));
- EXPECT_FALSE(root.GetString("se.ction2.key5", &value));
-}
-
-} // namespace
-
-} // namespace base