Make WordPress Core


Ignore:
Timestamp:
12/10/2023 01:17:29 PM (2 years ago)
Author:
zieladam
Message:

HTML API: Track spans of text with (offset, length) instead of (start, end).

Updates the internal representation of the text span coordinates. The mixture of (offset, length) and (start, end) coordinates becomes confusing, this commit replaces it with a (offset, length) pair. There should be no functional or behavioral changes in this patch. For the internal helper classes this patch introduces breaking changes, but those classes are marked private and should not be used outside of the HTML API itself.

Props dmsnell.
Fixes #59993.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/html-api/class-wp-html-attribute-token.php

    r55734 r57179  
    1616 * @access private
    1717 * @since 6.2.0
     18 * @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
    1819 *
    1920 * @see WP_HTML_Tag_Processor
     
    2425     *
    2526     * @since 6.2.0
     27     *
    2628     * @var string
    2729     */
     
    3234     *
    3335     * @since 6.2.0
     36     *
    3437     * @var int
    3538     */
     
    4043     *
    4144     * @since 6.2.0
     45     *
    4246     * @var int
    4347     */
     
    4852     *
    4953     * @since 6.2.0
     54     *
    5055     * @var int
    5156     */
     
    5358
    5459    /**
    55      * The string offset after the attribute value or its name.
     60     * Byte length of text spanning the attribute inside a tag.
    5661     *
    57      * @since 6.2.0
     62     * This span starts at the first character of the attribute name
     63     * and it ends after one of three cases:
     64     *
     65     *  - at the end of the attribute name for boolean attributes.
     66     *  - at the end of the value for unquoted attributes.
     67     *  - at the final single or double quote for quoted attributes.
     68     *
     69     * Example:
     70     *
     71     *     <div class="post">
     72     *          ------------ length is 12, including quotes
     73     *
     74     *     <input type="checked" checked id="selector">
     75     *                           ------- length is 6
     76     *
     77     *     <a rel=noopener>
     78     *        ------------ length is 11
     79     *
     80     * @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
     81     *
    5882     * @var int
    5983     */
    60     public $end;
     84    public $length;
    6185
    6286    /**
     
    6488     *
    6589     * @since 6.2.0
     90     *
    6691     * @var bool
    6792     */
     
    7297     *
    7398     * @since 6.2.0
     99     * @since 6.5.0 Replaced `end` with `length` to more closely match `substr()`.
    74100     *
    75101     * @param string $name         Attribute name.
     
    77103     * @param int    $value_length Number of bytes attribute value spans.
    78104     * @param int    $start        The string offset where the attribute name starts.
    79      * @param int    $end          The string offset after the attribute value or its name.
     105     * @param int    $length       Byte length of the entire attribute name or name and value pair expression.
    80106     * @param bool   $is_true      Whether the attribute is a boolean attribute with true value.
    81107     */
    82     public function __construct( $name, $value_start, $value_length, $start, $end, $is_true ) {
     108    public function __construct( $name, $value_start, $value_length, $start, $length, $is_true ) {
    83109        $this->name            = $name;
    84110        $this->value_starts_at = $value_start;
    85111        $this->value_length    = $value_length;
    86112        $this->start           = $start;
    87         $this->end             = $end;
     113        $this->length          = $length;
    88114        $this->is_true         = $is_true;
    89115    }
Note: See TracChangeset for help on using the changeset viewer.