1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

LibJS: Support all line terminators (LF, CR, LS, PS)

https://tc39.es/ecma262/#sec-line-terminators
This commit is contained in:
Linus Groh 2020-10-21 22:16:45 +01:00 committed by Andreas Kling
parent 5043c4a3e5
commit 15642874f3
8 changed files with 161 additions and 29 deletions

View file

@ -114,8 +114,15 @@ public:
{
if (line == 0 || column == 0)
return {};
// We need to modify the source to match what the lexer considers one line - normalizing
// line terminators to \n is easier than splitting using all different LT characters.
String source_string { source };
source_string.replace("\r\n", "\n");
source_string.replace("\r", "\n");
source_string.replace(LINE_SEPARATOR, "\n");
source_string.replace(PARAGRAPH_SEPARATOR, "\n");
StringBuilder builder;
builder.append(source.split_view('\n', true)[line - 1]);
builder.append(source_string.split_view('\n', true)[line - 1]);
builder.append('\n');
for (size_t i = 0; i < column - 1; ++i)
builder.append(spacer);