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

Function StringVScan

base/string/format/vscan.cpp:18–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16namespace toft {
17
18int StringVScan(const char* string, const char* format,
19 const FormatScanArg** args, int nargs)
20{
21 int success_count = 0;
22 int ai = 0;
23 const char* f = format;
24 const char* s = string;
25 while (*f != '\0') {
26 if (*f == '%') {
27 if (f[1] == '\0')
28 return -1;
29 if (f[1] == '%') {
30 if (*s == '%') {
31 f += 2;
32 ++s;
33 } else {
34 // Not match '%'
35 break;
36 }
37 } else {
38 ++f;
39 ScanSpecification spec;
40 int fw = spec.Parse(f);
41 if (fw == 0)
42 break;
43 bool success;
44 int sw = 0;
45 if (spec.skip) {
46 sw = FormatScanArg::ParseSkipped(s, spec);
47 success = sw > 0;
48 } else {
49 if (spec.specifier == 'n') {
50 success = args[ai]->WriteInt(s - string, spec);
51 if (success)
52 ++success_count;
53 else
54 LOG(ERROR) << "Invalid argument " << ai << " for %n";
55 } else {
56 sw = args[ai]->Parse(s, spec);
57 success = sw > 0;
58 if (success) {
59 ++success_count;
60 ++ai;
61 }
62 }
63 }
64 if (success) {
65 f += fw;
66 s += sw;
67 } else {
68 break;
69 }
70 }
71 } else {
72 if (*s == *f) {
73 ++f;
74 ++s;
75 } else {

Callers 1

StringScanFunction · 0.85

Calls 2

WriteIntMethod · 0.80
ParseMethod · 0.45

Tested by

no test coverage detected