From 44cd16fcc85697b5094250a89decaab5c692b392 Mon Sep 17 00:00:00 2001 From: "mmentovai@google.com" Date: Thu, 14 Aug 2008 01:25:32 +0000 Subject: DCHECK vswprintf format string cross-platform portability. Use %ls, not %s, for wchar_t* fields. git-svn-id: svn://svn.chromium.org/chrome/trunk/src@849 0039d316-1c4b-4281-b951-d872f2087c98 --- base/string_util.cc | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'base/string_util.cc') diff --git a/base/string_util.cc b/base/string_util.cc index 7208cd0..0a930d9 100644 --- a/base/string_util.cc +++ b/base/string_util.cc @@ -259,6 +259,48 @@ class WStringToDoubleTraits { } // namespace +namespace base { + +bool IsWprintfFormatPortable(const wchar_t* format) { + for (const wchar_t* position = format; *position != '\0'; ++position) { + + if (*position == '%') { + bool in_specification = true; + bool modifier_l = false; + while (in_specification) { + // Eat up characters until reaching a known specifier. + if (*++position == '\0') { + // The format string ended in the middle of a specification. Call + // it portable because no unportable specifications were found. The + // string is equally broken on all platforms. + return true; + } + + if (*position == 'l') { + // 'l' is the only thing that can save the 's' and 'c' specifiers. + modifier_l = true; + } else if (((*position == 's' || *position == 'c') && !modifier_l) || + *position == 'S' || *position == 'C' || *position == 'F' || + *position == 'D' || *position == 'O' || *position == 'U') { + // Not portable. + return false; + } + + if (wcschr(L"diouxXeEfgGaAcspn%", *position)) { + // Portable, keep scanning the rest of the format string. + in_specification = false; + } + } + } + + } + + return true; +} + +} // namespace base + + const std::string& EmptyString() { return *Singleton::get(); } -- cgit v1.1