| @@ -45,15 +45,18 @@ | ||
| 45 | 45 | * Read characters until we reach the given character $char. |
| 46 | 46 | * By default, discard that final matching character and return the rest. |
| 47 | 47 | * |
| 48 | 48 | * @param string $char |
| 49 | + * | |
| 49 | 50 | * @return string |
| 50 | 51 | */ |
| 51 | 52 | public function read_until( $char ) { |
| 52 | 53 | $value = ''; |
| 54 | + | |
| 53 | 55 | while ( $this->pos <= $this->max && ( $one = $this->string[ $this->pos++ ] ) !== $char ) { |
| 54 | 56 | $value .= $one; |
| 55 | 57 | } |
| 58 | + | |
| 56 | 59 | return $value; |
| 57 | 60 | } |
| 58 | 61 | |
| 59 | 62 | /** |
| @@ -61,8 +64,9 @@ | ||
| 61 | 64 | * whichever comes first. |
| 62 | 65 | * By default, remove enclosing double-quotes from the result. |
| 63 | 66 | * |
| 64 | 67 | * @param int $count |
| 68 | + * | |
| 65 | 69 | * @return string |
| 66 | 70 | */ |
| 67 | 71 | public function read( $count ) { |
| 68 | 72 | $value = ''; |
| @@ -80,9 +84,9 @@ | ||
| 80 | 84 | * abc => abc |
| 81 | 85 | * "abc" => abc |
| 82 | 86 | * ""abc"" => "abc" |
| 83 | 87 | */ |
| 84 | - if ( strlen( $value ) < 2 || substr( $value, 0, 1 ) !== '"' || substr( $value, -1, 1 ) !== '"' ) { | |
| 88 | + if ( strlen( $value ) < 2 || ! str_starts_with( $value, '"' ) || ! str_ends_with( $value, '"' ) ) { | |
| 85 | 89 | // Only remove exactly one quote from the start and the end and then only if there is one at each end. |
| 86 | 90 | // Too short, or does not start or end with a quote. |
| 87 | 91 | return $value; |
| 88 | 92 | } |