1
0
mirror of https://github.com/erusev/parsedown.git synced 2023-08-10 21:13:06 +03:00

faster check substr at beginning of string

This commit is contained in:
Aidan Woods 2017-05-05 21:55:58 +01:00
parent dc30cb441c
commit 2e4afde68d
No known key found for this signature in database
GPG Key ID: 9A6A8EFAA512BBB9

View File

@ -1533,7 +1533,7 @@ class Parsedown
unset($Element['attributes'][$att]);
}
# dump onevent attribute
elseif (preg_match('/^on/i', $att))
elseif (self::striAtStart($att, 'on'))
{
unset($Element['attributes'][$att]);
}
@ -1551,7 +1551,7 @@ class Parsedown
foreach ($this->safeLinksWhitelist as $scheme)
{
if (stripos($Element['attributes'][$attribute], $scheme) === 0)
if (self::striAtStart($Element['attributes'][$attribute], $scheme))
{
$safe = true;
@ -1584,6 +1584,20 @@ class Parsedown
return htmlspecialchars($text, $allowQuotes ? ENT_NOQUOTES : ENT_QUOTES, 'UTF-8');
}
protected static function striAtStart($string, $needle)
{
$len = strlen($needle);
if ($len > strlen($string))
{
return false;
}
else
{
return strtolower(substr($string, 0, $len)) === strtolower($needle);
}
}
static function instance($name = 'default')
{
if (isset(self::$instances[$name]))