]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-20810: add missing function hotpot_charcode_to_utf8() required when importing...
authorGordon Bateson <gordon@kanazawa-gu.ac.jp>
Tue, 8 Dec 2009 04:13:20 +0000 (04:13 +0000)
committerGordon Bateson <gordon@kanazawa-gu.ac.jp>
Tue, 8 Dec 2009 04:13:20 +0000 (04:13 +0000)
question/format/hotpot/format.php

index 3c95de161a1d42f9a9d75dbd072b5f5003f7f3d1..a9fdc7246748f51d7d170c4b47946e49e1c7240f 100644 (file)
@@ -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 = '(?:(<)|(&lt;)|(&amp;#x003C;))'; // left angle bracket
     $tagclose = '(?(2)>|(?(3)&gt;|(?(4)&amp;#x003E;)))'; //  right angle bracket (to match left angle bracket)