Skip to content

Commit 3f1f116

Browse files
committed
[css-counter-styles-3] Rewrite the additive representation algo. This is partially for style, but also properly handles the case where you hit a 0-weight symbol when there's still value left. Fixes w3c#5784.
1 parent 49d6092 commit 3f1f116

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

css-counter-styles-3/Overview.bs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -632,33 +632,33 @@ Accumulating Numerals: the ''additive'' system</h4>
632632
</pre>
633633
</div>
634634

635-
To construct the representation, run this algorithm:
635+
<div algorithm="additive representation">
636+
To construct the representation:
636637

638+
1. Let |value| initially be the counter value,
639+
|S| initially be the empty string,
640+
and |symbol list| initially be the list of <a>additive tuples</a>.
637641

638-
Let <var>value</var> initially be the counter value,
639-
<var>S</var> initially be the empty string,
640-
and <var>symbol list</var> initially be the list of <a>additive tuples</a>.
642+
2. If |value| is 0, and there is an <a>additive tuple</a> with a weight of 0, append that tuple's <a>counter symbol</a> to |S| and return |S|.
641643

642-
<ol>
643-
<li>If <var>value</var> is initially 0, and there is an <a>additive tuple</a> with a weight of 0, append that tuple's <a>counter symbol</a> to S and return S.
644+
3. For each |tuple| in |symbol list|:
644645

645-
<li>While <var>value</var> is greater than 0 and there are elements left in the <var>symbol list</var>:
646+
1. Let |symbol| and |weight| be |tuple|'s [=counter symbol=] and weight, respectively.
646647

647-
<ol>
648-
<li>Pop the first <a>additive tuple</a> from the <var>symbol list</var>.
649-
This is the <dfn>current tuple</dfn>.
648+
2. If |weight| is zero, or |weight| is greater than |value|,
649+
[=iteration/continue=].
650650

651-
<li>Append the <a>current tuple</a>’s <a>counter symbol</a> to <var>S</var>
652-
<code>floor( <var>value</var> / <var><a>current tuple</a>’s weight</var> )</code>
653-
times (this may be 0).
651+
3. Let |reps| be <code>floor( |value| / |weight| )</code>.
654652

655-
<li>Decrement <var>value</var> by the <var><a>current tuple</a>’s weight</var> multiplied
656-
by the number of times the <a>current tuple</a> was appended to <var>S</var>
657-
in the previous step.
658-
</ol>
653+
4. Append |symbol| to |S| |reps| times.
659654

660-
<li>If the loop ended because <var>value</var> is 0, return S. Otherwise, the given counter value cannot be represented by this counter style, and must instead be represented by the fallback counter style.
661-
</ol>
655+
5. Decrement |value| by <code>|weight| * |reps|</code>.
656+
If |value| is now zero, return |S|.
657+
658+
4. Assertion: |value| is still non-zero.
659+
660+
The given counter value cannot be represented by this counter style, and must instead be represented by the fallback counter style.
661+
</div>
662662

663663
Note: All of the predefined additive ''@counter-style'' rules in this specification
664664
produce representations for every value in their range,

0 commit comments

Comments
 (0)