MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / to_string

Method to_string

smallthinker/common/arg.cpp:137–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

135}
136
137std::string common_arg::to_string() {
138 // params for printing to console
139 const static int n_leading_spaces = 40;
140 const static int n_char_per_line_help = 70; // TODO: detect this based on current console
141 std::string leading_spaces(n_leading_spaces, ' ');
142
143 std::ostringstream ss;
144 for (const auto arg : args) {
145 if (arg == args.front()) {
146 if (args.size() == 1) {
147 ss << arg;
148 } else {
149 // first arg is usually abbreviation, we need padding to make it more beautiful
150 auto tmp = std::string(arg) + ", ";
151 auto spaces = std::string(std::max(0, 7 - (int)tmp.size()), ' ');
152 ss << tmp << spaces;
153 }
154 } else {
155 ss << arg << (arg != args.back() ? ", " : "");
156 }
157 }
158 if (value_hint) ss << " " << value_hint;
159 if (value_hint_2) ss << " " << value_hint_2;
160 if (ss.tellp() > n_leading_spaces - 3) {
161 // current line is too long, add new line
162 ss << "\n" << leading_spaces;
163 } else {
164 // padding between arg and help, same line
165 ss << std::string(leading_spaces.size() - ss.tellp(), ' ');
166 }
167 const auto help_lines = break_str_into_lines(help, n_char_per_line_help);
168 for (const auto & line : help_lines) {
169 ss << (&line == &help_lines.front() ? "" : leading_spaces) << line << "\n";
170 }
171 return ss.str();
172}
173
174//
175// downloader

Callers 3

common_params_parse_exFunction · 0.45
json.hppFile · 0.45

Calls 5

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

Tested by

no test coverage detected