From f96684271362daf6326a54ac3992e5d77ec33429 Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Thu, 28 Mar 2024 12:22:05 -0400 Subject: [PATCH] Editorial: Generalize ToZeroPaddedDecimalString to support hexadecimal output --- spec.html | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) diff --git a/spec.html b/spec.html index b272c6b8ab..f2825fdb2a 100644 --- a/spec.html +++ b/spec.html @@ -29232,8 +29232,7 @@

1. Set _k_ to _k_ + _cp_.[[CodeUnitCount]]. 1. Let _Octets_ be the List of octets resulting by applying the UTF-8 transformation to _cp_.[[CodePoint]]. 1. For each element _octet_ of _Octets_, do - 1. Let _hex_ be the String representation of _octet_, formatted as an uppercase hexadecimal number. - 1. Set _R_ to the string-concatenation of _R_, *"%"*, and StringPad(_hex_, 2, *"0"*, ~start~). + 1. Set _R_ to the string-concatenation of _R_, *"%"*, and ZeroPad(_octet_, 2, ~hex-upper~). 1. Return _R_. @@ -34026,9 +34025,9 @@

- 1. Let _hour_ be ToZeroPaddedDecimalString(ℝ(HourFromTime(_tv_)), 2). - 1. Let _minute_ be ToZeroPaddedDecimalString(ℝ(MinFromTime(_tv_)), 2). - 1. Let _second_ be ToZeroPaddedDecimalString(ℝ(SecFromTime(_tv_)), 2). + 1. Let _hour_ be ZeroPad(ℝ(HourFromTime(_tv_)), 2, ~decimal~). + 1. Let _minute_ be ZeroPad(ℝ(MinFromTime(_tv_)), 2, ~decimal~). + 1. Let _second_ be ZeroPad(ℝ(SecFromTime(_tv_)), 2, ~decimal~). 1. Return the string-concatenation of _hour_, *":"*, _minute_, *":"*, _second_, the code unit 0x0020 (SPACE), and *"GMT"*. @@ -34044,10 +34043,10 @@

1. Let _weekday_ be the Name of the entry in with the Number WeekDay(_tv_). 1. Let _month_ be the Name of the entry in with the Number MonthFromTime(_tv_). - 1. Let _day_ be ToZeroPaddedDecimalString(ℝ(DateFromTime(_tv_)), 2). + 1. Let _day_ be ZeroPad(ℝ(DateFromTime(_tv_)), 2, ~decimal~). 1. Let _yv_ be YearFromTime(_tv_). 1. If _yv_ is *+0*𝔽 or _yv_ > *+0*𝔽, let _yearSign_ be the empty String; otherwise, let _yearSign_ be *"-"*. - 1. Let _paddedYear_ be ToZeroPaddedDecimalString(abs(ℝ(_yv_)), 4). + 1. Let _paddedYear_ be ZeroPad(abs(ℝ(_yv_)), 4, ~decimal~). 1. Return the string-concatenation of _weekday_, the code unit 0x0020 (SPACE), _month_, the code unit 0x0020 (SPACE), _day_, the code unit 0x0020 (SPACE), _yearSign_, and _paddedYear_. @@ -34249,8 +34248,8 @@

1. Else, 1. Let _offsetSign_ be *"-"*. 1. Let _absOffset_ be -_offset_. - 1. Let _offsetMin_ be ToZeroPaddedDecimalString(ℝ(MinFromTime(_absOffset_)), 2). - 1. Let _offsetHour_ be ToZeroPaddedDecimalString(ℝ(HourFromTime(_absOffset_)), 2). + 1. Let _offsetMin_ be ZeroPad(ℝ(MinFromTime(_absOffset_)), 2, ~decimal~). + 1. Let _offsetHour_ be ZeroPad(ℝ(HourFromTime(_absOffset_)), 2, ~decimal~). 1. Let _tzName_ be an implementation-defined string that is either the empty String or the string-concatenation of the code unit 0x0020 (SPACE), the code unit 0x0028 (LEFT PARENTHESIS), an implementation-defined timezone name, and the code unit 0x0029 (RIGHT PARENTHESIS). 1. Return the string-concatenation of _offsetSign_, _offsetHour_, _offsetMin_, and _tzName_. @@ -34296,10 +34295,10 @@

