[email protected] | 176ab80 | 2010-11-18 02:15:12 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | // |
| 5 | // This file defines preprocessor macros for stringizing preprocessor |
| 6 | // symbols (or their output) and manipulating preprocessor symbols |
| 7 | // that define strings. |
| 8 | |
| 9 | #ifndef BASE_STRINGIZE_MACROS_H_ |
| 10 | #define BASE_STRINGIZE_MACROS_H_ |
[email protected] | 176ab80 | 2010-11-18 02:15:12 | [diff] [blame] | 11 | |
| 12 | #include "build/build_config.h" |
| 13 | |
| 14 | // This is not very useful as it does not expand defined symbols if |
| 15 | // called directly. Use its counterpart without the _NO_EXPANSION |
| 16 | // suffix, below. |
| 17 | #define STRINGIZE_NO_EXPANSION(x) #x |
| 18 | |
| 19 | // Use this to quote the provided parameter, first expanding it if it |
| 20 | // is a preprocessor symbol. |
| 21 | // |
| 22 | // For example, if: |
| 23 | // #define A FOO |
| 24 | // #define B(x) myobj->FunctionCall(x) |
| 25 | // |
| 26 | // Then: |
| 27 | // STRINGIZE(A) produces "FOO" |
| 28 | // STRINGIZE(B(y)) produces "myobj->FunctionCall(y)" |
| 29 | #define STRINGIZE(x) STRINGIZE_NO_EXPANSION(x) |
| 30 | |
| 31 | // The following are defined only on Windows (for use when interacting |
| 32 | // with Windows APIs) as wide strings are otherwise deprecated. |
| 33 | #if defined(OS_WIN) |
| 34 | |
| 35 | // Second-level utility macros to let us expand symbols. |
| 36 | #define LSTRINGIZE_NO_EXPANSION(x) L ## #x |
| 37 | #define TO_L_STRING_NO_EXPANSION(x) L ## x |
| 38 | |
| 39 | // L version of STRINGIZE(). For examples above, |
| 40 | // LSTRINGIZE(A) produces L"FOO" |
| 41 | // LSTRINGIZE(B(y)) produces L"myobj->FunctionCall(y)" |
| 42 | #define LSTRINGIZE(x) LSTRINGIZE_NO_EXPANSION(x) |
| 43 | |
| 44 | // Adds an L in front of an existing ASCII string constant (after |
| 45 | // expanding symbols). Does not do any quoting. |
| 46 | // |
| 47 | // For example, if: |
| 48 | // #define C "foo" |
| 49 | // |
| 50 | // Then: |
| 51 | // TO_L_STRING(C) produces L"foo" |
| 52 | #define TO_L_STRING(x) TO_L_STRING_NO_EXPANSION(x) |
| 53 | |
| 54 | #endif // defined(OS_WIN) |
| 55 | |
| 56 | #endif // BASE_STRINGIZE_MACROS_H_ |