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

Method to_string

subprojects/llama.cpp/common/arg.cpp:175–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

173}
174
175std::string common_arg::to_string() const {
176 // params for printing to console
177 const static int n_leading_spaces = 40;
178 const static int n_char_per_line_help = 70; // TODO: detect this based on current console
179 std::string leading_spaces(n_leading_spaces, ' ');
180
181 std::ostringstream ss;
182 auto all_args = get_args(); // also contains args_neg
183 for (const auto & arg : all_args) {
184 if (arg == all_args.front()) {
185 if (all_args.size() == 1) {
186 ss << arg;
187 } else {
188 // first arg is usually abbreviation, we need padding to make it more beautiful
189 auto tmp = std::string(arg) + ", ";
190 auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' ');
191 ss << tmp << spaces;
192 }
193 } else {
194 ss << arg << (arg != all_args.back() ? ", " : "");
195 }
196 }
197 if (value_hint) ss << " " << value_hint;
198 if (value_hint_2) ss << " " << value_hint_2;
199 if (ss.tellp() > n_leading_spaces - 3) {
200 // current line is too long, add new line
201 ss << "\n" << leading_spaces;
202 } else {
203 // padding between arg and help, same line
204 ss << std::string(leading_spaces.size() - ss.tellp(), ' ');
205 }
206 const auto help_lines = break_str_into_lines(help, n_char_per_line_help);
207 for (const auto & line : help_lines) {
208 ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n";
209 }
210 return ss.str();
211}
212
213std::vector<std::string> common_arg::get_args() const {
214 std::vector<std::string> result;

Callers 4

load_from_cacheMethod · 0.45
common_params_parse_exFunction · 0.45

Calls 5

stringClass · 0.85
maxFunction · 0.85
break_str_into_linesFunction · 0.85
sizeMethod · 0.65
strMethod · 0.45

Tested by

no test coverage detected