diff options
author | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-14 01:25:32 +0000 |
---|---|---|
committer | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-14 01:25:32 +0000 |
commit | 44cd16fcc85697b5094250a89decaab5c692b392 (patch) | |
tree | 37e4fb0dbee34f2cc673c287b54515a71b1f9629 /base/string_util.cc | |
parent | 5f800edb90578f08b3462e1dc96b78bf0ec56d36 (diff) | |
download | chromium_src-44cd16fcc85697b5094250a89decaab5c692b392.zip chromium_src-44cd16fcc85697b5094250a89decaab5c692b392.tar.gz chromium_src-44cd16fcc85697b5094250a89decaab5c692b392.tar.bz2 |
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
Diffstat (limited to 'base/string_util.cc')
-rw-r--r-- | base/string_util.cc | 42 |
1 files changed, 42 insertions, 0 deletions
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<std::string>::get(); } |