File tree Expand file tree Collapse file tree 5 files changed +29
-158
lines changed Expand file tree Collapse file tree 5 files changed +29
-158
lines changed Original file line number Diff line number Diff line change 2020 "files" : [
2121 " utf8.php" ,
2222 " compat-utf8.php" ,
23- " utf8-encoder.php" ,
24- " utf8-decoder.php"
23+ " utf8-encoder.php"
2524 ],
2625 "exclude-from-classmap" : [
2726 " /Tests/"
Load Diff This file was deleted.
Original file line number Diff line number Diff line change @@ -197,3 +197,31 @@ function wp_has_noncharacters( string $text ): bool {
197197 return _wp_has_noncharacters_fallback ( $ text );
198198 }
199199endif ;
200+
201+ /**
202+ * Convert a UTF-8 byte sequence to its Unicode codepoint.
203+ *
204+ * @param string $character UTF-8 encoded byte sequence representing a single Unicode character.
205+ *
206+ * @return int Unicode codepoint.
207+ */
208+ function utf8_ord ( string $ character ): int {
209+ // Convert the byte sequence to its binary representation.
210+ $ bytes = unpack ( 'C* ' , $ character );
211+
212+ // Initialize the codepoint.
213+ $ codepoint = 0 ;
214+
215+ // Calculate the codepoint based on the number of bytes.
216+ if ( 1 === count ( $ bytes ) ) {
217+ $ codepoint = $ bytes [1 ];
218+ } elseif ( 2 === count ( $ bytes ) ) {
219+ $ codepoint = ( ( $ bytes [1 ] & 0x1F ) << 6 ) | ( $ bytes [2 ] & 0x3F );
220+ } elseif ( 3 === count ( $ bytes ) ) {
221+ $ codepoint = ( ( $ bytes [1 ] & 0x0F ) << 12 ) | ( ( $ bytes [2 ] & 0x3F ) << 6 ) | ( $ bytes [3 ] & 0x3F );
222+ } elseif ( 4 === count ( $ bytes ) ) {
223+ $ codepoint = ( ( $ bytes [1 ] & 0x07 ) << 18 ) | ( ( $ bytes [2 ] & 0x3F ) << 12 ) | ( ( $ bytes [3 ] & 0x3F ) << 6 ) | ( $ bytes [4 ] & 0x3F );
224+ }
225+
226+ return $ codepoint ;
227+ }
Original file line number Diff line number Diff line change 5151 " components/Encoding/utf8.php" ,
5252 " components/Encoding/compat-utf8.php" ,
5353 " components/Encoding/utf8-encoder.php" ,
54- " components/Encoding/utf8-decoder.php" ,
5554 " components/Filesystem/functions.php" ,
5655 " components/Zip/functions.php" ,
5756 " components/Polyfill/wordpress.php" ,
Original file line number Diff line number Diff line change 6363 " components/Encoding/utf8.php" ,
6464 " components/Encoding/compat-utf8.php" ,
6565 " components/Encoding/utf8-encoder.php" ,
66- " components/Encoding/utf8-decoder.php" ,
6766 " components/Filesystem/functions.php" ,
6867 " components/Zip/functions.php" ,
6968 " components/Polyfill/wordpress.php" ,
You can’t perform that action at this time.
0 commit comments