Commit d02a99d9 authored by Sebastian Holtermann's avatar Sebastian Holtermann

Autogen: Modernize code to use cm::string_view for the info writer

parent bbf4a577
...@@ -156,30 +156,27 @@ std::string cmQtAutoGenInitializer::InfoWriter::ListJoin(IT it_begin, ...@@ -156,30 +156,27 @@ std::string cmQtAutoGenInitializer::InfoWriter::ListJoin(IT it_begin,
return res; return res;
} }
std::string cmQtAutoGenInitializer::InfoWriter::ConfigKey( inline std::string cmQtAutoGenInitializer::InfoWriter::ConfigKey(
const char* key, std::string const& config) cm::string_view key, std::string const& config)
{ {
std::string ckey = key; return cmStrCat(key, "_", config);
ckey += '_';
ckey += config;
return ckey;
} }
void cmQtAutoGenInitializer::InfoWriter::Write(const char* key, void cmQtAutoGenInitializer::InfoWriter::Write(cm::string_view key,
std::string const& value) std::string const& value)
{ {
Ofs_ << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value) Ofs_ << "set(" << key << " " << cmOutputConverter::EscapeForCMake(value)
<< ")\n"; << ")\n";
}; };
void cmQtAutoGenInitializer::InfoWriter::WriteUInt(const char* key, void cmQtAutoGenInitializer::InfoWriter::WriteUInt(cm::string_view key,
unsigned int value) unsigned int value)
{ {
Ofs_ << "set(" << key << " " << value << ")\n"; Ofs_ << "set(" << key << " " << value << ")\n";
}; };
template <class C> template <class C>
void cmQtAutoGenInitializer::InfoWriter::WriteStrings(const char* key, void cmQtAutoGenInitializer::InfoWriter::WriteStrings(cm::string_view key,
C const& container) C const& container)
{ {
Ofs_ << "set(" << key << " \"" Ofs_ << "set(" << key << " \""
...@@ -187,31 +184,29 @@ void cmQtAutoGenInitializer::InfoWriter::WriteStrings(const char* key, ...@@ -187,31 +184,29 @@ void cmQtAutoGenInitializer::InfoWriter::WriteStrings(const char* key,
} }
void cmQtAutoGenInitializer::InfoWriter::WriteConfig( void cmQtAutoGenInitializer::InfoWriter::WriteConfig(
const char* key, std::map<std::string, std::string> const& map) cm::string_view key, std::map<std::string, std::string> const& map)
{ {
for (auto const& item : map) { for (auto const& item : map) {
Write(ConfigKey(key, item.first).c_str(), item.second); Write(ConfigKey(key, item.first), item.second);
} }
}; };
template <class C> template <class C>
void cmQtAutoGenInitializer::InfoWriter::WriteConfigStrings( void cmQtAutoGenInitializer::InfoWriter::WriteConfigStrings(
const char* key, std::map<std::string, C> const& map) cm::string_view key, std::map<std::string, C> const& map)
{ {
for (auto const& item : map) { for (auto const& item : map) {
WriteStrings(ConfigKey(key, item.first).c_str(), item.second); WriteStrings(ConfigKey(key, item.first), item.second);
} }
} }
void cmQtAutoGenInitializer::InfoWriter::WriteNestedLists( void cmQtAutoGenInitializer::InfoWriter::WriteNestedLists(
const char* key, std::vector<std::vector<std::string>> const& lists) cm::string_view key, std::vector<std::vector<std::string>> const& lists)
{ {
std::vector<std::string> seplist; std::vector<std::string> seplist;
for (const std::vector<std::string>& list : lists) { seplist.reserve(lists.size());
std::string blist = "{"; for (std::vector<std::string> const& list : lists) {
blist += ListJoin(list.begin(), list.end()); seplist.push_back(cmStrCat("{", ListJoin(list.begin(), list.end()), "}"));
blist += "}";
seplist.push_back(std::move(blist));
} }
Write(key, cmJoin(seplist, cmQtAutoGen::ListSep)); Write(key, cmJoin(seplist, cmQtAutoGen::ListSep));
}; };
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep #include "cmConfigure.h" // IWYU pragma: keep
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmQtAutoGen.h" #include "cmQtAutoGen.h"
#include "cm_string_view.hxx"
#include <map> #include <map>
#include <memory> #include <memory>
...@@ -85,24 +86,24 @@ public: ...@@ -85,24 +86,24 @@ public:
/// @return True if the file is open /// @return True if the file is open
explicit operator bool() const { return static_cast<bool>(Ofs_); } explicit operator bool() const { return static_cast<bool>(Ofs_); }
void Write(const char* text) { Ofs_ << text; } void Write(cm::string_view text) { Ofs_ << text; }
void Write(const char* key, std::string const& value); void Write(cm::string_view, std::string const& value);
void WriteUInt(const char* key, unsigned int value); void WriteUInt(cm::string_view, unsigned int value);
template <class C> template <class C>
void WriteStrings(const char* key, C const& container); void WriteStrings(cm::string_view, C const& container);
void WriteConfig(const char* key, void WriteConfig(cm::string_view,
std::map<std::string, std::string> const& map); std::map<std::string, std::string> const& map);
template <class C> template <class C>
void WriteConfigStrings(const char* key, void WriteConfigStrings(cm::string_view,
std::map<std::string, C> const& map); std::map<std::string, C> const& map);
void WriteNestedLists(const char* key, void WriteNestedLists(cm::string_view,
std::vector<std::vector<std::string>> const& lists); std::vector<std::vector<std::string>> const& lists);
private: private:
template <class IT> template <class IT>
static std::string ListJoin(IT it_begin, IT it_end); static std::string ListJoin(IT it_begin, IT it_end);
static std::string ConfigKey(const char* key, std::string const& config); static std::string ConfigKey(cm::string_view, std::string const& config);
private: private:
cmGeneratedFileStream Ofs_; cmGeneratedFileStream Ofs_;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment