MCPcopy Create free account
hub / github.com/chen3feng/toft / VFormatPrint

Function VFormatPrint

base/string/format/vprint.cpp:58–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

56}
57
58int VFormatPrint(FormatPrintTarget* target, const char* format,
59 const FormatPrintArg** args, int nargs)
60{
61 int total_printed = 0;
62 int ai = 0;
63 const char* f = format;
64 while (*f != '\0') {
65 const char* p = strchrnul(f, '%');
66 target->WriteString(f, p - f);
67 total_printed += p - f;
68 f = p;
69 if (*f) { // If not nul, must be '%'
70 if (f[1] == '\0')
71 return -1;
72 if (f[1] == '%') {
73 target->WriteChar('%');
74 ++total_printed;
75 f += 2;
76 } else {
77 ++f;
78 PrintSpecification spec;
79 int n = spec.Parse(f);
80 if (n > 0) {
81 if (FillSpeciationFromArg(&spec.width, args, nargs, &ai) < 0)
82 return -1;
83 if (FillSpeciationFromArg(&spec.precision, args, nargs, &ai) < 0)
84 return -1;
85 if (ai >= nargs) {
86 LOG(DFATAL) << "Arg out of bound";
87 return -1;
88 }
89 int printed = args[ai]->Write(target, spec);
90 if (printed < 0)
91 return -1;
92 total_printed += printed;
93 f += n;
94 ++ai;
95 } else {
96 return -1;
97 }
98 }
99 }
100 }
101
102 if (ai != nargs) {
103 LOG(WARNING) << "Extra param provided, expect " << ai << ", "
104 << nargs << " provided";
105 }
106 return total_printed;
107}
108
109int StringVPrintAppend(std::string* target, const char* format,
110 const FormatPrintArg** args, int nargs)

Callers 1

StringVPrintAppendFunction · 0.85

Calls 6

strchrnulFunction · 0.85
FillSpeciationFromArgFunction · 0.85
WriteStringMethod · 0.80
WriteCharMethod · 0.45
ParseMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected