Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/languages/cpp.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ function(hljs) {
className: 'string',
variants: [
{
begin: '(u8?|U)?L?"', end: '"',
begin: '(u8?|U|L)?"', end: '"',
illegal: '\\n',
contains: [hljs.BACKSLASH_ESCAPE]
},
{
begin: '(u8?|U)?R"', end: '"',
contains: [hljs.BACKSLASH_ESCAPE]
// TODO: This does not handle raw string literals with prefixes. Using
// a single regex with backreferences would work (note to use *?
// instead of * to make it non-greedy), but the mode.terminators
// computation in highlight.js breaks the counting.
begin: '(u8?|U|L)?R"\\(', end: '\\)"',
},
{
begin: '\'\\\\?.', end: '\'',
Expand Down
8 changes: 4 additions & 4 deletions test/markup/cpp/string-literals.expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@

<span class="hljs-comment">// Raw string literals (multiline)</span>
<span class="hljs-keyword">auto</span> char_multi = <span class="hljs-string">R"(Hello
normal
"normal"
muliline
string.)"</span>;
<span class="hljs-keyword">auto</span> utf8_multi = <span class="hljs-string">u8R"(Hello
utf-8
"utf-8"
muliline
string)"</span>;
<span class="hljs-keyword">auto</span> utf16_multi = <span class="hljs-string">uR"(Hello
utf-16
"utf-16"
muliline
string)"</span>;
<span class="hljs-keyword">auto</span> utf32_multi = <span class="hljs-string">UR"(Hello
utf-32
"utf-32"
muliline
string)"</span>;

Expand Down
8 changes: 4 additions & 4 deletions test/markup/cpp/string-literals.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ auto wide_char = L"Hello wchar_t string";

// Raw string literals (multiline)
auto char_multi = R"(Hello
normal
"normal"
muliline
string.)";
auto utf8_multi = u8R"(Hello
utf-8
"utf-8"
muliline
string)";
auto utf16_multi = uR"(Hello
utf-16
"utf-16"
muliline
string)";
auto utf32_multi = UR"(Hello
utf-32
"utf-32"
muliline
string)";

Expand Down