Skip to content

Commit 1c339d9

Browse files
committed
when we find nullbytes, point user towards 16bit encodings
1 parent f245b06 commit 1c339d9

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/HLL/Compiler.nqp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,7 @@ class HLL::Compiler does HLL::Backend::Default {
357357
my str $line := "";
358358
my int $lineno := 0;
359359
my int $char-found := -1;
360+
my int $nulls-found := 0;
360361

361362
until $char-found != -1 {
362363
$line := nqp::readlinechompfh($new-handle);
@@ -368,6 +369,8 @@ class HLL::Compiler does HLL::Backend::Default {
368369
if nqp::ordat($line, $idx) == 0x10fffd {
369370
$char-found := $idx;
370371
last;
372+
} elsif nqp::ordat($line, $idx) == 0 {
373+
$nulls-found++;
371374
}
372375
}
373376
}
@@ -376,6 +379,9 @@ class HLL::Compiler does HLL::Backend::Default {
376379
nqp::sayfh(nqp::getstderr(), "Error while reading from file: Invalid UTF-8 encountered on line $lineno, character $char-found");
377380
nqp::sayfh(nqp::getstderr(), $line);
378381
nqp::sayfh(nqp::getstderr(), nqp::x(" ", $char-found) ~ "^ here maybe?");
382+
if $nulls-found > 2 {
383+
nqp::sayfh(nqp::getstderr(), "Is the caret in the wrong position?\nWe found $nulls-found null bytes, which usually means utf16 or ucs16 encoding.");
384+
}
379385

380386
return;
381387
}

0 commit comments

Comments
 (0)