36 void RemoveComment(std::string& line)
38 auto posComment = line.find('#');
39 if (posComment != std::string::npos)
40 line.erase(posComment - 1);
44 std::array<std::string_view, 2> SeparateKeyValue(const std::string& line)
46 std::string::size_type posColon = line.find(':');
47 if (posColon == std::string::npos)
49 std::array<std::string_view, 2> ret{{line, line}};
50 ret[0] = ret[0].substr(0, posColon);
51 ret[1] = ret[1].substr(posColon + 1);
56 std::string_view TrimWhitespace(std::string_view view)
58 std::string_view ret(view);
59 auto begin = ret.begin();
60 for (auto end = ret.end(); begin != end; ++begin) {
61 if (!std::isspace(*begin))
64 ret.remove_prefix(begin - ret.begin());
66 auto rbegin = ret.rbegin();
67 for (auto rend = ret.rend(); rbegin != rend; ++rbegin) {
68 if (!std::isspace(*rbegin))
71 ret.remove_suffix(rbegin - ret.rbegin());
76bool RStyleReader::AddFromStyleFile(const std::string &filename)
78 std::ifstream in(filename);
81 std::string styleName;
84 while (std::getline(in, line)) {
87 auto noSpaceLine = TrimWhitespace(line);
88 if (noSpaceLine.compare(0, 1, "[") == 0 && noSpaceLine.compare(noSpaceLine.length() - 1, 1, "]")) {
89 // A section introducing a style name.
90 noSpaceLine.remove_prefix(1); // [
91 noSpaceLine.remove_suffix(1); // ]
92 noSpaceLine = TrimWhitespace(noSpaceLine);
93 styleName = std::string(noSpaceLine);
97 auto keyValue = SeparateKeyValue(line);
98 for (auto& kv: keyValue)
99 kv = TrimWhitespace(kv);
100 if (keyValue[0].empty()) {
101 R__ERROR_HERE("GPrimitive") << "Syntax error in style file " << filename << ":" << lineNo << ": "
102 << "missing key in line \n" << line << "\nInoring line.";
106 fAttrs[styleName].GetAttribute(std::string(keyValue[0])) = std::string(keyValue[1]);