#include <algorithm>
#include <cctype>
+#include <experimental/iterator>
#include <fstream>
#include <iostream>
#include <iterator>
return k;
}
+void ConfFile::check_old_style_section_names(const std::vector<std::string>& prefixes,
+ std::ostream& os)
+{
+ // Warn about section names that look like old-style section names
+ std::vector<std::string> old_style_section_names;
+ for (auto& [name, section] : *this) {
+ for (auto& prefix : prefixes) {
+ if (name.find(prefix) == 0 && name.size() > 3 && name[3] != '.') {
+ old_style_section_names.push_back(name);
+ }
+ }
+ }
+ if (!old_style_section_names.empty()) {
+ os << "ERROR! old-style section name(s) found: ";
+ std::copy(std::begin(old_style_section_names),
+ std::end(old_style_section_names),
+ std::experimental::make_ostream_joiner(os, ", "));
+ os << ". Please use the new style section names that include a period.";
+ }
+}
+
std::ostream &operator<<(std::ostream &oss, const ConfFile &cf)
{
for (auto& [name, section] : cf) {
int read(const std::string& section, std::string_view key,
std::string &val) const;
static std::string normalize_key_name(std::string_view key);
+ // print warnings to os if any old-style section name is found
+ //
+ // consider a section name as old-style name if it starts with any of the
+ // given prefixes, but does not follow with a "."
+ void check_old_style_section_names(const std::vector<std::string>& prefixes,
+ std::ostream& os);
+
private:
bool load_from_buffer(std::string_view buf, std::ostream* warning);
};
}
}
}
-
- // Warn about section names that look like old-style section names
- std::deque < std::string > old_style_section_names;
- for (auto& [name, section] : cf) {
- if (((name.find("mds") == 0) || (name.find("mon") == 0) ||
- (name.find("osd") == 0)) && (name.size() > 3) && (name[3] != '.')) {
- old_style_section_names.push_back(name);
- }
- }
- if (!old_style_section_names.empty()) {
- ostringstream oss;
- cerr << "ERROR! old-style section name(s) found: ";
- string sep;
- for (std::deque < std::string >::const_iterator os = old_style_section_names.begin();
- os != old_style_section_names.end(); ++os) {
- cerr << sep << *os;
- sep = ", ";
- }
- cerr << ". Please use the new style section names that include a period.";
- }
-
+ cf.check_old_style_section_names({"mds", "mon", "osd"}, cerr);
update_legacy_vals(values);
-
return 0;
}