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-text-replacement.php

    r55734 r57179  
    1616 * @access private
    1717 * @since 6.2.0
     18 * @since 6.5.0 Replace `end` with `length` to more closely match `substr()`.
    1819 *
    1920 * @see WP_HTML_Tag_Processor
     
    2425     *
    2526     * @since 6.2.0
     27     *
    2628     * @var int
    2729     */
     
    2931
    3032    /**
    31      * Byte offset into document where replacement span ends.
     33     * Byte length of span being replaced.
    3234     *
    33      * @since 6.2.0
     35     * @since 6.5.0
     36     *
    3437     * @var int
    3538     */
    36     public $end;
     39    public $length;
    3740
    3841    /**
     
    4043     *
    4144     * @since 6.2.0
     45     *
    4246     * @var string
    4347     */
     
    4953     * @since 6.2.0
    5054     *
    51      * @param int    $start Byte offset into document where replacement span begins.
    52      * @param int    $end   Byte offset into document where replacement span ends.
    53      * @param string $text  Span of text to insert in document to replace existing content from start to end.
     55     * @param int    $start  Byte offset into document where replacement span begins.
     56     * @param int    $length Byte length of span in document being replaced.
     57     * @param string $text   Span of text to insert in document to replace existing content from start to end.
    5458     */
    55     public function __construct( $start, $end, $text ) {
    56         $this->start = $start;
    57         $this->end   = $end;
    58         $this->text  = $text;
     59    public function __construct( $start, $length, $text ) {
     60        $this->start  = $start;
     61        $this->length = $length;
     62        $this->text   = $text;
    5963    }
    6064}
Note: See TracChangeset for help on using the changeset viewer.