diff options
author | 2022-10-10 20:36:14 +0200 | |
---|---|---|
committer | 2022-10-10 11:36:14 -0700 | |
commit | e9cc65ffeb0684a97618b67c2164d95ea497226c (patch) | |
tree | ed65f7ac86cc4e8945021dc36a79c8bc246c150d /Source/Utils/Strings/StringUtils.cpp | |
parent | 56e04c1b911f9399662c4ff9ecf6630d686cc220 (diff) | |
download | WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.tar.gz WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.tar.zst WarpX-e9cc65ffeb0684a97618b67c2164d95ea497226c.zip |
Partial refactoring of the utils directory (#3404)
* initial work to clean WarpX Utils
* remove AMRCore from Ionization tables
* progress
* refactoring of a part of the utils directory
* fix bug
* fixed bug
* fixed bug
* remove debug line accidentally slipped into the code
* remove debug line accidentally slipped into the code
* remove debug line accidentally slipped into the code
* cleaning
* fixed bug
Diffstat (limited to 'Source/Utils/Strings/StringUtils.cpp')
-rw-r--r-- | Source/Utils/Strings/StringUtils.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/Source/Utils/Strings/StringUtils.cpp b/Source/Utils/Strings/StringUtils.cpp new file mode 100644 index 000000000..f095794c9 --- /dev/null +++ b/Source/Utils/Strings/StringUtils.cpp @@ -0,0 +1,51 @@ +/* Copyright 2022 Andrew Myers, Luca Fedeli, Maxence Thevenet + * Revathi Jambunathan + * + * This file is part of WarpX. + * + * License: BSD-3-Clause-LBNL + */ + +#include "StringUtils.H" + +#include <sstream> + +std::vector<std::string> automatic_text_wrap( + const std::string& text, const int max_line_length){ + + auto ss_text = std::stringstream{text}; + auto wrapped_text_lines = std::vector<std::string>{}; + + std::string line; + while(std::getline(ss_text, line,'\n')){ + + auto ss_line = std::stringstream{line}; + int counter = 0; + std::stringstream ss_line_out; + std::string word; + + while (ss_line >> word){ + const auto wlen = static_cast<int>(word.length()); + + if(counter == 0){ + ss_line_out << word; + counter += wlen; + } + else{ + if (counter + wlen < max_line_length){ + ss_line_out << " " << word; + counter += (wlen+1); + } + else{ + wrapped_text_lines.push_back(ss_line_out.str()); + ss_line_out = std::stringstream{word}; + counter = wlen; + } + } + } + + wrapped_text_lines.push_back(ss_line_out.str()); + } + + return wrapped_text_lines; +} |