Skip to content

Commit

Permalink
Fixed MSVC compiler complaint
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanming-hu committed Nov 8, 2018
1 parent 1cec450 commit 5a2f1d7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/io/amal_base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,25 @@ auto amal_base64 = [](const std::vector<std::string> &param) {
if(param.size() >= 2) {
auto line_width = 78;
auto fo = fopen(param[2].c_str(), "w");
fmt::print(fo, "#include <taichi/common/util.h>\n\nTC_NAMESPACE_BEGIN\n\nconst std::string {} = \n", param[1]);
for (int i = 0; i < encoded.size(); i+= line_width) {
fmt::print(fo, "\"{}\"\n", encoded.substr(i, line_width));
auto maximum_literal_length = 65500 / line_width * line_width; // MSVC cannot deal with literal with length > 65535
fmt::print(fo, "#include <taichi/common/util.h>\n\nTC_NAMESPACE_BEGIN\n\n\n");
int num_literals = 0;
for (int l = 0; l < encoded.size(); l += maximum_literal_length) {
fmt::print(fo, "const std::string {}_{:04d} =\n", param[1], num_literals);
num_literals += 1;
for (int i = l; i < std::min((int)encoded.size(), l + maximum_literal_length); i += line_width) {
fmt::print(fo, "\"{}\"\n", encoded.substr(i, line_width));
}
fmt::print(fo, ";\n");
}

fmt::print(fo, "const std::string {} = ", param[1]);
for (int i = 0; i < num_literals; i++) {
fmt::print(fo, "{}_{:04d}", param[1], i);
if (i < num_literals - 1)
fmt::print(fo, " + ", param[1], i);
}

fmt::print(fo, ";\n\nTC_NAMESPACE_END");
std::fclose(fo);
}
Expand Down

0 comments on commit 5a2f1d7

Please sign in to comment.