protected function parsePattern($pattern)
{
$pattern = explode(';', $pattern);
$negative = null;
if (count($pattern) > 1) {
$negative = $pattern[1];
}
$pattern = $pattern[0];
$comma = ',';
$dot = '.';
$digit = '0';
$hash = '#';
//find the first group point, and decimal point
$groupPos1 = strrpos($pattern, $comma);
$decimalPos = strrpos($pattern, $dot);
$groupPos2 = false;
$groupSize1 = false;
$groupSize2 = false;
$decimalPoints = is_int($decimalPos) ? -1 : false;
$info['negPref'] = $this->data['NumberElements'][6];
$info['negPost'] = '';
$info['negative'] = $negative;
$info['positive'] = $pattern;
//find the negative prefix and postfix
if ($negative) {
$prefixPostfix = $this->getPrePostfix($negative);
$info['negPref'] = $prefixPostfix[0];
$info['negPost'] = $prefixPostfix[1];
}
$posfix = $this->getPrePostfix($pattern);
$info['posPref'] = $posfix[0];
$info['posPost'] = $posfix[1];
//var_dump($pattern);
//var_dump($decimalPos);
if (is_int($groupPos1)) {
//get the second group
$groupPos2 = strrpos(substr($pattern, 0, $groupPos1), $comma);
//get the number of decimal digits
if (is_int($decimalPos)) {
$groupSize1 = $decimalPos - $groupPos1 - 1;
} else {
//no decimal point, so traverse from the back
//to find the groupsize 1.
for ($i = strlen($pattern) - 1; $i >= 0; $i--) {
if ($pattern[$i] == $digit || $pattern[$i] == $hash) {
$groupSize1 = $i - $groupPos1;
break;
}
}
}
//get the second group size
if (is_int($groupPos2)) {
$groupSize2 = $groupPos1 - $groupPos2 - 1;
}
}
if (is_int($decimalPos)) {
for ($i = strlen($pattern) - 1; $i >= 0; $i--) {
if ($pattern[$i] == $dot) {
break;
}
if ($pattern[$i] == $digit) {
$decimalPoints = $i - $decimalPos;
break;
}
}
}
if (is_int($decimalPos)) {
$digitPattern = substr($pattern, 0, $decimalPos);
} else {
$digitPattern = $pattern;
}
$digitPattern = preg_replace('/[^0]/', '', $digitPattern);
$info['groupPos1'] = $groupPos1;
$info['groupSize1'] = $groupSize1;
$info['groupPos2'] = $groupPos2;
$info['groupSize2'] = $groupSize2;
$info['decimalPos'] = $decimalPos;
$info['decimalPoints'] = $decimalPoints;
$info['digitSize'] = strlen($digitPattern);
return $info;
}