@@ -19,11 +19,11 @@ bin2cpp20 - conversion tool
1919#include < string>
2020#include < vector>
2121
22- #define VERSION_INFO " 1.0.1 "
22+ #define VERSION_INFO " 1.1.0 "
2323
2424void convertStreamToVector (std::string_view name, std::istream &in, std::ostream &out);
2525void convertStreamToArray (std::string_view name, const char *data, std::size_t length, std::ostream &out);
26- void convertStreamToString (bool sorted, std::string_view name, std::istream &in, std::ostream &out);
26+ void convertStreamToString (bool unicode, bool sorted, std::string_view name, std::istream &in, std::ostream &out);
2727void stringOutputVector (const std::vector<unsigned char > &v);
2828template <std::size_t N>
2929void stringOutputArray (std::array<unsigned char , N> &a);
@@ -37,12 +37,13 @@ int main(int argc, char **argv) {
3737 }
3838 try {
3939 Argz<std::string> argz{argc, argv};
40- argz.addOptionSingleValue (' i' , " input file/stdin" ).addOptionDoubleValue (' I' , " input" , " input file/stdin" ).addOptionSingleValue (' o' , " output" ).addOptionDoubleValue (' O' , " output" , " output file" ).addOptionSingle (' h' , " help" ).addOptionDouble (' H' , " help" , " help message" ).addOptionSingleValue (' v' , " variable name" ).addOptionDoubleValue (' V' , " variable" , " variable name" ).addOptionSingle (' s' , " string output" ).addOptionDouble (' S' , " string" , " string output" ).addOptionSingle (' z' , " sort" ).addOptionDouble (' Z' , " sort" , " sort string" );
40+ argz.addOptionSingleValue (' i' , " input file/stdin" ).addOptionDoubleValue (' I' , " input" , " input file/stdin" ).addOptionSingleValue (' o' , " output" ).addOptionDoubleValue (' O' , " output" , " output file" ).addOptionSingle (' h' , " help" ).addOptionDouble (' H' , " help" , " help message" ).addOptionSingleValue (' v' , " variable name" ).addOptionDoubleValue (' V' , " variable" , " variable name" ).addOptionSingle (' s' , " string output" ).addOptionDouble (' S' , " string" , " string output" ).addOptionSingle (' z' , " sort" ).addOptionDouble (' Z' , " sort" , " sort string" ). addOptionSingle ( ' u ' , " Unicode " ). addOptionDouble ( ' U ' , " unicode " , " unicode " ) ;
4141 Argument<std::string> arg;
4242 int value{};
4343 std::string input_file, output_file, variable_name;
4444 bool as_string {false };
4545 bool sorted {false };
46+ bool unicode {false };
4647 while ((value = argz.proc (arg)) != -1 ) {
4748 switch (value) {
4849 case ' i' :
@@ -71,6 +72,10 @@ int main(int argc, char **argv) {
7172 case ' Z' :
7273 sorted = true ;
7374 break ;
75+ case ' u' :
76+ case ' U' :
77+ unicode = true ;
78+ break ;
7479 }
7580 }
7681 if (input_file.length () == 0 ) {
@@ -90,7 +95,7 @@ int main(int argc, char **argv) {
9095
9196 if (input_file == " stdin" ) {
9297 if (output_file.length () == 0 )
93- convertStreamToString (sorted, variable_name, std::cin, std::cout);
98+ convertStreamToString (unicode, sorted, variable_name, std::cin, std::cout);
9499 else {
95100 std::fstream file;
96101 const auto pos{output_file.rfind (" .hpp" )};
@@ -104,7 +109,7 @@ int main(int argc, char **argv) {
104109 file << " #ifndef __STR_H_HPP_" << variable_name << " \n " ;
105110 file << " #define __STR_H_HPP_" << variable_name << " \n " ;
106111 file << " #include<string>\n " ;
107- convertStreamToString (sorted, variable_name, std::cin, file);
112+ convertStreamToString (unicode, sorted, variable_name, std::cin, file);
108113 file << " #endif\n\n " ;
109114 file.close ();
110115 }
@@ -128,7 +133,7 @@ int main(int argc, char **argv) {
128133 } else {
129134 variable_name = " str_" + variable_name;
130135 std::istringstream in (buf.get ());
131- convertStreamToString (sorted, variable_name, in, std::cout);
136+ convertStreamToString (unicode, sorted, variable_name, in, std::cout);
132137 }
133138 return EXIT_SUCCESS;
134139 } else {
@@ -151,7 +156,7 @@ int main(int argc, char **argv) {
151156 } else {
152157 file << " #include<string>\n\n " ;
153158 std::istringstream in{buf.get ()};
154- convertStreamToString (sorted, variable_name, in, file);
159+ convertStreamToString (unicode, sorted, variable_name, in, file);
155160 }
156161 file << " \n\n #endif\n " ;
157162 file.close ();
@@ -188,8 +193,11 @@ void convertStreamToArray(std::string_view name, const char *data, std::size_t l
188193 out << hex << " };\n " ;
189194}
190195
191- void convertStreamToString (bool sorted, std::string_view name, std::istream &in, std::ostream &out) {
192- out << " inline const std::string " << name << " [] = {" ;
196+ void convertStreamToString (bool unicode, bool sorted, std::string_view name, std::istream &in, std::ostream &out) {
197+ if (unicode == false )
198+ out << " inline const std::string " << name << " [] = {" ;
199+ else
200+ out << " inline const std::wstring " << name << " [] = {" ;
193201 std::size_t index{};
194202 std::size_t length{};
195203 std::vector<std::string> v;
@@ -208,7 +216,10 @@ void convertStreamToString(bool sorted, std::string_view name, std::istream &in,
208216 for (auto &line : v) {
209217 index += line.length () + 1 ;
210218 if (line.length () > 0 ) {
211- out << " \" " << convertString (line) << " \" " ;
219+ if (unicode == false )
220+ out << " \" " << convertString (line) << " \" " ;
221+ else
222+ out << " L\" " << convertString (line) << " \" " ;
212223 if (index < length)
213224 out << " ," ;
214225 }
0 commit comments