Compares two strings, returning the longest, or whichever is first alphabetically if they are the same length.
Description
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
.
Parameters
$a
stringrequired- First string to compare.
$b
stringrequired- Second string to compare.
Source
* @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.
*/
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;
}
Changelog
Version | Description |
---|---|
6.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.