Commit 279e43d
committed
HTML API: Track spans of text with (offset, length) instead of (start, end)
This patch follows-up with earlier design questions around how to represent
spans of strings inside the class. It's relevant now as preparation for #5683.
The mixture of (offset, length) and (start, end) coordinates becomes confusing
at times and all final string operations are performed with the (offset, length)
pair, since these feed into `strlen()`.
In preparation for exposing all tokens within an HTML document this change:
- Unifies the representation throughout the class.
- It creates `token_starts_at` to track the start of the current token.
- It replaces `tag_ends_at` with `token_length` for re-use with other token types.
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.1 parent 1850589 commit 279e43d
File tree
4 files changed
+130
-67
lines changed- src/wp-includes/html-api
4 files changed
+130
-67
lines changedLines changed: 32 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
| |||
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
| 36 | + | |
34 | 37 | | |
35 | 38 | | |
36 | 39 | | |
| |||
39 | 42 | | |
40 | 43 | | |
41 | 44 | | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| |||
47 | 51 | | |
48 | 52 | | |
49 | 53 | | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
53 | 58 | | |
54 | 59 | | |
55 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
56 | 81 | | |
57 | | - | |
58 | 82 | | |
59 | 83 | | |
60 | | - | |
| 84 | + | |
61 | 85 | | |
62 | 86 | | |
63 | 87 | | |
64 | 88 | | |
65 | 89 | | |
| 90 | + | |
66 | 91 | | |
67 | 92 | | |
68 | 93 | | |
| |||
71 | 96 | | |
72 | 97 | | |
73 | 98 | | |
| 99 | + | |
74 | 100 | | |
75 | 101 | | |
76 | 102 | | |
77 | 103 | | |
78 | 104 | | |
79 | | - | |
| 105 | + | |
80 | 106 | | |
81 | 107 | | |
82 | | - | |
| 108 | + | |
83 | 109 | | |
84 | 110 | | |
85 | 111 | | |
86 | 112 | | |
87 | | - | |
| 113 | + | |
88 | 114 | | |
89 | 115 | | |
90 | 116 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
33 | 35 | | |
34 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | | - | |
37 | 40 | | |
38 | 41 | | |
39 | | - | |
| 42 | + | |
40 | 43 | | |
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
44 | 47 | | |
45 | 48 | | |
46 | | - | |
47 | | - | |
| 49 | + | |
| 50 | + | |
48 | 51 | | |
49 | | - | |
50 | | - | |
51 | | - | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
0 commit comments