Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit bd2227a

Browse files
committed
Importing state as of zendframework/zendframework@fdf39b5 (1423580085)
Automatic import via rsync
1 parent 3afbb5d commit bd2227a

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Scanner/AnnotationScanner.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ protected function tokenize()
160160
}
161161
$currentChar = $stream[$streamIndex];
162162
$matches = array();
163-
$currentLine = (preg_match('#(.*)\n#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex);
163+
$currentLine = (preg_match('#(.*?)(?:\n|\r\n?)#', $stream, $matches, null, $streamIndex) === 1) ? $matches[1] : substr($stream, $streamIndex);
164164
if ($currentChar === ' ') {
165165
$currentWord = (preg_match('#( +)#', $currentLine, $matches) === 1) ? $matches[1] : $currentLine;
166166
} else {
@@ -213,7 +213,7 @@ protected function tokenize()
213213
}
214214

215215
if ($MACRO_HAS_CONTEXT($CONTEXT_CLASS)) {
216-
if (in_array($currentChar, array(' ', '(', "\n"))) {
216+
if (in_array($currentChar, array(' ', '(', "\n", "\r"))) {
217217
$context &= ~$CONTEXT_CLASS;
218218
$MACRO_TOKEN_ADVANCE();
219219
} else {
@@ -225,7 +225,22 @@ protected function tokenize()
225225
}
226226
}
227227

228-
if ($currentChar === "\n") {
228+
// Since we don't know what line endings are used in the file, we check for all scenarios. If we find a
229+
// cariage return (\r), we check the next character for a line feed (\n). If so we consume it and act as
230+
// if the cariage return was a line feed.
231+
$lineEnded = $currentChar === "\n";
232+
if ($currentChar === "\r") {
233+
$lineEnded = true;
234+
235+
$nextChar = $MACRO_STREAM_ADVANCE_CHAR();
236+
if ($nextChar !== "\n") {
237+
$streamIndex--;
238+
}
239+
240+
$currentChar = "\n";
241+
}
242+
243+
if ($lineEnded) {
229244
$MACRO_TOKEN_SET_TYPE('ANNOTATION_NEWLINE');
230245
$MACRO_TOKEN_APPEND_CHAR();
231246
$MACRO_TOKEN_ADVANCE();

0 commit comments

Comments
 (0)