= $textLength) { $pos = $textLength; } elseif ($pos < 0) { $pos = 0; } // Start strrpos check from the character before the current character, // in case the current character is a newline $startAt = max(-($textLength - $pos) - 1, -$textLength); $lastNewlinePos = \strrpos($text, "\n", $startAt); $char = $pos - ($lastNewlinePos === false ? 0 : $lastNewlinePos + 1); $line = $pos > 0 ? \substr_count($text, "\n", 0, $pos) : 0; return new LineCharacterPosition($line, $char); } }