VideoPlayer: Fix titlebar issues on video error
[chromium-blink-merge.git] / base / ini_parser.cc
blob7a2bd1c911bd8028cc4f83636d2df2d9b6dd0285
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.
5 #include "base/ini_parser.h"
7 #include "base/logging.h"
8 #include "base/strings/string_tokenizer.h"
10 namespace base {
12 INIParser::INIParser() : used_(false) {}
14 INIParser::~INIParser() {}
16 void INIParser::Parse(const std::string& content) {
17 DCHECK(!used_);
18 used_ = true;
19 base::StringTokenizer tokenizer(content, "\r\n");
21 std::string current_section;
22 while (tokenizer.GetNext()) {
23 std::string line = tokenizer.token();
24 if (line.empty()) {
25 // Skips the empty line.
26 continue;
28 if (line[0] == '#' || line[0] == ';') {
29 // This line is a comment.
30 continue;
32 if (line[0] == '[') {
33 // It is a section header.
34 current_section = line.substr(1);
35 size_t end = current_section.rfind(']');
36 if (end != std::string::npos)
37 current_section.erase(end);
38 } else {
39 std::string key, value;
40 size_t equal = line.find('=');
41 if (equal != std::string::npos) {
42 key = line.substr(0, equal);
43 value = line.substr(equal + 1);
44 HandleTriplet(current_section, key, value);
50 DictionaryValueINIParser::DictionaryValueINIParser() {}
52 DictionaryValueINIParser::~DictionaryValueINIParser() {}
54 void DictionaryValueINIParser::HandleTriplet(const std::string& section,
55 const std::string& key,
56 const std::string& value) {
58 // Checks whether the section and key contain a '.' character.
59 // Those sections and keys break DictionaryValue's path format when not
60 // using the *WithoutPathExpansion methods.
61 if (section.find('.') == std::string::npos &&
62 key.find('.') == std::string::npos)
63 root_.SetString(section + "." + key, value);
66 } // namespace base