forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrings_class.cpp
108 lines (90 loc) · 2.39 KB
/
strings_class.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Aseprite Code Generator
// Copyright (c) 2016-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#include "gen/strings_class.h"
#include "base/fs.h"
#include "base/replace_string.h"
#include "base/string.h"
#include "cfg/cfg.h"
#include <iostream>
static std::string to_cpp(std::string stringId)
{
base::replace_string(stringId, ".", "_");
return stringId;
}
void gen_strings_class(const std::string& inputFn)
{
cfg::CfgFile cfg;
cfg.load(inputFn);
std::cout
<< "// Don't modify, generated file from " << inputFn << "\n"
<< "\n";
std::cout
<< "#ifndef GENERATED_STRINGS_INI_H_INCLUDED\n"
<< "#define GENERATED_STRINGS_INI_H_INCLUDED\n"
<< "#pragma once\n"
<< "\n"
<< "namespace app {\n"
<< "namespace gen {\n"
<< "\n"
<< " template<typename T>\n"
<< " class Strings {\n"
<< " public:\n";
std::vector<std::string> sections;
std::vector<std::string> keys;
cfg.getAllSections(sections);
for (const auto& section : sections) {
keys.clear();
cfg.getAllKeys(section.c_str(), keys);
std::string textId = section;
textId.push_back('.');
for (auto key : keys) {
textId.append(key);
std::cout << " static const std::string& " << to_cpp(textId) << "() { return T::instance()->translate(\"" << textId << "\"); }\n";
textId.erase(section.size()+1);
}
}
std::cout
<< " };\n"
<< "\n"
<< "} // namespace gen\n"
<< "} // namespace app\n"
<< "\n"
<< "#endif\n";
}
void gen_command_ids(const std::string& inputFn)
{
cfg::CfgFile cfg;
cfg.load(inputFn);
std::cout
<< "// Don't modify, generated file from " << inputFn << "\n"
<< "\n";
std::cout
<< "#ifndef GENERATED_COMMAND_IDS_H_INCLUDED\n"
<< "#define GENERATED_COMMAND_IDS_H_INCLUDED\n"
<< "#pragma once\n"
<< "\n"
<< "namespace app {\n"
<< "namespace gen {\n"
<< "\n"
<< " class CommandId {\n"
<< " public:\n";
std::vector<std::string> keys;
cfg.getAllKeys("commands", keys);
for (auto key : keys) {
if (key.find('_') != std::string::npos)
continue;
std::cout << " static const char* "
<< key << "() { return \""
<< key << "\"; }\n";
}
std::cout
<< " };\n"
<< "\n"
<< "} // namespace gen\n"
<< "} // namespace app\n"
<< "\n"
<< "#endif\n";
}