Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML API: Add custom text decoder #6387

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3ff78cc
HTML API: Add custom text decoder.
dmsnell Apr 24, 2024
401d30f
Correct typo in max digit computation.
dmsnell May 15, 2024
4f5f21e
Adjust docs, names.
dmsnell May 24, 2024
72aeccd
Updates to attribute_starts_with
dmsnell May 25, 2024
d60e320
Add tests for attribute_starts_with
dmsnell May 28, 2024
db384b9
Fix alignment lint
sirreal May 28, 2024
be8b2a5
Annotate global variable type
sirreal May 28, 2024
8f9b076
Change read_character_reference return type to string|false
sirreal May 28, 2024
2d3dee1
Merge remote-tracking branch 'upstream/trunk' into html-api/add-text-…
sirreal May 28, 2024
b559320
Replace &colon entity test with ∷
sirreal May 28, 2024
53dafce
Remove ∷ test (this means "∷"!)
sirreal May 28, 2024
3bf0434
Add WIP test for edge cases.
dmsnell May 28, 2024
edbc0b0
Fix type error in text decoder
dmsnell May 28, 2024
fd83c46
Replace false with null for token reading.
dmsnell May 29, 2024
59671d6
Update tests for Token Map returning null.
dmsnell May 29, 2024
ab672e7
Fill in test phpdoc details
sirreal May 29, 2024
2e2fb8b
Update optional $case_sensitivity param types
sirreal May 29, 2024
d38df36
Fix optional @param types
sirreal May 29, 2024
9931e09
Use default argument for read_character_reference at
sirreal May 29, 2024
95820aa
Add additional attribute prefix tests
sirreal May 29, 2024
47dcdc1
Change byte_length_of_matched_token to matched_token_byte_length
sirreal May 29, 2024
0c0b36c
Docblock cleanup
dmsnell May 31, 2024
f594b87
Merge remote-tracking branch 'upstream/trunk' into html-api/add-text-…
dmsnell Jun 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/wp-includes/class-wp-token-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,8 +435,8 @@ public static function from_precomputed_table( $state ) {
*
* @since 6.6.0
*
* @param string $word Determine if this word is a lookup key in the map.
* @param ?string $case_sensitivity 'ascii-case-insensitive' to ignore ASCII case or default of 'case-sensitive'.
* @param string $word Determine if this word is a lookup key in the map.
* @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'.
* @return bool Whether there's an entry for the given word in the map.
*/
public function contains( $word, $case_sensitivity = 'case-sensitive' ) {
Expand Down Expand Up @@ -521,10 +521,10 @@ public function contains( $word, $case_sensitivity = 'case-sensitive' ) {
* @since 6.6.0
*
* @param string $text String in which to search for a lookup key.
* @param ?int $offset How many bytes into the string where the lookup key ought to start.
* @param ?int &$matched_token_byte_length Holds byte-length of found token matched, otherwise not set.
* @param ?string $case_sensitivity 'ascii-case-insensitive' to ignore ASCII case or default of 'case-sensitive'.
* @return string|false Mapped value of lookup key if found, otherwise `false`.
* @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0.
* @param ?int &$matched_token_byte_length Optional. Holds byte-length of found token matched, otherwise not set. Default null.
* @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'.
* @return string|null Mapped value of lookup key if found, otherwise `null`.
*/
public function read_token( $text, $offset = 0, &$matched_token_byte_length = null, $case_sensitivity = 'case-sensitive' ) {
$ignore_case = 'ascii-case-insensitive' === $case_sensitivity;
Expand All @@ -539,7 +539,7 @@ public function read_token( $text, $offset = 0, &$matched_token_byte_length = nu
// Perhaps a short word then.
return strlen( $this->small_words ) > 0
? $this->read_small_token( $text, $offset, $matched_token_byte_length, $case_sensitivity )
: false;
: null;
}

$group = $this->large_words[ $group_at / ( $this->key_length + 1 ) ];
Expand All @@ -564,19 +564,19 @@ public function read_token( $text, $offset = 0, &$matched_token_byte_length = nu
// Perhaps a short word then.
return strlen( $this->small_words ) > 0
? $this->read_small_token( $text, $offset, $matched_token_byte_length, $case_sensitivity )
: false;
: null;
}

/**
* Finds a match for a short word at the index.
*
* @since 6.6.0.
*
* @param string $text String in which to search for a lookup key.
* @param ?int $offset How many bytes into the string where the lookup key ought to start.
* @param ?int &$matched_token_byte_length Holds byte-length of found lookup key if matched, otherwise not set.
* @param ?string $case_sensitivity 'ascii-case-insensitive' to ignore ASCII case or default of 'case-sensitive'.
* @return string|false Mapped value of lookup key if found, otherwise `false`.
* @param string $text String in which to search for a lookup key.
* @param int $offset Optional. How many bytes into the string where the lookup key ought to start. Default 0.
* @param ?int &$matched_token_byte_length Optional. Holds byte-length of found lookup key if matched, otherwise not set. Default null.
* @param string $case_sensitivity Optional. Pass 'ascii-case-insensitive' to ignore ASCII case when matching. Default 'case-sensitive'.
* @return string|null Mapped value of lookup key if found, otherwise `null`.
*/
private function read_small_token( $text, $offset, &$matched_token_byte_length, $case_sensitivity = 'case-sensitive' ) {
$ignore_case = 'ascii-case-insensitive' === $case_sensitivity;
Expand Down Expand Up @@ -616,7 +616,7 @@ private function read_small_token( $text, $offset, &$matched_token_byte_length,
return $this->small_mappings[ $at / ( $this->key_length + 1 ) ];
}

return false;
return null;
}

/**
Expand Down Expand Up @@ -692,7 +692,7 @@ public function to_array() {
*
* @since 6.6.0
*
* @param ?string $indent Use this string for indentation, or rely on the default horizontal tab character.
* @param string $indent Optional. Use this string for indentation, or rely on the default horizontal tab character. Default "\t".
* @return string Value which can be pasted into a PHP source file for quick loading of table.
*/
public function precomputed_php_source_table( $indent = "\t" ) {
Expand Down
Loading
Loading