@@ -43,22 +43,24 @@ struct Unicode_block_data {
43
43
44
44
const char *description_str =
45
45
" /* This header was auto-generated by the UnicodeHPP (Unicode C++ Header Generator)\n "
46
- " * that is located at github. com/StableCoder /unicode-hpp. \n "
46
+ " * that is located at git.stabletec. com/utilities /unicode-hpp\n "
47
47
" *\n "
48
48
" * Check for an updated version anytime, or state concerns/bugs.\n "
49
49
" */\n " ;
50
50
51
- const char *help_str = " This program builds a quick Unicode header for use in C++11 or\n "
52
- " higher programs. It lists all unicode blocks, and their starting\n "
53
- " and ending code points."
54
- " \n Program Arguments:"
55
- " \n --help : Help Blurb"
56
- " \n -blocksize : Also builds a function for listing each block's size."
57
- " \n -f <filename> : The input file to build the unicode block from."
58
- " \n Must be an XML from Unicode org, such as from"
59
- " \n http://www.unicode.org/Public/9.0.0/ucdxml/ for 9.0.0"
60
- " \n -o <out_dir> : This is the directory where the file unicode_blocks.hpp"
61
- " \n will be written to." ;
51
+ const char *help_str =
52
+ " This program builds a quick Unicode header for use in C++11 or\n "
53
+ " higher programs. It lists all unicode blocks, and their starting\n "
54
+ " and ending code points."
55
+ " \n Program Arguments:"
56
+ " \n -h, --help : Help Blurb"
57
+ " \n -b, --blocksize : Also builds a function enumerating each block's size, rather"
58
+ " \n than calculating it."
59
+ " \n -f <filename> : The input file to build the unicode block from."
60
+ " \n Must be an XML from Unicode org, such as from"
61
+ " \n http://www.unicode.org/Public/9.0.0/ucdxml/ for 9.0.0"
62
+ " \n -o <out_dir> : This is the directory where the file unicode_blocks_#.hpp"
63
+ " \n will be written to." ;
62
64
63
65
int main (int argc, const char **argv) {
64
66
std::string input_file = " " ;
@@ -72,7 +74,7 @@ int main(int argc, const char **argv) {
72
74
std::cout << help_str << std::endl;
73
75
return 0 ;
74
76
}
75
- if (strcmp (argv[idx], " -blocksize" ) == 0 ) {
77
+ if (strcmp (argv[idx], " -- blocksize" ) == 0 || strcmp (argv[idx], " -b " ) == 0 ) {
76
78
include_block_size = true ;
77
79
}
78
80
if (strcmp (argv[idx], " -f" ) == 0 ) {
@@ -134,6 +136,10 @@ int main(int argc, const char **argv) {
134
136
135
137
std::cout << " Parsing Unicode Version " << unicode_vers << std::endl;
136
138
139
+ // Format the version number
140
+ std::replace (unicode_vers.begin (), unicode_vers.end (), ' .' , ' _' );
141
+ unicode_vers = unicode_vers.substr (unicode_vers.find_last_of (' ' ) + 1 );
142
+
137
143
// Search for Blocks
138
144
rapidxml::xml_node<> *blockNode = ucdNode->first_node (" blocks" );
139
145
if (blockNode == nullptr ) {
@@ -169,7 +175,8 @@ int main(int argc, const char **argv) {
169
175
output_dir += ' /' ;
170
176
}
171
177
172
- std::ofstream out_file (output_dir + " unicode_blocks.hpp" , std::ofstream::out);
178
+ std::ofstream out_file (output_dir + " unicode_blocks_" + unicode_vers + " .hpp" ,
179
+ std::ofstream::out);
173
180
if (!out_file.is_open ()) {
174
181
std::cout << " Failed to open header for writing: " << output_dir << " unicode_blocks.h" ;
175
182
return 0 ;
@@ -179,11 +186,11 @@ int main(int argc, const char **argv) {
179
186
out_file << description_str;
180
187
181
188
// Next, the definition lines.
182
- out_file << " \n\n #ifndef UNICODE_BLOCKS_CHG_HPP \n "
183
- << " #define UNICODE_BLOCKS_CHG_HPP " << std::endl;
189
+ out_file << " \n\n #ifndef UNICODE_BLOCKS_HPP \n "
190
+ << " #define UNICODE_BLOCKS_HPP " << std::endl;
184
191
185
192
// Headers
186
- out_file << " \n // C++ \n #include <cstdint>" ;
193
+ out_file << " \n #include <cstdint>" ;
187
194
188
195
// namespace
189
196
out_file << " \n\n namespace unicode {" ;
@@ -200,7 +207,7 @@ int main(int argc, const char **argv) {
200
207
std::replace (iter->name .begin (), iter->name .end (), ' -' , ' _' );
201
208
202
209
// Now, write the enum name out.
203
- out_file << " \n " << iter->name << ' ,' ;
210
+ out_file << " \n " << iter->name << ' ,' ;
204
211
}
205
212
out_file << " \n };" ;
206
213
@@ -226,7 +233,7 @@ int main(int argc, const char **argv) {
226
233
out_file << " \n }" ;
227
234
228
235
if (include_block_size) {
229
- // Only add block sizes if requested.
236
+ // Only add block size enumeration if requested.
230
237
out_file << std::dec;
231
238
out_file << " \n\n constexpr uint32_t getBlockSize(Block unicode_block) {" ;
232
239
out_file << " \n switch(unicode_block) {" ;
@@ -236,13 +243,19 @@ int main(int argc, const char **argv) {
236
243
}
237
244
out_file << " \n }" ;
238
245
out_file << " \n }" ;
246
+ } else {
247
+ // just give the basic calculating function instead.
248
+ out_file << " \n\n constexpr uint32_t getBlockSize(Block unicode_block) {" ;
249
+ out_file
250
+ << " \n return getLastCodePoint(unicode_block) - getFirstCodePoint(unicode_block);" ;
251
+ out_file << " \n }" ;
239
252
}
240
253
241
254
// End namespace
242
255
out_file << " \n\n };" ;
243
256
244
257
// The #endif statement
245
- out_file << " \n\n\n #endif // UNICODE_BLOCKS_CHG_HPP " ;
258
+ out_file << " \n\n\n #endif // UNICODE_BLOCKS_HPP " ;
246
259
247
260
// Close the file.
248
261
out_file.close ();
0 commit comments