diff --git a/tools/scribe/src/main.cpp b/tools/scribe/src/main.cpp index ec2b1afc28..b7038e392e 100755 --- a/tools/scribe/src/main.cpp +++ b/tools/scribe/src/main.cpp @@ -188,36 +188,36 @@ int main (int argc, char** argv) { std::ostringstream targetStringStream; if (makeCPlusPlus) { + // Because there is a maximum size for literal strings declared in source we need to partition the + // full source string stream into pages that seems to be around that value... + const int MAX_STRING_LITERAL = 10000; + std::string lineToken; + auto pageSize = lineToken.length(); + std::vector> pages(1, std::make_shared()); + while (!destStringStream.eof()) { + std::getline(destStringStream, lineToken); + auto lineSize = lineToken.length() + 1; + + if (pageSize + lineSize > MAX_STRING_LITERAL) { + pages.push_back(std::make_shared()); + // reset pageStringStream + pageSize = 0; + } + + (*pages.back()) << lineToken << std::endl; + pageSize += lineSize; + } + targetStringStream << "// File generated by Scribe " << vars["_SCRIBE_DATE"] << std::endl; targetStringStream << "#ifndef scribe_" << targetName << "_h" << std::endl; targetStringStream << "#define scribe_" << targetName << "_h" << std::endl << std::endl; targetStringStream << "const char " << targetName << "[] = \n"; - // Because there is a maximum size for literal strings declared in source we need to partition the - // full source string stream into pages that seems to be around that value... - 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 pages content + for (auto page : pages) { + targetStringStream << "R\"SCRIBE(\n" << page->str() << "\n)SCRIBE\"\n"; } - - // Write the last page content if reached eof - targetStringStream << "R\"SCRIBE(\n" << pageStringStream.str() << "\n)SCRIBE\"\n"; targetStringStream << ";\n" << std::endl << std::endl; targetStringStream << "#endif" << std::endl;