From 6a046e33e9f140a31f7b8543a5485405ab70cf15 Mon Sep 17 00:00:00 2001 From: Michele Locati Date: Fri, 2 Sep 2016 10:55:07 +0200 Subject: [PATCH] Use strpos (much faster than preg_match) to determine if a char is a white space White space characters are defined by the PCRELib as: - LF (dec 10 = hex \x0a = char "\n") - HT (dec 9 = hex \x09 = char "\t") - VT (dec 11 = hex \x0b = char "\v") - FF (dec 12 = hex \x0c = char "\f") - CR (dec 13 = hex \x0d = char "\r") - space (dec 32 = hex \x20 = char " ") Reference: https://github.com/php/php-src/blob/master/ext/pcre/pcrelib/doc/pcre.txt#L5203-L5204 --- lib/Less/Parser.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Less/Parser.php b/lib/Less/Parser.php index 1c65f982..44ff885c 100644 --- a/lib/Less/Parser.php +++ b/lib/Less/Parser.php @@ -664,9 +664,15 @@ private function forget(){ array_pop($this->saveStack); } - + /** + * Determine if the character at the specified offset from the current position is a white space. + * + * @param int $offset + * + * @return bool + */ private function isWhitespace($offset = 0) { - return preg_match('/\s/',$this->input[ $this->pos + $offset]); + return strpos(" \t\n\r\v\f", $this->input[$this->pos + $offset]) !== false; } /**