mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 01:09:27 +02:00
make scribe spit out bigger chunks of litteral strings
This commit is contained in:
parent
80c80091e4
commit
a436c54817
1 changed files with 26 additions and 11 deletions
|
@ -168,7 +168,7 @@ int main (int argc, char** argv) {
|
||||||
auto scribe = std::make_shared<TextTemplate>(srcFilename, config);
|
auto scribe = std::make_shared<TextTemplate>(srcFilename, config);
|
||||||
|
|
||||||
// ready to parse and generate
|
// ready to parse and generate
|
||||||
std::ostringstream destStringStream;
|
std::stringstream destStringStream;
|
||||||
int numErrors = scribe->scribe(destStringStream, srcStream, vars);
|
int numErrors = scribe->scribe(destStringStream, srcStream, vars);
|
||||||
if (numErrors) {
|
if (numErrors) {
|
||||||
cerr << "Scribe " << srcFilename << "> failed: " << numErrors << " errors." << endl;
|
cerr << "Scribe " << srcFilename << "> failed: " << numErrors << " errors." << endl;
|
||||||
|
@ -191,19 +191,34 @@ int main (int argc, char** argv) {
|
||||||
targetStringStream << "#ifndef scribe_" << targetName << "_h" << std::endl;
|
targetStringStream << "#ifndef scribe_" << targetName << "_h" << std::endl;
|
||||||
targetStringStream << "#define scribe_" << targetName << "_h" << std::endl << std::endl;
|
targetStringStream << "#define scribe_" << targetName << "_h" << std::endl << std::endl;
|
||||||
|
|
||||||
std::istringstream destStringStreamAgain(destStringStream.str());
|
|
||||||
targetStringStream << "const char " << targetName << "[] = \n";
|
targetStringStream << "const char " << targetName << "[] = \n";
|
||||||
while (!destStringStreamAgain.eof()) {
|
|
||||||
std::string lineToken;
|
// Because there is a maximum size for literal strings declared in source we need to partition the
|
||||||
std::getline(destStringStreamAgain, lineToken);
|
// full source string stream into pages that seems to be around that value...
|
||||||
targetStringStream << "R\"XXX(" << lineToken << ")XXX\"\"\\n\"\n";
|
const int MAX_STRING_LITERAL = 10000;
|
||||||
|
std::string lineToken;
|
||||||
|
auto pageSize = lineToken.length();
|
||||||
|
std::stringstream pageStringStream;
|
||||||
|
|
||||||
|
while (!destStringStream.eof()) {
|
||||||
|
std::getline(destStringStream, lineToken);
|
||||||
|
auto lineSize = lineToken.length() + 1;
|
||||||
|
|
||||||
|
if (pageSize + lineSize > MAX_STRING_LITERAL) {
|
||||||
|
targetStringStream << "R\"SCRIBE(\n" << pageStringStream.str() << "\n)SCRIBE\"\n";
|
||||||
|
// reset pageStringStream
|
||||||
|
pageStringStream = std::stringstream();
|
||||||
|
pageSize = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pageStringStream << lineToken << std::endl;
|
||||||
|
pageSize += lineSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Write the last page content if reached eof
|
||||||
|
targetStringStream << "R\"SCRIBE(\n" << pageStringStream.str() << "\n)SCRIBE\"\n";
|
||||||
targetStringStream << ";\n" << std::endl << std::endl;
|
targetStringStream << ";\n" << std::endl << std::endl;
|
||||||
/*
|
|
||||||
targetStringStream << "const char " << targetName << "[] = R\"SCRIBE(";
|
|
||||||
targetStringStream << destStringStream.str();
|
|
||||||
targetStringStream << "\n)SCRIBE\";\n\n";
|
|
||||||
*/
|
|
||||||
targetStringStream << "#endif" << std::endl;
|
targetStringStream << "#endif" << std::endl;
|
||||||
} else {
|
} else {
|
||||||
targetStringStream << destStringStream.str();
|
targetStringStream << destStringStream.str();
|
||||||
|
|
Loading…
Reference in a new issue