summaryrefslogtreecommitdiffstats
path: root/base/stringize_macros.h
diff options
context:
space:
mode:
authorjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-18 02:15:12 +0000
committerjoi@chromium.org <joi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-11-18 02:15:12 +0000
commit176ab8038d7c1b291dcec51f29ed81f9fba52b8e (patch)
treecf837db3622bc957a21309e96005e16a94cf594d /base/stringize_macros.h
parentab9cb282693fb8e36b2d035fccd07d4b93acf65f (diff)
downloadchromium_src-176ab8038d7c1b291dcec51f29ed81f9fba52b8e.zip
chromium_src-176ab8038d7c1b291dcec51f29ed81f9fba52b8e.tar.gz
chromium_src-176ab8038d7c1b291dcec51f29ed81f9fba52b8e.tar.bz2
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
Diffstat (limited to 'base/stringize_macros.h')
-rw-r--r--base/stringize_macros.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/base/stringize_macros.h b/base/stringize_macros.h
new file mode 100644
index 0000000..7c3af49
--- /dev/null
+++ b/base/stringize_macros.h
@@ -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_