} $text = preg_replace(array('/^\\s*/', '/\\s*$/', '/\\s+/'), array('', '', ' '), optional_param('text', '', PARAM_TEXT)); // Compare strings ignoring case if (false == $options['usecasesensitive']) { $parsed_text = mb_strtolower($text, 'UTF-8'); $parsed_content = mb_strtolower($elements[$number]['content'], 'UTF-8'); } else { $parsed_text = $text; $parsed_content = $elements[$number]['content']; } $previous_locale = setlocale(LC_ALL, 0); // Use the locales associated to the language tag if (false === setlocale(LC_ALL, Elang\getLocale($options["language"]))) { setlocale(LC_ALL, $previous_locale); } if ($parsed_text == $parsed_content || $options['usetransliteration'] && @iconv('UTF-8', 'ASCII//TRANSLIT', $parsed_text) == @iconv('UTF-8', 'ASCII//TRANSLIT', $parsed_content) || Elang\jaro($parsed_text, $parsed_content) >= $options['jaroDistance']) { $text = $elements[$number]['content']; } setlocale(LC_ALL, $previous_locale); // Log action if (!empty($text)) { $check_id = $DB->insert_record('elang_check', array('id_elang' => $elang->id, 'cue' => $cue->number, 'guess' => $elements[$number]['order'], 'info' => $elements[$number]['content'], 'user' => $text)); if (version_compare($version, '2.7') < 0) { add_to_log($course->id, 'elang', 'add check', 'view.php?id=' . $cm->id, $check_id, $cm->id); } else { $event = \mod_elang\event\check_added::create(array('objectid' => $check_id, 'context' => $context, 'courseid' => $course->id, 'other' => array('cue' => $cue->number, 'guess' => $elements[$number]['order'], 'info' => $elements[$number]['content'], 'user' => $text))); $event->trigger(); } } if ($user) { $data[$number] = array('help' => false, 'content' => $text);
/** * Test the jaro method * * @param string $str1 String 1 * @param string $str2 String 2 * @param integer $precision Precision * @param float $jaro Jaro's distance * * @return void * * @dataProvider casesJaro * * @since 1.3.0 */ public function testJaro($str1, $str2, $precision, $jaro) { // Test Jaro's distance $this->assertEquals(round(Elang\jaro($str1, $str2), $precision), round($jaro, $precision)); }