Skip to content

Commit

Permalink
base/strings: Use BUILDFLAG for OS checking
Browse files Browse the repository at this point in the history
Use BUILDFLAG(IS_XXX) instead of defined(OS_XXX).

Generated by `os_buildflag_migration.py` (https://crrev.com/c/3311983).

R=thakis@chromium.org

Bug: 1234043
Test: No functionality change
Change-Id: Ib23eadf371cee390b87738eaeb065293a5b8d613
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3390864
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#959590}
  • Loading branch information
xhwang-chromium authored and Chromium LUCI CQ committed Jan 15, 2022
1 parent 633d2d7 commit 6700dcf
Show file tree
Hide file tree
Showing 14 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion base/strings/safe_sprintf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Buffer {
// MSVS2013's standard library doesn't mark max() as constexpr yet. cl.exe
// supports static_cast but doesn't really implement constexpr yet so it doesn't
// complain, but clang does.
#if __cplusplus >= 201103 && !(defined(__clang__) && defined(OS_WIN))
#if __cplusplus >= 201103 && !(defined(__clang__) && BUILDFLAG(IS_WIN))
static_assert(kSSizeMaxConst ==
static_cast<size_t>(std::numeric_limits<ssize_t>::max()),
"kSSizeMaxConst should be the max value of an ssize_t");
Expand Down
2 changes: 1 addition & 1 deletion base/strings/safe_sprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include "build/build_config.h"

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// For ssize_t
#include <unistd.h>
#endif
Expand Down
2 changes: 1 addition & 1 deletion base/strings/safe_sprintf_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// Death tests on Android are currently very flaky. No need to add more flaky
// tests, as they just make it hard to spot real problems.
// TODO(markus): See if the restrictions on Android can eventually be lifted.
#if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
#if defined(GTEST_HAS_DEATH_TEST) && !BUILDFLAG(IS_ANDROID)
#define ALLOW_DEATH_TEST
#endif

Expand Down
4 changes: 2 additions & 2 deletions base/strings/strcat.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "base/strings/string_piece.h"
#include "build/build_config.h"

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
// Guard against conflict with Win32 API StrCat macro:
// check StrCat wasn't and will not be redefined.
#define StrCat StrCat
Expand Down Expand Up @@ -102,7 +102,7 @@ inline void StrAppend(std::u16string* dest,

} // namespace base

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
#include "base/strings/strcat_win.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion base/strings/string_number_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ BASE_EXPORT bool HexStringToSpan(StringPiece input, base::span<uint8_t> output);

} // namespace base

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
#include "base/strings/string_number_conversions_win.h"
#endif

Expand Down
2 changes: 1 addition & 1 deletion base/strings/string_split.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ SplitStringPieceUsingSubstr(StringPiece16 input,

} // namespace base

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
#include "base/strings/string_split_win.h"
#endif

Expand Down
4 changes: 2 additions & 2 deletions base/strings/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -505,9 +505,9 @@ BASE_EXPORT std::u16string ReplaceStringPlaceholders(

} // namespace base

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
#include "base/strings/string_util_win.h"
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include "base/strings/string_util_posix.h"
#else
#error Define string operations appropriately for your platform
Expand Down
12 changes: 6 additions & 6 deletions base/strings/stringprintf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ inline int vsnprintfT(char* buffer,
return base::vsnprintf(buffer, buf_size, format, argptr);
}

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
inline int vsnprintfT(wchar_t* buffer,
size_t buf_size,
const wchar_t* format,
Expand Down Expand Up @@ -77,7 +77,7 @@ static void StringAppendVT(std::basic_string<CharT>* dst,
int mem_length = base::size(stack_buf);
while (true) {
if (result < 0) {
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
// On Windows, vsnprintfT always returns the number of characters in a
// fully-formatted string, so if we reach this point, something else is
// wrong and no amount of buffer-doubling is going to fix it.
Expand Down Expand Up @@ -128,7 +128,7 @@ std::string StringPrintf(const char* format, ...) {
return result;
}

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
std::wstring StringPrintf(const wchar_t* format, ...) {
va_list ap;
va_start(ap, format);
Expand Down Expand Up @@ -163,7 +163,7 @@ const std::string& SStringPrintf(std::string* dst, const char* format, ...) {
return *dst;
}

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
const std::wstring& SStringPrintf(std::wstring* dst,
const wchar_t* format, ...) {
va_list ap;
Expand Down Expand Up @@ -193,7 +193,7 @@ void StringAppendF(std::string* dst, const char* format, ...) {
va_end(ap);
}

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

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
void StringAppendV(std::wstring* dst, const wchar_t* format, va_list ap) {
StringAppendVT(dst, format, ap);
}
Expand Down
8 changes: 4 additions & 4 deletions base/strings/stringprintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace base {
// Return a C++ string given printf-like input.
[[nodiscard]] BASE_EXPORT std::string StringPrintf(const char* format, ...)
PRINTF_FORMAT(1, 2);
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
// Note: Unfortunately compile time checking of the format string for UTF-16
// strings is not supported by any compiler, thus these functions should be used
// carefully and sparingly. Also applies to SStringPrintf and StringAppendV
Expand All @@ -38,7 +38,7 @@ namespace base {
BASE_EXPORT const std::string& SStringPrintf(std::string* dst,
const char* format,
...) PRINTF_FORMAT(2, 3);
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
BASE_EXPORT const std::wstring& SStringPrintf(std::wstring* dst,
const wchar_t* format,
...) WPRINTF_FORMAT(2, 3);
Expand All @@ -50,7 +50,7 @@ BASE_EXPORT const std::u16string& SStringPrintf(std::u16string* dst,
// Append result to a supplied string.
BASE_EXPORT void StringAppendF(std::string* dst, const char* format, ...)
PRINTF_FORMAT(2, 3);
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
BASE_EXPORT void StringAppendF(std::wstring* dst, const wchar_t* format, ...)
WPRINTF_FORMAT(2, 3);
BASE_EXPORT void StringAppendF(std::u16string* dst, const char16_t* format, ...)
Expand All @@ -61,7 +61,7 @@ BASE_EXPORT void StringAppendF(std::u16string* dst, const char16_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_WIN)
#if BUILDFLAG(IS_WIN)
BASE_EXPORT void StringAppendV(std::wstring* dst,
const wchar_t* format,
va_list ap) WPRINTF_FORMAT(2, 0);
Expand Down
18 changes: 9 additions & 9 deletions base/strings/stringprintf_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ TEST(StringPrintfTest, StringPrintfEmpty) {

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

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

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

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

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
srcw[kSrcLen - i] = 0;
std::wstring outw;
SStringPrintf(&outw, L"%ls", srcw);
Expand Down Expand Up @@ -139,9 +139,9 @@ TEST(StringPrintfTest, Grow) {

const int kRefSize = 320000;
char* ref = new char[kRefSize];
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
sprintf_s(ref, kRefSize, fmt, src, src, src, src, src, src, src);
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
#elif BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
snprintf(ref, kRefSize, fmt, src, src, src, src, src, src, src);
#endif

Expand All @@ -154,7 +154,7 @@ TEST(StringPrintfTest, StringAppendV) {
StringAppendVTestHelper(&out, "%d foo %s", 1, "bar");
EXPECT_EQ("1 foo bar", out);

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
std::wstring outw;
StringAppendVTestHelper(&outw, L"%d foo %ls", 1, L"bar");
EXPECT_EQ(L"1 foo bar", outw);
Expand Down Expand Up @@ -184,7 +184,7 @@ TEST(StringPrintfTest, GrowBoundary) {
EXPECT_STREQ(src, out.c_str());
}

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
TEST(StringPrintfTest, Invalid) {
wchar_t invalid[2];
invalid[0] = 0xffff;
Expand Down
12 changes: 6 additions & 6 deletions base/strings/sys_string_conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#include "base/strings/string_piece.h"
#include "build/build_config.h"

#if defined(OS_APPLE)
#if BUILDFLAG(IS_APPLE)
#include <CoreFoundation/CoreFoundation.h>

#include "base/mac/scoped_cftyperef.h"

#ifdef __OBJC__
@class NSString;
#endif
#endif // OS_APPLE
#endif // BUILDFLAG(IS_APPLE)

namespace base {

Expand All @@ -43,7 +43,7 @@ namespace base {

// Windows-specific ------------------------------------------------------------

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)

// Converts between 8-bit and wide strings, using the given code page. The
// code page identifier is one accepted by the Windows function
Expand All @@ -54,11 +54,11 @@ namespace base {
const std::wstring& wide,
uint32_t code_page);

#endif // defined(OS_WIN)
#endif // BUILDFLAG(IS_WIN)

// Mac-specific ----------------------------------------------------------------

#if defined(OS_APPLE)
#if BUILDFLAG(IS_APPLE)

// Converts between strings and CFStringRefs/NSStrings.

Expand Down Expand Up @@ -86,7 +86,7 @@ namespace base {

#endif // __OBJC__

#endif // defined(OS_APPLE)
#endif // BUILDFLAG(IS_APPLE)

} // namespace base

Expand Down
4 changes: 2 additions & 2 deletions base/strings/sys_string_conversions_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ std::wstring SysUTF8ToWide(StringPiece utf8) {
return out;
}

#if defined(SYSTEM_NATIVE_UTF8) || defined(OS_ANDROID)
#if defined(SYSTEM_NATIVE_UTF8) || BUILDFLAG(IS_ANDROID)
// TODO(port): Consider reverting the OS_ANDROID when we have wcrtomb()
// support and a better understanding of what calls these routines.

Expand Down Expand Up @@ -154,6 +154,6 @@ std::wstring SysNativeMBToWide(StringPiece native_mb) {
return out;
}

#endif // defined(SYSTEM_NATIVE_UTF8) || defined(OS_ANDROID)
#endif // defined(SYSTEM_NATIVE_UTF8) || BUILDFLAG(IS_ANDROID)

} // namespace base
4 changes: 2 additions & 2 deletions base/strings/sys_string_conversions_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ TEST(SysStrings, SysUTF8ToWide) {
}

// Tests depend on setting a specific Linux locale.
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
TEST(SysStrings, SysWideToNativeMB) {
#if !defined(SYSTEM_NATIVE_UTF8)
ScopedLocale locale("en_US.UTF-8");
Expand Down Expand Up @@ -190,6 +190,6 @@ TEST(SysStrings, SysNativeMBAndWide) {
EXPECT_EQ(wide, trip);
}
}
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

} // namespace base
4 changes: 2 additions & 2 deletions base/strings/utf_string_conversion_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void PrepareForUTF8Output(const CHAR* src,
}

// Instantiate versions we know callers will need.
#if !defined(OS_WIN)
#if !BUILDFLAG(IS_WIN)
// wchar_t and char16_t are the same thing on Windows.
template void PrepareForUTF8Output(const wchar_t*, size_t, std::string*);
#endif
Expand All @@ -146,7 +146,7 @@ void PrepareForUTF16Or32Output(const char* src,
}

// Instantiate versions we know callers will need.
#if !defined(OS_WIN)
#if !BUILDFLAG(IS_WIN)
// std::wstring and std::u16string are the same thing on Windows.
template void PrepareForUTF16Or32Output(const char*, size_t, std::wstring*);
#endif
Expand Down

0 comments on commit 6700dcf

Please sign in to comment.