Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 06f201b

Browse filesBrowse files
committed
Updated unicode version information
The unicode version is now added to the end of the output file. The unicode block size now defaults to a simple calculation function, which can be substituted with the full enumerated set using the switches as before.
1 parent bbec522 commit 06f201b
Copy full SHA for 06f201b

File tree

1 file changed

+33
-20
lines changed
Filter options

1 file changed

+33
-20
lines changed

‎src/unicode_cpp_generator.cpp

Copy file name to clipboardExpand all lines: src/unicode_cpp_generator.cpp
+33-20Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,24 @@ struct Unicode_block_data {
4343

4444
const char *description_str =
4545
"/* 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"
4747
" *\n"
4848
" * Check for an updated version anytime, or state concerns/bugs.\n"
4949
" */\n";
5050

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-
"\nProgram 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+
"\nProgram 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.";
6264

6365
int main(int argc, const char **argv) {
6466
std::string input_file = "";
@@ -72,7 +74,7 @@ int main(int argc, const char **argv) {
7274
std::cout << help_str << std::endl;
7375
return 0;
7476
}
75-
if (strcmp(argv[idx], "-blocksize") == 0) {
77+
if (strcmp(argv[idx], "--blocksize") == 0 || strcmp(argv[idx], "-b") == 0) {
7678
include_block_size = true;
7779
}
7880
if (strcmp(argv[idx], "-f") == 0) {
@@ -134,6 +136,10 @@ int main(int argc, const char **argv) {
134136

135137
std::cout << "Parsing Unicode Version " << unicode_vers << std::endl;
136138

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+
137143
// Search for Blocks
138144
rapidxml::xml_node<> *blockNode = ucdNode->first_node("blocks");
139145
if (blockNode == nullptr) {
@@ -169,7 +175,8 @@ int main(int argc, const char **argv) {
169175
output_dir += '/';
170176
}
171177

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);
173180
if (!out_file.is_open()) {
174181
std::cout << "Failed to open header for writing: " << output_dir << "unicode_blocks.h";
175182
return 0;
@@ -179,11 +186,11 @@ int main(int argc, const char **argv) {
179186
out_file << description_str;
180187

181188
// 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;
184191

185192
// Headers
186-
out_file << "\n// C++\n#include <cstdint>";
193+
out_file << "\n#include <cstdint>";
187194

188195
// namespace
189196
out_file << "\n\nnamespace unicode {";
@@ -200,7 +207,7 @@ int main(int argc, const char **argv) {
200207
std::replace(iter->name.begin(), iter->name.end(), '-', '_');
201208

202209
// Now, write the enum name out.
203-
out_file << "\n " << iter->name << ',';
210+
out_file << "\n " << iter->name << ',';
204211
}
205212
out_file << "\n};";
206213

@@ -226,7 +233,7 @@ int main(int argc, const char **argv) {
226233
out_file << "\n}";
227234

228235
if (include_block_size) {
229-
// Only add block sizes if requested.
236+
// Only add block size enumeration if requested.
230237
out_file << std::dec;
231238
out_file << "\n\nconstexpr uint32_t getBlockSize(Block unicode_block) {";
232239
out_file << "\n switch(unicode_block) {";
@@ -236,13 +243,19 @@ int main(int argc, const char **argv) {
236243
}
237244
out_file << "\n }";
238245
out_file << "\n}";
246+
} else {
247+
// just give the basic calculating function instead.
248+
out_file << "\n\nconstexpr uint32_t getBlockSize(Block unicode_block) {";
249+
out_file
250+
<< "\n return getLastCodePoint(unicode_block) - getFirstCodePoint(unicode_block);";
251+
out_file << "\n}";
239252
}
240253

241254
// End namespace
242255
out_file << "\n\n};";
243256

244257
// The #endif statement
245-
out_file << "\n\n\n#endif // UNICODE_BLOCKS_CHG_HPP";
258+
out_file << "\n\n\n#endif // UNICODE_BLOCKS_HPP";
246259

247260
// Close the file.
248261
out_file.close();

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.