Skip to content

Commit 9cae1f9

Browse files
authored
Remove utf8_codepoint_at() (#203)
Removes the `utf8_codepoint_at()` function. It is no longer used as all the php-toolkit classes are migrated to the `_wp_scan_utf8` function shipped with WordPress 6.9. Follows up on #200 Solves #196 #201 and #202 must be merged before this PR.
1 parent 7241121 commit 9cae1f9

File tree

5 files changed

+29
-158
lines changed

5 files changed

+29
-158
lines changed

components/Encoding/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
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/"

components/Encoding/utf8-decoder.php

Lines changed: 0 additions & 154 deletions
This file was deleted.

components/Encoding/utf8.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,31 @@ function wp_has_noncharacters( string $text ): bool {
197197
return _wp_has_noncharacters_fallback( $text );
198198
}
199199
endif;
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+
}

composer-ci-matrix-tests.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
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",

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
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",

0 commit comments

Comments
 (0)