Skip to content

Commit

Permalink
Make wstring StringPrintf() functions Windows only.
Browse files Browse the repository at this point in the history
Review URL: https://codereview.chromium.org/807913004

Cr-Commit-Position: refs/heads/master@{#309084}
  • Loading branch information
leizleiz authored and Commit bot committed Dec 18, 2014
1 parent 9cfc3f8 commit d0f0a4b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
12 changes: 7 additions & 5 deletions base/strings/stringprintf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

#include <errno.h>

#include <vector>

#include "base/scoped_clear_errno.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
Expand All @@ -27,7 +29,7 @@ inline int vsnprintfT(char* buffer,
return base::vsnprintf(buffer, buf_size, format, argptr);
}

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
inline int vsnprintfT(wchar_t* buffer,
size_t buf_size,
const wchar_t* format,
Expand Down Expand Up @@ -117,7 +119,7 @@ std::string StringPrintf(const char* format, ...) {
return result;
}

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
std::wstring StringPrintf(const wchar_t* format, ...) {
va_list ap;
va_start(ap, format);
Expand All @@ -143,7 +145,7 @@ const std::string& SStringPrintf(std::string* dst, const char* format, ...) {
return *dst;
}

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
const std::wstring& SStringPrintf(std::wstring* dst,
const wchar_t* format, ...) {
va_list ap;
Expand All @@ -162,7 +164,7 @@ void StringAppendF(std::string* dst, const char* format, ...) {
va_end(ap);
}

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
void StringAppendF(std::wstring* dst, const wchar_t* format, ...) {
va_list ap;
va_start(ap, format);
Expand All @@ -175,7 +177,7 @@ void StringAppendV(std::string* dst, const char* format, va_list ap) {
StringAppendVT(dst, format, ap);
}

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
StringAppendVT(dst, format, ap);
}
Expand Down
11 changes: 4 additions & 7 deletions base/strings/stringprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ namespace base {
// Return a C++ string given printf-like input.
BASE_EXPORT std::string StringPrintf(const char* format, ...)
PRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
// OS_ANDROID's libc does not support wchar_t, so several overloads are omitted.
#if !defined(OS_ANDROID)
#if defined(OS_WIN)
BASE_EXPORT std::wstring StringPrintf(const wchar_t* format, ...)
WPRINTF_FORMAT(1, 2) WARN_UNUSED_RESULT;
#endif
Expand All @@ -31,7 +30,7 @@ BASE_EXPORT std::string StringPrintV(const char* format, va_list ap)
BASE_EXPORT const std::string& SStringPrintf(std::string* dst,
const char* format, ...)
PRINTF_FORMAT(2, 3);
#if !defined(OS_ANDROID)
#if defined(OS_WIN)
BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
const wchar_t* format, ...)
WPRINTF_FORMAT(2, 3);
Expand All @@ -40,9 +39,7 @@ BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
// Append result to a supplied string.
BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...)
PRINTF_FORMAT(2, 3);
#if !defined(OS_ANDROID)
// TODO(evanm): this is only used in a few places in the code;
// replace with string16 version.
#if defined(OS_WIN)
BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
WPRINTF_FORMAT(2, 3);
#endif
Expand All @@ -51,7 +48,7 @@ BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
// string. All other routines are just convenience wrappers around it.
BASE_EXPORT void StringAppendV(std::string* dst, const char* format, va_list ap)
PRINTF_FORMAT(2, 0);
#if !defined(OS_ANDROID)
#if defined(OS_WIN)
BASE_EXPORT void StringAppendV(std::wstring* dst,
const wchar_t* format, va_list ap)
WPRINTF_FORMAT(2, 0);
Expand Down
10 changes: 5 additions & 5 deletions base/strings/stringprintf_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ TEST(StringPrintfTest, StringPrintfEmpty) {

TEST(StringPrintfTest, StringPrintfMisc) {
EXPECT_EQ("123hello w", StringPrintf("%3d%2s %1c", 123, "hello", 'w'));
#if !defined(OS_ANDROID)
#if defined(OS_WIN)
EXPECT_EQ(L"123hello w", StringPrintf(L"%3d%2ls %1lc", 123, L"hello", 'w'));
#endif
}
Expand All @@ -41,7 +41,7 @@ TEST(StringPrintfTest, StringAppendfEmptyString) {
StringAppendF(&value, "%s", "");
EXPECT_EQ("Hello", value);

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
std::wstring valuew(L"Hello");
StringAppendF(&valuew, L"%ls", L"");
EXPECT_EQ(L"Hello", valuew);
Expand All @@ -53,7 +53,7 @@ TEST(StringPrintfTest, StringAppendfString) {
StringAppendF(&value, " %s", "World");
EXPECT_EQ("Hello World", value);

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
std::wstring valuew(L"Hello");
StringAppendF(&valuew, L" %ls", L"World");
EXPECT_EQ(L"Hello World", valuew);
Expand All @@ -65,7 +65,7 @@ TEST(StringPrintfTest, StringAppendfInt) {
StringAppendF(&value, " %d", 123);
EXPECT_EQ("Hello 123", value);

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
std::wstring valuew(L"Hello");
StringAppendF(&valuew, L" %d", 123);
EXPECT_EQ(L"Hello 123", valuew);
Expand All @@ -90,7 +90,7 @@ TEST(StringPrintfTest, StringPrintfBounds) {
SStringPrintf(&out, "%s", src);
EXPECT_STREQ(src, out.c_str());

#if !defined(OS_ANDROID)
#if defined(OS_WIN)
srcw[kSrcLen - i] = 0;
std::wstring outw;
SStringPrintf(&outw, L"%ls", srcw);
Expand Down

0 comments on commit d0f0a4b

Please sign in to comment.