From eaa658c4b2736786298b48a97ea89d904c25bb79 Mon Sep 17 00:00:00 2001 From: Gordon Bateson Date: Tue, 8 Dec 2009 04:13:20 +0000 Subject: [PATCH] MDL-20810: add missing function hotpot_charcode_to_utf8() required when importing Hot Potatoes files containing non-ascii chars into Moodle question bank --- question/format/hotpot/format.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/question/format/hotpot/format.php b/question/format/hotpot/format.php index 3c95de161a..a9fdc72467 100644 --- a/question/format/hotpot/format.php +++ b/question/format/hotpot/format.php @@ -509,6 +509,28 @@ class qformat_hotpot extends qformat_default { } } // end class +function hotpot_charcode_to_utf8($charcode) { + // thanks to Miguel Perez: http://jp2.php.net/chr (19-Sep-2007) + if ($charcode <= 0x7F) { + // ascii char (roman alphabet + punctuation) + return chr($charcode); + } + if ($charcode <= 0x7FF) { + // 2-byte char + return chr(($charcode >> 0x06) + 0xC0).chr(($charcode & 0x3F) + 128); + } + if ($charcode <= 0xFFFF) { + // 3-byte char + return chr(($charcode >> 0x0C) + 0xE0).chr((($charcode >> 0x06) & 0x3F) + 0x80).chr(($charcode & 0x3F) + 0x80); + } + if ($charcode <= 0x1FFFFF) { + // 4-byte char + return chr(($charcode >> 0x12) + 0xF0).chr((($charcode >> 0x0C) & 0x3F) + 0x80).chr((($charcode >> 0x06) & 0x3F) + 0x80).chr(($charcode & 0x3F) + 0x80); + } + // unidentified char code !! + return ' '; +} + function hotpot_convert_relative_urls($str, $baseurl, $filename) { $tagopen = '(?:(<)|(<)|(&#x003C;))'; // left angle bracket $tagclose = '(?(2)>|(?(3)>|(?(4)&#x003E;)))'; // right angle bracket (to match left angle bracket) -- 2.39.5