Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(109)

Side by Side Diff: base/ini_parser.h

Issue 16982004: Move Firefox importer's INI parser to c/browser/common. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef BASE_INI_PARSER_H_
6 #define BASE_INI_PARSER_H_
7
8 #include <string>
9
10 #include "base/base_export.h"
11 #include "base/basictypes.h"
12 #include "base/values.h"
13
14 namespace base {
15
16 // A simple class to parse INI files in a string. Users should in inherit from
17 // this class. This is a very basic INI parser with these characteristics:
18 // - Ignores blank lines.
19 // - Ignores comment lines beginning with '#' or ';'.
20 // - Duplicate key names in the same section will simply cause repeated calls
21 // to HandleTriplet with the same |section| and |key| parameters.
22 // - No escape characters supported.
23 // - Global properties result in calls to HandleTriplet with an empty string in
24 // the |section| argument.
25 // - Section headers begin with a '[' character. It is recommended, but
26 // not required to close the header bracket with a ']' character. All
27 // characters after a closing ']' character is ignored.
28 // - Key value pairs are indicated with an '=' character. Whitespace is not
29 // ignored. Quoting is not supported. Everything before the first '='
30 // is considered the |key|, and everything after is the |value|.
31 class BASE_EXPORT INIParser {
32 public:
33 INIParser();
34 virtual ~INIParser();
35
36 void Parse(const std::string& content);
37
38 private:
39 virtual void HandleTriplet(const std::string& section, const std::string& key,
40 const std::string& value) = 0;
41
42 DISALLOW_COPY_AND_ASSIGN(INIParser);
43 };
44
45 // Parsed values are stored as strings at the "section.key" path. Triplets with
46 // |section| or |key| parameters containing '.' are ignored.
47 class BASE_EXPORT DictionaryValueINIParser : public INIParser {
48 public:
49 DictionaryValueINIParser();
50 virtual ~DictionaryValueINIParser();
51
52 const DictionaryValue& root() const { return root_; }
53
54 private:
55 virtual void HandleTriplet(const std::string& section, const std::string& key,
56 const std::string& value) OVERRIDE;
57
58 DictionaryValue root_;
59
60 DISALLOW_COPY_AND_ASSIGN(DictionaryValueINIParser);
61 };
62
63 } // namespace base
64
65 #endif // BASE_INI_PARSER_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/ini_parser.cc » ('j') | base/ini_parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698