31void RStyleReader::ReadDefaults()
41 void RemoveComment(std::string&
line)
43 auto posComment =
line.find(
'#');
44 if (posComment != std::string::npos)
45 line.erase(posComment - 1);
49 std::array<std::string_view, 2> SeparateKeyValue(
const std::string&
line)
51 std::string::size_type posColon =
line.find(
':');
52 if (posColon == std::string::npos)
54 std::array<std::string_view, 2> ret{{
line,
line}};
55 ret[0] = ret[0].substr(0, posColon);
56 ret[1] = ret[1].substr(posColon + 1);
64 auto begin = ret.begin();
65 for (
auto end = ret.end(); begin != end; ++begin) {
66 if (!std::isspace(*begin))
69 ret.remove_prefix(begin - ret.begin());
71 auto rbegin = ret.rbegin();
72 for (
auto rend = ret.rend(); rbegin != rend; ++rbegin) {
73 if (!std::isspace(*rbegin))
76 ret.remove_suffix(rbegin - ret.rbegin());
83 std::ifstream in(filename);
86 std::string styleName;
89 while (std::getline(in,
line)) {
92 auto noSpaceLine = TrimWhitespace(
line);
93 if (noSpaceLine.compare(0, 1,
"[") == 0 && noSpaceLine.compare(noSpaceLine.length() - 1, 1,
"]")) {
95 noSpaceLine.remove_prefix(1);
96 noSpaceLine.remove_suffix(1);
97 noSpaceLine = TrimWhitespace(noSpaceLine);
98 styleName = std::string(noSpaceLine);
102 auto keyValue = SeparateKeyValue(
line);
103 for (
auto& kv: keyValue)
104 kv = TrimWhitespace(kv);
105 if (keyValue[0].empty()) {
106 R__ERROR_HERE(
"GPrimitive") <<
"Syntax error in style file " << filename <<
":" << lineNo <<
": "
107 <<
"missing key in line \n" <<
line <<
"\nInoring line.";
111 fAttrs[styleName].GetAttribute(std::string(keyValue[0])) = std::string(keyValue[1]);
#define R__ERROR_HERE(GROUP)
R__EXTERN TSystem * gSystem
AllStyles_t & fAttrs
Collection of attributes to read into.
bool AddFromStyleFile(const std::string &filename)
Adds attributes specified in filename to those already existing in fAttrs.
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
virtual std::string GetHomeDirectory(const char *userName=0) const
Return the user's home directory.
basic_string_view< char > string_view