Factor out percent escaping

This commit is contained in:
Michal Čihař 2011-08-15 08:56:02 +02:00
parent 621d179573
commit 9be2507a58

View File

@ -81,6 +81,14 @@ class Advisor
return true;
}
/**
* Escapes percent string to be used in format string.
*/
function escapePercent($str)
{
return preg_replace('/%( |,|\.|$)/','%%\1', $str);
}
/**
* Splits justification to text and formula.
*/
@ -88,7 +96,7 @@ class Advisor
{
$jst = preg_split('/\s*\|\s*/', $rule['justification'], 2);
if (count($jst) > 1) {
$jst[0] = preg_replace('/%( |,|\.|$)/','%%\1',$jst[0]);
$jst[0] = Advisor::escapePercent($jst[0]);
return array($jst[0], $jst[1]);
}
return array($rule['justification']);