MCPcopy Create free account
hub / github.com/apache/brpc / IsWprintfFormatPortable

Function IsWprintfFormatPortable

src/butil/strings/string_util.cc:71–104  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

69namespace butil {
70
71bool IsWprintfFormatPortable(const wchar_t* format) {
72 for (const wchar_t* position = format; *position != '\0'; ++position) {
73 if (*position == '%') {
74 bool in_specification = true;
75 bool modifier_l = false;
76 while (in_specification) {
77 // Eat up characters until reaching a known specifier.
78 if (*++position == '\0') {
79 // The format string ended in the middle of a specification. Call
80 // it portable because no unportable specifications were found. The
81 // string is equally broken on all platforms.
82 return true;
83 }
84
85 if (*position == 'l') {
86 // 'l' is the only thing that can save the 's' and 'c' specifiers.
87 modifier_l = true;
88 } else if (((*position == 's' || *position == 'c') && !modifier_l) ||
89 *position == 'S' || *position == 'C' || *position == 'F' ||
90 *position == 'D' || *position == 'O' || *position == 'U') {
91 // Not portable.
92 return false;
93 }
94
95 if (wcschr(L"diouxXeEfgGaAcspn%", *position)) {
96 // Portable, keep scanning the rest of the format string.
97 in_specification = false;
98 }
99 }
100 }
101 }
102
103 return true;
104}
105
106const std::string& EmptyString() {
107 return EmptyStrings::GetInstance()->s;

Callers 2

TESTFunction · 0.85
vswprintfFunction · 0.85

Calls

no outgoing calls

Tested by 1

TESTFunction · 0.68