Date.prototype.toUTCString ( )

1. If _tv_ is *NaN*, return *"Invalid Date"*. 1. Let _weekday_ be the Name of the entry in with the Number WeekDay(_tv_). 1. Let _month_ be the Name of the entry in with the Number MonthFromTime(_tv_). - 1. Let _day_ be ToZeroPaddedDecimalString(ℝ(DateFromTime(_tv_)), 2). + 1. Let _day_ be ZeroPad(ℝ(DateFromTime(_tv_)), 2, ~decimal~). 1. Let _yv_ be YearFromTime(_tv_). 1. If _yv_ is *+0*𝔽 or _yv_ > *+0*𝔽, let _yearSign_ be the empty String; otherwise, let _yearSign_ be *"-"*. - 1. Let _paddedYear_ be ToZeroPaddedDecimalString(abs(ℝ(_yv_)), 4). + 1. Let _paddedYear_ be ZeroPad(abs(ℝ(_yv_)), 4, ~decimal~). 1. Return the string-concatenation of _weekday_, *","*, the code unit 0x0020 (SPACE), _day_, the code unit 0x0020 (SPACE), _month_, the code unit 0x0020 (SPACE), _yearSign_, _paddedYear_, the code unit 0x0020 (SPACE), and TimeString(_tv_). @@ -34849,17 +34848,20 @@

- +

- ToZeroPaddedDecimalString ( + ZeroPad ( _n_: a non-negative integer, _minLength_: a non-negative integer, + _alphabet_: ~decimal~, ~hex-lower~, or ~hex-upper~, ): a String

- 1. Let _S_ be the String representation of _n_, formatted as a decimal number. + 1. If _alphabet_ is ~hex-lower~, let _S_ be the String representation of _n_, formatted as a lowercase hexadecimal number. + 1. Else if _alphabet_ is ~hex-upper~, let _S_ be the String representation of _n_, formatted as an uppercase hexadecimal number. + 1. Else, let _S_ be the String representation of _n_, formatted as a decimal number. 1. Return StringPad(_S_, _minLength_, *"0"*, ~start~).
@@ -45312,8 +45314,7 @@

1. Let _n_ be the numeric value of _C_. 1. Assert: _n_ ≤ 0xFFFF. - 1. Let _hex_ be the String representation of _n_, formatted as a lowercase hexadecimal number. - 1. Return the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), *"u"*, and StringPad(_hex_, 4, *"0"*, ~start~). + 1. Return the string-concatenation of the code unit 0x005C (REVERSE SOLIDUS), *"u"*, and ZeroPad(_n_, 4, ~hex-lower~). @@ -50108,11 +50109,9 @@

escape ( _string_ )

1. Else, 1. Let _n_ be the numeric value of _C_. 1. If _n_ < 256, then - 1. Let _hex_ be the String representation of _n_, formatted as an uppercase hexadecimal number. - 1. Let _S_ be the string-concatenation of *"%"* and StringPad(_hex_, 2, *"0"*, ~start~). + 1. Let _S_ be the string-concatenation of *"%"* and ZeroPad(_n_, 2, ~hex-upper~). 1. Else, - 1. Let _hex_ be the String representation of _n_, formatted as an uppercase hexadecimal number. - 1. Let _S_ be the string-concatenation of *"%u"* and StringPad(_hex_, 4, *"0"*, ~start~). + 1. Let _S_ be the string-concatenation of *"%u"* and ZeroPad(_n_, 4, ~hex-upper~). 1. Set _R_ to the string-concatenation of _R_ and _S_. 1. Set _k_ to _k_ + 1. 1. Return _R_.