mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 00:16:46 +02:00
MDL-20636 I think I have now find a reliable way to parse responses.
This commit is contained in:
parent
544de1c035
commit
b3c9da2f0a
1 changed files with 11 additions and 11 deletions
|
@ -1120,13 +1120,12 @@ class qtype_numerical_answer_processor {
|
|||
$decimalsre = $decsep . '(\d*)';
|
||||
$exponentre = '(?:e|E|(?:x|\*|×)10(?:\^|\*\*))([+-]?\d+)';
|
||||
|
||||
$validunitendchars = "[^-$decsep\deEx*×^+$thousandssep]";
|
||||
$numberbit = "$beforepointre(?:$decimalsre)?(?:$exponentre)?";
|
||||
|
||||
if ($this->unitsbefore) {
|
||||
$unitre = "(.*)(?:(?=\s)|(?<=$validunitendchars))\s*";
|
||||
$this->regex = "/^(?:$unitre)?$beforepointre(?:$decimalsre)?(?:$exponentre)?$/U";
|
||||
$this->regex = "/$numberbit$/";
|
||||
} else {
|
||||
$unitre = "\s*(?:(?<=\s)|(?=$validunitendchars))(.*)";
|
||||
$this->regex = "/^$beforepointre(?:$decimalsre)?(?:$exponentre)?(?:$unitre)?$/U";
|
||||
$this->regex = "/^$numberbit/";
|
||||
}
|
||||
return $this->regex;
|
||||
}
|
||||
|
@ -1144,12 +1143,8 @@ class qtype_numerical_answer_processor {
|
|||
return array(null, null, null, null);
|
||||
}
|
||||
|
||||
$matches += array('', '', '', '', ''); // Fill in any missing matches.
|
||||
if ($this->unitsbefore) {
|
||||
list($notused, $unit, $beforepoint, $decimals, $exponent) = $matches;
|
||||
} else {
|
||||
list($notused, $beforepoint, $decimals, $exponent, $unit) = $matches;
|
||||
}
|
||||
$matches += array('', '', '', ''); // Fill in any missing matches.
|
||||
list($matchedpart, $beforepoint, $decimals, $exponent) = $matches;
|
||||
|
||||
// Strip out thousands separators.
|
||||
$beforepoint = str_replace($this->thousandssep, '', $beforepoint);
|
||||
|
@ -1160,6 +1155,11 @@ class qtype_numerical_answer_processor {
|
|||
return array(null, null, null, null);
|
||||
}
|
||||
|
||||
if ($this->unitsbefore) {
|
||||
$unit = substr($response, 0, -strlen($matchedpart));
|
||||
} else {
|
||||
$unit = substr($response, strlen($matchedpart));
|
||||
}
|
||||
$unit = trim($unit);
|
||||
if ($unit && !array_key_exists($unit, $this->units)) {
|
||||
$unit = '';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue