[clang-tools-extra] r284391 - [clang-move] Fix generating illegal header guard.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 17 08:26:34 PDT 2016
Author: hokein
Date: Mon Oct 17 10:26:34 2016
New Revision: 284391
URL: http://llvm.org/viewvc/llvm-project?rev=284391&view=rev
Log:
[clang-move] Fix generating illegal header guard.
The filepath might contain some characters (i.e. '@') which are not
illegal in c identifiers. This patch changes all non-alphanumeric characters
to '_'.
Modified:
clang-tools-extra/trunk/clang-move/ClangMove.cpp
Modified: clang-tools-extra/trunk/clang-move/ClangMove.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-move/ClangMove.cpp?rev=284391&r1=284390&r2=284391&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-move/ClangMove.cpp (original)
+++ clang-tools-extra/trunk/clang-move/ClangMove.cpp Mon Oct 17 10:26:34 2016
@@ -233,10 +233,10 @@ createInsertedReplacements(const std::ve
std::string NewCode;
std::string GuardName(FileName);
if (IsHeader) {
- std::replace(GuardName.begin(), GuardName.end(), '/', '_');
- std::replace(GuardName.begin(), GuardName.end(), '.', '_');
- std::replace(GuardName.begin(), GuardName.end(), '-', '_');
-
+ for (size_t i = 0; i < GuardName.size(); ++i) {
+ if (!isAlphanumeric(GuardName[i]))
+ GuardName[i] = '_';
+ }
GuardName = StringRef(GuardName).upper();
NewCode += "#ifndef " + GuardName + "\n";
NewCode += "#define " + GuardName + "\n";
More information about the cfe-commits
mailing list