2# Copyright (C) 2004 Brion Vibber <brion@pobox.com>
5# This program is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
15# You should have received a copy of the GNU General Public License along
16# with this program; if not, write to the Free Software Foundation, Inc.,
17# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
40 if ($codepoint < 0x80) {
41 return chr($codepoint);
43 if ($codepoint < 0x800) {
44 return chr($codepoint >> 6 & 0x3f | 0xc0) .
45 chr($codepoint & 0x3f | 0x80);
47 if ($codepoint < 0x10000) {
48 return chr($codepoint >> 12 & 0x0f | 0xe0) .
49 chr($codepoint >> 6 & 0x3f | 0x80) .
50 chr($codepoint & 0x3f | 0x80);
52 if ($codepoint < 0x110000) {
53 return chr($codepoint >> 18 & 0x07 | 0xf0) .
54 chr($codepoint >> 12 & 0x3f | 0x80) .
55 chr($codepoint >> 6 & 0x3f | 0x80) .
56 chr($codepoint & 0x3f | 0x80);
59 echo
"Asked for code outside of range ($codepoint)\n";
75 foreach (explode(
' ', $sequence) as $hex) {
92 return rtrim(preg_replace_callback(
123 if ($length != strlen($char)) {
130 # Mask off the length-determining bits and shift back to the original location
134 # Add in the free bits from subsequent bytes
135 for (
$i=1;
$i<$length;
$i++) {
137 $z |= ord($char{
$i}) & 0x3f;
sprintf('%.4f', $callTime)
utf8ToHexSequence($str)
Take a UTF-8 string and return a space-separated series of hex numbers representing Unicode code poin...
escapeSingleString($string)
Escape a string for inclusion in a PHP single-quoted string literal.
codepointToUtf8($codepoint)
Return UTF-8 sequence for a given Unicode code point.
utf8ToCodepoint($char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.
hexSequenceToUtf8($sequence)
Take a series of space-separated hexadecimal numbers representing Unicode code points and return a UT...
An exception for terminatinating execution or to throw for unit testing.