protected function doParsingInLenientMode($numberToParse, array $parsedFormat, array $localizedSymbols)
{
$numberIsNegative = false;
$positionOfFirstDigit = null;
$positionOfLastDigit = null;
$charactersOfNumberString = str_split($numberToParse);
foreach ($charactersOfNumberString as $position => $character) {
if (ord($character) >= 48 && ord($character) <= 57) {
$positionOfFirstDigit = $position;
break;
}
}
if ($positionOfFirstDigit === null) {
return false;
}
krsort($charactersOfNumberString);
foreach ($charactersOfNumberString as $position => $character) {
if (ord($character) >= 48 && ord($character) <= 57) {
$positionOfLastDigit = $position;
break;
}
}
$positionOfDecimalSeparator = strrpos($numberToParse, $localizedSymbols['decimal'], $positionOfFirstDigit);
if ($positionOfDecimalSeparator === false) {
$integerPart = substr($numberToParse, $positionOfFirstDigit, $positionOfLastDigit - $positionOfFirstDigit + 1);
$decimalPart = false;
} else {
$integerPart = substr($numberToParse, $positionOfFirstDigit, $positionOfDecimalSeparator - $positionOfFirstDigit);
$decimalPart = substr($numberToParse, $positionOfDecimalSeparator + 1, $positionOfLastDigit - $positionOfDecimalSeparator);
}
$parsedNumber = (int) preg_replace(self::PATTERN_MATCH_NOT_DIGITS, '', $integerPart);
if ($decimalPart !== false) {
$decimalPart = (int) preg_replace(self::PATTERN_MATCH_NOT_DIGITS, '', $decimalPart);
$parsedNumber = (double) ($parsedNumber . '.' . $decimalPart);
}
$partBeforeNumber = substr($numberToParse, 0, $positionOfFirstDigit);
$partAfterNumber = substr($numberToParse, -(strlen($numberToParse) - $positionOfLastDigit - 1));
if (!empty($parsedFormat['negativePrefix']) && !empty($parsedFormat['negativeSuffix'])) {
if (Utility::stringEndsWith($partBeforeNumber, $parsedFormat['negativePrefix']) && Utility::stringBeginsWith($partAfterNumber, $parsedFormat['negativeSuffix'])) {
$numberIsNegative = true;
}
} elseif (!empty($parsedFormat['negativePrefix']) && Utility::stringEndsWith($partBeforeNumber, $parsedFormat['negativePrefix'])) {
$numberIsNegative = true;
} elseif (!empty($parsedFormat['negativeSuffix']) && Utility::stringBeginsWith($partAfterNumber, $parsedFormat['negativeSuffix'])) {
$numberIsNegative = true;
}
$parsedNumber /= $parsedFormat['multiplier'];
if ($numberIsNegative) {
$parsedNumber = 0 - $parsedNumber;
}
return $parsedNumber;
}