Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/modernize/raw-string-literal.rst

raw
1 .. title:: clang-tidy - modernize-raw-string-literal
2
3 modernize-raw-string-literal
4 ============================
5
6 This check selectively replaces string literals containing escaped characters
7 with raw string literals.
8
9 Example:
10
11 .. code-block:: c++
12
13 const char *const Quotes{"embedded \"quotes\""};
14 const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
15 const char *const SingleLine{"Single line.\n"};
16 const char *const TrailingSpace{"Look here -> \n"};
17 const char *const Tab{"One\tTwo\n"};
18 const char *const Bell{"Hello!\a And welcome!"};
19 const char *const Path{"C:\\Program Files\\Vendor\\Application.exe"};
20 const char *const RegEx{"\\w\\([a-z]\\)"};
21
22 becomes
23
24 .. code-block:: c++
25
26 const char *const Quotes{R"(embedded "quotes")"};
27 const char *const Paragraph{"Line one.\nLine two.\nLine three.\n"};
28 const char *const SingleLine{"Single line.\n"};
29 const char *const TrailingSpace{"Look here -> \n"};
30 const char *const Tab{"One\tTwo\n"};
31 const char *const Bell{"Hello!\a And welcome!"};
32 const char *const Path{R"(C:\Program Files\Vendor\Application.exe)"};
33 const char *const RegEx{R"(\w\([a-z]\))"};
34
35 The presence of any of the following escapes can cause the string to be
36 converted to a raw string literal: ``\\``, ``\'``, ``\"``, ``\?``,
37 and octal or hexadecimal escapes for printable ASCII characters.
38
39 A string literal containing only escaped newlines is a common way of
40 writing lines of text output. Introducing physical newlines with raw
41 string literals in this case is likely to impede readability. These
42 string literals are left unchanged.
43
44 An escaped horizontal tab, form feed, or vertical tab prevents the string
45 literal from being converted. The presence of a horizontal tab, form feed or
46 vertical tab in source code is not visually obvious.
47
48 .. option:: DelimiterStem
49
50 Custom delimiter to escape characters in raw string literals. It is used in
51 the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.
52 The default value is `lit`.
53
54 .. option:: ReplaceShorterLiterals
55
56 Controls replacing shorter non-raw string literals with longer raw string
57 literals. Setting this option to `true` enables the replacement.
58 The default value is `false` (shorter literals are not replaced).