ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
UtfNormalUtil.php File Reference

Go to the source code of this file.

Functions

 codepointToUtf8 ( $codepoint)
 Return UTF-8 sequence for a given Unicode code point. More...
 
 hexSequenceToUtf8 ( $sequence)
 Take a series of space-separated hexadecimal numbers representing Unicode code points and return a UTF-8 string composed of those characters. More...
 
 utf8ToHexSequence ( $str)
 Take a UTF-8 string and return a space-separated series of hex numbers representing Unicode code points. More...
 
 utf8ToCodepoint ( $char)
 Determine the Unicode codepoint of a single-character UTF-8 sequence. More...
 
 escapeSingleString ( $string)
 Escape a string for inclusion in a PHP single-quoted string literal. More...
 

Function Documentation

◆ codepointToUtf8()

codepointToUtf8 (   $codepoint)

Return UTF-8 sequence for a given Unicode code point.

May die if fed out of range data.

Parameters
$codepointInteger:
Returns
String

Definition at line 38 of file UtfNormalUtil.php.

Referenced by ilCharSelectorConfig\getItemParsedCallback(), Sanitizer\hexCharReference(), hexSequenceToUtf8(), and CleanUpTest\XtestAllChars().

38  {
39  if($codepoint < 0x80) return chr($codepoint);
40  if($codepoint < 0x800) return chr($codepoint >> 6 & 0x3f | 0xc0) .
41  chr($codepoint & 0x3f | 0x80);
42  if($codepoint < 0x10000) return chr($codepoint >> 12 & 0x0f | 0xe0) .
43  chr($codepoint >> 6 & 0x3f | 0x80) .
44  chr($codepoint & 0x3f | 0x80);
45  if($codepoint < 0x110000) return chr($codepoint >> 18 & 0x07 | 0xf0) .
46  chr($codepoint >> 12 & 0x3f | 0x80) .
47  chr($codepoint >> 6 & 0x3f | 0x80) .
48  chr($codepoint & 0x3f | 0x80);
49 
50  echo "Asked for code outside of range ($codepoint)\n";
51  die( -1 );
52 }
+ Here is the caller graph for this function:

◆ escapeSingleString()

escapeSingleString (   $string)

Escape a string for inclusion in a PHP single-quoted string literal.

Parameters
$stringString: string to be escaped.
Returns
String: escaped string.

Definition at line 138 of file UtfNormalUtil.php.

References array.

138  {
139  return strtr( $string,
140  array(
141  '\\' => '\\\\',
142  '\'' => '\\\''
143  ));
144 }
Create styles array
The data for the language used.

◆ hexSequenceToUtf8()

hexSequenceToUtf8 (   $sequence)
private

Take a series of space-separated hexadecimal numbers representing Unicode code points and return a UTF-8 string composed of those characters.

Used by UTF-8 data generation and testing routines.

Parameters
$sequenceString
Returns
String

Definition at line 63 of file UtfNormalUtil.php.

References $n, and codepointToUtf8().

63  {
64  $utf = '';
65  foreach( explode( ' ', $sequence ) as $hex ) {
66  $n = hexdec( $hex );
67  $utf .= codepointToUtf8( $n );
68  }
69  return $utf;
70 }
codepointToUtf8( $codepoint)
Return UTF-8 sequence for a given Unicode code point.
$n
Definition: RandomTest.php:80
+ Here is the call graph for this function:

◆ utf8ToCodepoint()

utf8ToCodepoint (   $char)

Determine the Unicode codepoint of a single-character UTF-8 sequence.

Does not check for invalid input data.

Parameters
$charString
Returns
Integer

Definition at line 98 of file UtfNormalUtil.php.

Referenced by ilCharSelectorConfig\getItemCodepoint(), and utf8ToHexSequence().

98  {
99  # Find the length
100  $z = ord( $char{0} );
101  if ( $z & 0x80 ) {
102  $length = 0;
103  while ( $z & 0x80 ) {
104  $length++;
105  $z <<= 1;
106  }
107  } else {
108  $length = 1;
109  }
110 
111  if ( $length != strlen( $char ) ) {
112  return false;
113  }
114  if ( $length == 1 ) {
115  return ord( $char );
116  }
117 
118  # Mask off the length-determining bits and shift back to the original location
119  $z &= 0xff;
120  $z >>= $length;
121 
122  # Add in the free bits from subsequent bytes
123  for ( $i=1; $i<$length; $i++ ) {
124  $z <<= 6;
125  $z |= ord( $char{$i} ) & 0x3f;
126  }
127 
128  return $z;
129 }
+ Here is the caller graph for this function:

◆ utf8ToHexSequence()

utf8ToHexSequence (   $str)
private

Take a UTF-8 string and return a space-separated series of hex numbers representing Unicode code points.

For debugging.

Parameters
$strString: UTF-8 string.
Returns
string

Definition at line 80 of file UtfNormalUtil.php.

References utf8ToCodepoint().

80  {
81  return rtrim( preg_replace_callback(
82  '/(.)/uS',
83  function($hit) {
84  return sprintf("%04x ", utf8ToCodepoint($hit[1]));
85  },
86  $str
87  ));
88 }
utf8ToCodepoint( $char)
Determine the Unicode codepoint of a single-character UTF-8 sequence.
+ Here is the call graph for this function: