This repository has been archived by the owner on Sep 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add shared macros for stringizing and converting ANSI string constants
(in particular defined by macros) to wide string constants. Convert existing locally-defined stringizing to use the shared macros. Unit tests for the shared macros. This also fixes a minor bug in ceee_module_util.cc where I accidentally quoted a string constant I only meant to convert to wide (this caused no bug, but was unintended, so the change in semantics in that file in the current change is intentional). BUG=none TEST=automated tests Review URL: http://codereview.chromium.org/5103001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@66579 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
joi@chromium.org
committed
Nov 18, 2010
1 parent
7d9f83e
commit 8e0f745
Showing
7 changed files
with
128 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) 2010 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// This file defines preprocessor macros for stringizing preprocessor | ||
// symbols (or their output) and manipulating preprocessor symbols | ||
// that define strings. | ||
|
||
#ifndef BASE_STRINGIZE_MACROS_H_ | ||
#define BASE_STRINGIZE_MACROS_H_ | ||
#pragma once | ||
|
||
#include "build/build_config.h" | ||
|
||
// This is not very useful as it does not expand defined symbols if | ||
// called directly. Use its counterpart without the _NO_EXPANSION | ||
// suffix, below. | ||
#define STRINGIZE_NO_EXPANSION(x) #x | ||
|
||
// Use this to quote the provided parameter, first expanding it if it | ||
// is a preprocessor symbol. | ||
// | ||
// For example, if: | ||
// #define A FOO | ||
// #define B(x) myobj->FunctionCall(x) | ||
// | ||
// Then: | ||
// STRINGIZE(A) produces "FOO" | ||
// STRINGIZE(B(y)) produces "myobj->FunctionCall(y)" | ||
#define STRINGIZE(x) STRINGIZE_NO_EXPANSION(x) | ||
|
||
// The following are defined only on Windows (for use when interacting | ||
// with Windows APIs) as wide strings are otherwise deprecated. | ||
#if defined(OS_WIN) | ||
|
||
// Second-level utility macros to let us expand symbols. | ||
#define LSTRINGIZE_NO_EXPANSION(x) L ## #x | ||
#define TO_L_STRING_NO_EXPANSION(x) L ## x | ||
|
||
// L version of STRINGIZE(). For examples above, | ||
// LSTRINGIZE(A) produces L"FOO" | ||
// LSTRINGIZE(B(y)) produces L"myobj->FunctionCall(y)" | ||
#define LSTRINGIZE(x) LSTRINGIZE_NO_EXPANSION(x) | ||
|
||
// Adds an L in front of an existing ASCII string constant (after | ||
// expanding symbols). Does not do any quoting. | ||
// | ||
// For example, if: | ||
// #define C "foo" | ||
// | ||
// Then: | ||
// TO_L_STRING(C) produces L"foo" | ||
#define TO_L_STRING(x) TO_L_STRING_NO_EXPANSION(x) | ||
|
||
#endif // defined(OS_WIN) | ||
|
||
#endif // BASE_STRINGIZE_MACROS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2010 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
// | ||
// Unit tests for stringize_macros.h | ||
|
||
#include "base/stringize_macros.h" | ||
|
||
#include "testing/gtest/include/gtest/gtest.h" | ||
|
||
// Macros as per documentation in header file. | ||
#define PREPROCESSOR_UTIL_UNITTEST_A FOO | ||
#define PREPROCESSOR_UTIL_UNITTEST_B(x) myobj->FunctionCall(x) | ||
#define PREPROCESSOR_UTIL_UNITTEST_C "foo" | ||
|
||
TEST(StringizeTest, Ansi) { | ||
EXPECT_STREQ( | ||
"PREPROCESSOR_UTIL_UNITTEST_A", | ||
STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_A)); | ||
EXPECT_STREQ( | ||
"PREPROCESSOR_UTIL_UNITTEST_B(y)", | ||
STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_B(y))); | ||
EXPECT_STREQ( | ||
"PREPROCESSOR_UTIL_UNITTEST_C", | ||
STRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_C)); | ||
|
||
EXPECT_STREQ("FOO", STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_A)); | ||
EXPECT_STREQ("myobj->FunctionCall(y)", | ||
STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_B(y))); | ||
EXPECT_STREQ("\"foo\"", STRINGIZE(PREPROCESSOR_UTIL_UNITTEST_C)); | ||
} | ||
|
||
#if defined(OS_WIN) | ||
|
||
TEST(StringizeTest, Wide) { | ||
EXPECT_STREQ( | ||
L"PREPROCESSOR_UTIL_UNITTEST_A", | ||
LSTRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_A)); | ||
EXPECT_STREQ( | ||
L"PREPROCESSOR_UTIL_UNITTEST_B(y)", | ||
LSTRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_B(y))); | ||
EXPECT_STREQ( | ||
L"PREPROCESSOR_UTIL_UNITTEST_C", | ||
LSTRINGIZE_NO_EXPANSION(PREPROCESSOR_UTIL_UNITTEST_C)); | ||
|
||
EXPECT_STREQ(L"FOO", LSTRINGIZE(PREPROCESSOR_UTIL_UNITTEST_A)); | ||
EXPECT_STREQ(L"myobj->FunctionCall(y)", | ||
LSTRINGIZE(PREPROCESSOR_UTIL_UNITTEST_B(y))); | ||
EXPECT_STREQ(L"\"foo\"", LSTRINGIZE(PREPROCESSOR_UTIL_UNITTEST_C)); | ||
} | ||
|
||
TEST(ToLStringTest, Main) { | ||
EXPECT_STREQ(L"blat", TO_L_STRING_NO_EXPANSION("blat")); | ||
|
||
EXPECT_STREQ(L"foo", TO_L_STRING(PREPROCESSOR_UTIL_UNITTEST_C)); | ||
EXPECT_STREQ(L"blat", TO_L_STRING("blat")); | ||
} | ||
|
||
#endif // defined(OS_WIN) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters