@@ -425,6 +425,66 @@ function _wp_has_noncharacters_fallback( string $text ): bool {
425425 return $ has_noncharacters ;
426426}
427427
428+ /**
429+ * Get Unicode code point of character
430+ *
431+ * This is a polyfill for {@see \mb_ord()}.
432+ *
433+ * @since {WP_VERSION}
434+ *
435+ * @ignore
436+ *
437+ * @param string $string Return the Unicode code point number for the first UTF-8 character in this string.
438+ * @param ?string $encoding Must be "UTF-8" if provided, else omitted.
439+ * @return int|false Code point if able to decode the first character from the string, else false.
440+ */
441+ function _wp_mb_ord ( $ string , $ encoding = null ) {
442+ if ( isset ( $ encoding ) && ! is_utf8_charset ( $ encoding ) ) {
443+ return false ;
444+ }
445+
446+ $ at = 0 ;
447+ $ invalid_length = 0 ;
448+ $ count = _wp_scan_utf8 ( $ string , $ at , $ invalid_length , null , 1 );
449+
450+ // Beyond this check, all relevant bytes are well-formed.
451+ if ( 1 !== $ count ) {
452+ return false ;
453+ }
454+
455+ switch ( $ at ) {
456+ case 1 :
457+ return ord ( $ string [ $ at ] );
458+
459+ case 2 :
460+ $ byte1 = ord ( $ string [ $ at ] );
461+ $ byte2 = ord ( $ string [ $ at + 1 ] );
462+ return ( $ byte1 & 0x1F ) << 6 + ( $ byte2 & 0x3F );
463+
464+ case 3 :
465+ $ byte1 = ord ( $ string [ $ at ] );
466+ $ byte2 = ord ( $ string [ $ at + 1 ] );
467+ $ byte3 = ord ( $ string [ $ at + 2 ] );
468+ return (
469+ ( ( $ byte1 & 0x3F ) << 12 ) +
470+ ( ( $ byte2 & 0x3F ) << 6 ) +
471+ ( $ byte3 & 0x3F )
472+ );
473+
474+ case 4 :
475+ $ byte1 = ord ( $ string [ $ at ] );
476+ $ byte2 = ord ( $ string [ $ at + 1 ] );
477+ $ byte3 = ord ( $ string [ $ at + 2 ] );
478+ $ byte4 = ord ( $ string [ $ at + 3 ] );
479+ return (
480+ ( ( $ byte1 & 0x07 ) << 18 ) +
481+ ( ( $ byte2 & 0x3F ) << 12 ) +
482+ ( ( $ byte3 & 0x3F ) << 6 ) +
483+ ( $ byte4 & 0x3F )
484+ );
485+ }
486+ }
487+
428488/**
429489 * Converts a string from ISO-8859-1 to UTF-8, maintaining backwards compatibility
430490 * with the deprecated function from the PHP standard library.
0 commit comments