Skip to content

Commit

Permalink
Fix up some todo-s
Browse files Browse the repository at this point in the history
  • Loading branch information
sirreal committed Dec 11, 2024
1 parent da79b23 commit e193621
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ class WP_CSS_Complex_Selector_List extends WP_CSS_Compound_Selector_List {
* @return static|null The selector instance, or null if the parse was unsuccessful.
*/
public static function parse( string $input, int &$offset ): ?static {
$input = self::normalize_selector_input( $input );

if ( '' === $input ) {
return null;
}

$offset = 0;

$selector = WP_CSS_Complex_Selector::parse( $input, $offset );
if ( null === $selector ) {
return null;
Expand Down
14 changes: 6 additions & 8 deletions src/wp-includes/html-api/class-wp-css-compound-selector-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ protected function __construct( array $selectors ) {
* @return static|null
*/
public static function from_selectors( string $input ): ?static {
$input = self::normalize_selector_input( $input );

if ( '' === $input ) {
return null;
}

$offset = 0;
return static::parse( $input, $offset );
}
Expand All @@ -137,14 +143,6 @@ public static function from_selectors( string $input ): ?static {
* @return static|null The selector instance, or null if the parse was unsuccessful.
*/
public static function parse( string $input, int &$offset ): ?static {
$input = self::normalize_selector_input( $input );

if ( '' === $input ) {
return null;
}

$offset = 0;

$selector = WP_CSS_Compound_Selector::parse( $input, $offset );
if ( null === $selector ) {
return null;
Expand Down
19 changes: 14 additions & 5 deletions src/wp-includes/html-api/class-wp-css-selector-parser-matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,12 @@ abstract public static function parse( string $input, int &$offset ): ?static;
*/

/**
* @todo document
* Consumes whitespace from the input string.
*
* @param string $input The selector string.
* @param int $offset The offset into the string. The offset is passed by reference and will
* be update to the byte after the whitespace sequence.
* @return bool True if whitespace was consumed.
*/
final protected static function parse_whitespace( string $input, int &$offset ): bool {
$length = strspn( $input, self::WHITESPACE_CHARACTERS, $offset );
Expand Down Expand Up @@ -289,7 +294,6 @@ final protected static function parse_ident( string $input, int &$offset ): ?str
$ident .= self::consume_escaped_codepoint( $input, $offset );
continue;
} elseif ( self::is_ident_codepoint( $input, $offset ) ) {
// @todo this should append and advance the correct number of bytes.
$ident .= $input[ $offset ];
++$offset;
continue;
Expand Down Expand Up @@ -338,7 +342,7 @@ final protected static function next_two_are_valid_escape( string $input, int $o
}

/**
* Checks if the next code point is an "ident start code point".
* Checks if the next code point is an "ident start code point."
*
* Caution! This method does not do any bounds checking, it should not be passed
* a string with an offset that is out of bounds.
Expand Down Expand Up @@ -370,7 +374,7 @@ final protected static function is_ident_start_codepoint( string $input, int $of
}

/**
* Checks if the next code point is an "ident code point".
* Checks if the next code point is an "ident code point."
*
* Caution! This method does not do any bounds checking, it should not be passed
* a string with an offset that is out of bounds.
Expand Down Expand Up @@ -461,7 +465,12 @@ final protected static function check_if_three_code_points_would_start_an_ident_
}

/**
* @todo doc…
* Normalizes selector input for processing.
*
* @see https://www.w3.org/TR/css-syntax-3/#input-preprocessing
*
* @param string $input The selector string.
* @return string The normalized selector string.
*/
final protected static function normalize_selector_input( string $input ): string {
/*
Expand Down

0 comments on commit e193621

Please sign in to comment.