WP_Token_Map::longest_first_then_alphabetical()
Compares two strings, returning the longest, or whichever is first alphabetically if they are the same length.
This is an important sort when building the token map because it should not form a match on a substring of a longer potential match. For example, it should not detect Cap when matching against the string CapitalDifferentialD.
Method of the class: WP_Token_Map{}
No Hooks.
Return
Int
. -1 or lower if $a is less than $b; 1 or greater if $a is greater than $b, and 0 if they are equal.
Usage
$result = WP_Token_Map::longest_first_then_alphabetical( $a, $b ): int;
- $a(string) (required)
- First string to compare.
- $b(string) (required)
- Second string to compare.
Changelog
Since 6.6.0 | Introduced. |
WP_Token_Map::longest_first_then_alphabetical() WP Token Map::longest first then alphabetical code WP 6.7.1
private static function longest_first_then_alphabetical( string $a, string $b ): int { if ( $a === $b ) { return 0; } $length_a = strlen( $a ); $length_b = strlen( $b ); // Longer strings are less-than for comparison's sake. if ( $length_a !== $length_b ) { return $length_b - $length_a; } return strcmp( $a, $b ); }