1.. title:: clang-tidy - modernize-raw-string-literal 2 3modernize-raw-string-literal 4============================ 5 6This check selectively replaces string literals containing escaped characters 7with raw string literals. 8 9Example: 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 22becomes 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 35The presence of any of the following escapes can cause the string to be 36converted to a raw string literal: ``\\``, ``\'``, ``\"``, ``\?``, 37and octal or hexadecimal escapes for printable ASCII characters. 38 39A string literal containing only escaped newlines is a common way of 40writing lines of text output. Introducing physical newlines with raw 41string literals in this case is likely to impede readability. These 42string literals are left unchanged. 43 44An escaped horizontal tab, form feed, or vertical tab prevents the string 45literal from being converted. The presence of a horizontal tab, form feed or 46vertical 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). 59