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