Finds a match for a short word at the index.
Parameters
$text
stringrequired- String in which to search for a lookup key.
$offset
intoptional- How many bytes into the string where the lookup key ought to start. Default 0.
- &$matched_token_byte_length Optional. Holds byte-length of found lookup key if matched, otherwise not set. Default null.
$case_sensitivity
stringoptional- Pass
'ascii-case-insensitive'
to ignore ASCII case when matching. Default'case-sensitive'
.Default:
'case-sensitive'
Source
* @return string|null Mapped value of lookup key if found, otherwise `null`.
*/
private function read_small_token( string $text, int $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ): ?string {
$ignore_case = 'ascii-case-insensitive' === $case_sensitivity;
$small_length = strlen( $this->small_words );
$search_text = substr( $text, $offset, $this->key_length );
if ( $ignore_case ) {
$search_text = strtoupper( $search_text );
}
$starting_char = $search_text[0];
$at = 0;
while ( $at < $small_length ) {
if (
$starting_char !== $this->small_words[ $at ] &&
( ! $ignore_case || strtoupper( $this->small_words[ $at ] ) !== $starting_char )
) {
$at += $this->key_length + 1;
continue;
}
for ( $adjust = 1; $adjust < $this->key_length; $adjust++ ) {
if ( "\x00" === $this->small_words[ $at + $adjust ] ) {
$matched_token_byte_length = $adjust;
return $this->small_mappings[ $at / ( $this->key_length + 1 ) ];
}
if (
$search_text[ $adjust ] !== $this->small_words[ $at + $adjust ] &&
( ! $ignore_case || strtoupper( $this->small_words[ $at + $adjust ] !== $search_text[ $adjust ] ) )
) {
$at += $this->key_length + 1;
continue 2;
}
}
$matched_token_byte_length = $adjust;
return $this->small_mappings[ $at / ( $this->key_length + 1 ) ];
}
User Contributed Notes
You must log in before being able to contribute a note or feedback.