[PATCH] D45932: [clang-tidy][modernize-raw-string-literal] Don't replace upper ASCII with raw literals
Zinovy Nis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 23 23:31:49 PDT 2018
zinovy.nis updated this revision to Diff 143679.
zinovy.nis marked an inline comment as done.
zinovy.nis added a comment.
- Use clang::isASCII instead of home-brewed code.
https://reviews.llvm.org/D45932
Files:
clang-tidy/modernize/RawStringLiteralCheck.cpp
test/clang-tidy/modernize-raw-string-literal.cpp
Index: test/clang-tidy/modernize-raw-string-literal.cpp
===================================================================
--- test/clang-tidy/modernize-raw-string-literal.cpp
+++ test/clang-tidy/modernize-raw-string-literal.cpp
@@ -40,6 +40,8 @@
char const *const Us("goink\\\037");
char const *const HexNonPrintable("\\\x03");
char const *const Delete("\\\177");
+char const *const MultibyteSnowman("\xE2\x98\x83");
+// CHECK-FIXES: {{^}}char const *const MultibyteSnowman("\xE2\x98\x83");{{$}}
char const *const TrailingSpace("A line \\with space. \n");
char const *const TrailingNewLine("A single \\line.\n");
Index: clang-tidy/modernize/RawStringLiteralCheck.cpp
===================================================================
--- clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -10,6 +10,7 @@
#include "RawStringLiteralCheck.h"
#include "clang/AST/ASTContext.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Basic/CharInfo.h"
#include "clang/Lex/Lexer.h"
using namespace clang::ast_matchers;
@@ -65,6 +66,11 @@
33)) != StringRef::npos)
return false;
+ // Don't replace chars from upper ASCII as they can represent UTF-8 or be
+ // supported by specific code pages only.
+ if (Bytes.find_if_not(isASCII) != StringRef::npos)
+ return false;
+
CharSourceRange CharRange = Lexer::makeFileCharRange(
CharSourceRange::getTokenRange(Literal->getSourceRange()),
*Result.SourceManager, Result.Context->getLangOpts());
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45932.143679.patch
Type: text/x-patch
Size: 1571 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180424/7cf45e0f/attachment.bin>
More information about the cfe-commits
mailing list