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

Function dump_string_yaml_multiline

common/common.cpp:1196–1225  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1194}
1195
1196void dump_string_yaml_multiline(FILE * stream, const char * prop_name, const char * data) {
1197 std::string data_str(data == NULL ? "" : data);
1198
1199 if (data_str.empty()) {
1200 fprintf(stream, "%s:\n", prop_name);
1201 return;
1202 }
1203
1204 size_t pos_start = 0;
1205 size_t pos_found = 0;
1206
1207 if (!data_str.empty() && (std::isspace(data_str[0]) || std::isspace(data_str.back()))) {
1208 data_str = std::regex_replace(data_str, std::regex("\n"), "\\n");
1209 data_str = std::regex_replace(data_str, std::regex("\""), "\\\"");
1210 data_str = "\"" + data_str + "\"";
1211 fprintf(stream, "%s: %s\n", prop_name, data_str.c_str());
1212 return;
1213 }
1214
1215 if (data_str.find('\n') == std::string::npos) {
1216 fprintf(stream, "%s: %s\n", prop_name, data_str.c_str());
1217 return;
1218 }
1219
1220 fprintf(stream, "%s: |\n", prop_name);
1221 while ((pos_found = data_str.find('\n', pos_start)) != std::string::npos) {
1222 fprintf(stream, " %s\n", data_str.substr(pos_start, pos_found-pos_start).c_str());
1223 pos_start = pos_found + 1;
1224 }
1225}
1226
1227std::string get_sortable_timestamp() {
1228 using clock = std::chrono::system_clock;

Callers 3

write_logfileFunction · 0.85
write_logfileFunction · 0.85

Calls 5

fprintfFunction · 0.85
findMethod · 0.80
substrMethod · 0.80
emptyMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected