brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.2 KiB · 66e50e8 Raw
62 lines · plain
1.. title:: clang-tidy - modernize-raw-string-literal2 3modernize-raw-string-literal4============================5 6This check selectively replaces string literals containing escaped characters7with 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 22becomes23 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 be36converted 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 of40writing lines of text output. Introducing physical newlines with raw41string literals in this case is likely to impede readability. These42string literals are left unchanged.43 44An escaped horizontal tab, form feed, or vertical tab prevents the string45literal from being converted. The presence of a horizontal tab, form feed or46vertical tab in source code is not visually obvious.47 48Options49-------50 51.. option:: DelimiterStem52 53  Custom delimiter to escape characters in raw string literals. It is used in54  the following construction: ``R"stem_delimiter(contents)stem_delimiter"``.55  The default value is `lit`.56 57.. option:: ReplaceShorterLiterals58 59  Controls replacing shorter non-raw string literals with longer raw string60  literals. Setting this option to `true` enables the replacement.61  The default value is `false` (shorter literals are not replaced).62