Skip to content

Commit

Permalink
UTF8-safe snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
danog committed Mar 1, 2021
1 parent 1ab0a5d commit 04bd3d9
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Psalm/CodeLocation.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
use function strlen;
use function strpos;
use function strrpos;
use function substr;
use function substr_count;
use function mb_strcut;
use function trim;

class CodeLocation
Expand Down Expand Up @@ -183,7 +183,7 @@ private function calculateRealLocation(): void
) {
$preview_lines = explode(
"\n",
substr(
mb_strcut(
$file_contents,
$this->preview_start,
$this->selection_start - $this->preview_start - 1
Expand All @@ -206,7 +206,7 @@ private function calculateRealLocation(): void

$indentation = (int)strpos($key_line, '@');

$key_line = trim(preg_replace('@\**/\s*@', '', substr($key_line, $indentation)));
$key_line = trim(preg_replace('@\**/\s*@', '', mb_strcut($key_line, $indentation)));

$this->selection_start = $preview_offset + $indentation + $this->preview_start;
$this->selection_end = $this->selection_start + strlen($key_line);
Expand Down Expand Up @@ -258,7 +258,7 @@ private function calculateRealLocation(): void
throw new \UnexpectedValueException('Unrecognised regex type ' . $this->regex_type);
}

$preview_snippet = substr(
$preview_snippet = mb_strcut(
$file_contents,
$this->selection_start,
$this->selection_end - $this->selection_start
Expand Down Expand Up @@ -298,8 +298,8 @@ private function calculateRealLocation(): void
}
}

$this->snippet = substr($file_contents, $this->preview_start, $this->preview_end - $this->preview_start);
$this->text = substr($file_contents, $this->selection_start, $this->selection_end - $this->selection_start);
$this->snippet = mb_strcut($file_contents, $this->preview_start, $this->preview_end - $this->preview_start);
$this->text = mb_strcut($file_contents, $this->selection_start, $this->selection_end - $this->selection_start);

// reset preview start to beginning of line
$this->column_from = $this->selection_start -
Expand Down

0 comments on commit 04bd3d9

Please sign in to comment.