Indicates if a given word is a lookup key in the map.
Description
Example:
true === $smilies->contains( ':)' );
false === $smilies->contains( 'simile' );
Parameters
$word
stringrequired- Determine if this word is a lookup key in the map.
$case_sensitivity
stringoptional- Pass
'ascii-case-insensitive'
to ignore ASCII case when matching. Default'case-sensitive'
.Default:
'case-sensitive'
Source
public function contains( string $word, string $case_sensitivity = 'case-sensitive' ): bool {
$ignore_case = 'ascii-case-insensitive' === $case_sensitivity;
if ( $this->key_length >= strlen( $word ) ) {
if ( 0 === strlen( $this->small_words ) ) {
return false;
}
$term = str_pad( $word, $this->key_length + 1, "\x00", STR_PAD_RIGHT );
$word_at = $ignore_case ? stripos( $this->small_words, $term ) : strpos( $this->small_words, $term );
if ( false === $word_at ) {
return false;
}
return true;
}
$group_key = substr( $word, 0, $this->key_length );
$group_at = $ignore_case ? stripos( $this->groups, $group_key ) : strpos( $this->groups, $group_key );
if ( false === $group_at ) {
return false;
}
$group = $this->large_words[ $group_at / ( $this->key_length + 1 ) ];
$group_length = strlen( $group );
$slug = substr( $word, $this->key_length );
$length = strlen( $slug );
$at = 0;
while ( $at < $group_length ) {
$token_length = unpack( 'C', $group[ $at++ ] )[1];
$token_at = $at;
$at += $token_length;
$mapping_length = unpack( 'C', $group[ $at++ ] )[1];
$mapping_at = $at;
if ( $token_length === $length && 0 === substr_compare( $group, $slug, $token_at, $token_length, $ignore_case ) ) {
return true;
}
$at = $mapping_at + $mapping_length;
}
return false;
}
Changelog
Version | Description |
---|---|
6.6.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.