31 #include <unordered_map>
35 #ifdef QT_PROTOBUF_DEBUG_GENERATOR
36 #define QT_PROTOBUF_DEBUG(X) std::cout << X << std::endl
38 #define QT_PROTOBUF_DEBUG(X)
41 namespace google {
namespace protobuf {
45 namespace QtProtobuf {
55 static std::vector<std::string> split(
const std::string &str,
char delim)
57 std::vector<std::string> container;
58 if (str.size() <= 0) {
61 std::stringstream stream(str);
63 while (std::getline(stream, token, delim)) {
64 container.push_back(token);
70 static void replace(std::string &data,
const std::string &from,
const std::string &to) {
71 size_t pos = data.find(from);
72 while (pos != std::string::npos) {
73 data.replace(pos, from.size(), to);
74 pos = data.find(from, pos + to.size());
78 static void tolower(std::string &str) {
79 std::transform(std::begin(str), std::end(str), std::begin(str), ::tolower);
82 static std::string removeFileSuffix(std::string fileName) {
83 size_t index = fileName.rfind(
".");
84 fileName.resize(index);
88 static std::string extractFileBasename(std::string fileName) {
89 size_t index = fileName.rfind(
".");
90 fileName.resize(index);
91 index = fileName.rfind(
"/");
92 if (index != std::string::npos) {
93 return fileName.substr(index + 1, fileName.size() - 1);
99 static std::string upperCaseName(
const std::string &name)
101 std::string upperCaseName(name);
102 upperCaseName[0] =
static_cast<char>(::toupper(upperCaseName[0]));
103 return upperCaseName;
106 static std::string lowerCaseName(
const std::string &name)
108 std::string lowerCaseName(name);
109 lowerCaseName[0] =
static_cast<char>(::tolower(lowerCaseName[0]));
110 return lowerCaseName;
113 inline static std::string& rtrim(std::string& s)
115 s.erase(s.find_last_not_of(
" \t\n\r\f\v") + 1);
120 inline static std::string& ltrim(std::string& s)
122 s.erase(0, s.find_first_not_of(
" \t\n\r\f\v"));
127 inline static std::string& trim(std::string& s)
129 return ltrim(rtrim(s));
134 #define UNUSED(expr) do { (void)(expr); } while (0)
136 using PackagesList = std::unordered_map<std::string, std::list<const ::google::protobuf::FileDescriptor *>>;