MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / break_str_into_lines

Function break_str_into_lines

subprojects/llama.cpp/common/arg.cpp:148–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

146}
147
148static std::vector<std::string> break_str_into_lines(std::string input, size_t max_char_per_line) {
149 std::vector<std::string> result;
150 std::istringstream iss(input);
151 std::string line;
152 auto add_line = [&](const std::string& l) {
153 if (l.length() <= max_char_per_line) {
154 result.push_back(l);
155 } else {
156 std::istringstream line_stream(l);
157 std::string word, current_line;
158 while (line_stream >> word) {
159 if (current_line.length() + !current_line.empty() + word.length() > max_char_per_line) {
160 if (!current_line.empty()) result.push_back(current_line);
161 current_line = word;
162 } else {
163 current_line += (!current_line.empty() ? " " : "") + word;
164 }
165 }
166 if (!current_line.empty()) result.push_back(current_line);
167 }
168 };
169 while (std::getline(iss, line)) {
170 add_line(line);
171 }
172 return result;
173}
174
175std::string common_arg::to_string() const {
176 // params for printing to console

Callers 1

to_stringMethod · 0.85

Calls 3

lengthMethod · 0.65
emptyMethod · 0.65
push_backMethod · 0.45

Tested by

no test coverage detected