25 std::vector<std::string>
26 explode(
const std::string& str)
28 std::vector<std::string> parts;
29 std::size_t start_index = 0;
32 const auto index = str.find_first_of(split_chars, start_index);
34 if (index == std::string::npos)
36 parts.emplace_back(str.substr(start_index));
40 ASSERTX(index > start_index, index, start_index);
41 auto word = str.substr(start_index, index - start_index);
42 char next_char = str.substr(index, 1)[0];
43 if (is_whitespace(next_char))
45 parts.emplace_back(word);
46 parts.emplace_back(std::string(1, next_char));
50 parts.emplace_back(word + next_char);
53 start_index = index + 1;
60 std::vector<std::string>
63 const std::string& str,
64 std::function<
bool (
const std::string&)> fit
67 auto words = explode(str);
69 auto lines = std::vector<std::string>{};
70 std::optional<std::string> current_line;
72 auto add_current_line = [&]()
76 const auto t =
trim(*current_line,
" \t");
77 if(
t.empty() ==
false)
79 lines.emplace_back(
trim(
t));
85 for(
const auto& word:
words)
87 if (fit(current_line.value_or(
"") + word) ==
false)
91 current_line = current_line.value_or(
"") + word;
97 lines.emplace_back(
"");
constexpr std::string_view space_characters
Space characters.
std::string trim(const std::string &string_to_trim, std::string_view trim_characters)
Remove characters from both the start and the end.
std::vector< std::string > get_word_wrapped(const std::string &str, std::function< bool(const std::string &)> fit)
String utility functions.