You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[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. Fixesw3c#5784.
Copy file name to clipboardExpand all lines: css-counter-styles-3/Overview.bs
+19-19Lines changed: 19 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -632,33 +632,33 @@ Accumulating Numerals: the ''additive'' system</h4>
632
632
</pre>
633
633
</div>
634
634
635
-
To construct the representation, run this algorithm:
635
+
<div algorithm="additive representation">
636
+
To construct the representation:
636
637
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>.
637
641
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|.
641
643
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|:
644
645
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.
646
647
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=].
650
650
651
-
<li>Append the <a>current tuple</a>’s <a>counter symbol</a> to <var>S</var>
3. Let |reps| be <code>floor( |value| / |weight| )</code>.
654
652
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.
659
654
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>
662
662
663
663
Note: All of the predefined additive ''@counter-style'' rules in this specification
664
664
produce representations for every value in their range,
0 commit comments