Skip to content

Commit

Permalink
[e] (0) Rewrite this algorithm to make Philip` happier (and be more c…
Browse files Browse the repository at this point in the history
…onsistent with the other algorithms.)

Fixing http://www.w3.org/Bugs/Public/show_bug.cgi?id=8015

git-svn-id: http://svn.whatwg.org/webapps@4310 340c8d12-0b0e-0410-8428-c7bf67bfef74
  • Loading branch information
Hixie committed Oct 24, 2009
1 parent e481116 commit f4c4c8c
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 183 deletions.
106 changes: 48 additions & 58 deletions complete.html
Expand Up @@ -3072,59 +3072,51 @@ <h5 id=ratios><span class=secno>2.4.4.4 </span>Ratios</h5>
<p>The <dfn id=steps-for-finding-one-or-two-numbers-of-a-ratio-in-a-string>steps for finding one or two numbers of a ratio in a
string</dfn> are as follows:</p>

<ol><li>If the string is empty, then return nothing and abort these
steps.</li>

<li><a href=#find-a-number>Find a number</a> in the string according to the
algorithm below, starting at the start of the string.</li>
<ol><li><p>Let <var title="">input</var> be the string being
parsed.</li>

<li>If the sub-algorithm in step 2 returned nothing or returned an
error condition, return nothing and abort these steps.</li>
<li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>, initially pointing at the start of the
string.</li>

<li>Set <var title="">number1</var> to the number returned by the
sub-algorithm in step 2.</li>
<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, then return nothing and abort these
steps.</li>

<li>Starting with the character immediately after the last one
collected by the sub-algorithm in step 2, skip all
<a href=#white_space>White_Space</a> characters in the string (this might match
zero characters).</li>
<li><p><a href=#find-a-number>Find a number</a> in the string according to the
algorithm below. If this returns a number, let <var title="">number1</var> be that number. Otherwise, if it returned
nothing or returned an error condition, return nothing and abort
these steps.</li>

<li>If there are still further characters in the string, and the
next character in the string is a <a href=#valid-denominator-punctuation-character>valid denominator
punctuation character</a>, set <var title="">denominator</var>
to that character.</li>
<li><p><a href=#skip-white_space-characters>Skip White_Space characters</a>.</li>

<li>If the string contains any other characters in the range U+0030
DIGIT ZERO (0) to U+0039 DIGIT NINE (9), but <var title="">denominator</var> was given a value in the step 6, return
<li><p>If the character indicated by <var title="">position</var>
(if any) is a <a href=#valid-denominator-punctuation-character>valid denominator punctuation character</a>,
let <var title="">denominator</var> be that character. Otherwise,
<var title="">denominator</var> has no value.</li>

<li><p>If there are any characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9) in <var title="">input</var> at or
after the character indicated by <var title="">position</var> (if
any), but <var title="">denominator</var> has a value, return
nothing and abort these steps.</li>

<li>Otherwise, if <var title="">denominator</var> was given a value
in step 6, return <var title="">number1</var> and <var title="">denominator</var> and abort these steps.</li>
<li><p>Otherwise, if <var title="">denominator</var> has value,
return <var title="">number1</var> and <var title="">denominator</var> and abort these steps.</li>

<li><a href=#find-a-number>Find a number</a> in the string again, starting
immediately after the last character that was collected by the
sub-algorithm in step 2.</li>
<li><p><a href=#find-a-number>Find a number</a> in the string again. If this
returns a number, let <var title="">number2</var> be that
number. Otherwise, if it returned nothing or an error condition,
return <var title="">number1</var> and abort these steps.</li>

<li>If the sub-algorithm in step 9 returned nothing or an error
condition, return <var title="">number1</var> and abort these
steps.</li>

<li>Set <var title="">number2</var> to the number returned by the
sub-algorithm in step 9.</li>
<li><p><a href=#skip-white_space-characters>Skip White_Space characters</a>.</li>

<li>Starting with the character immediately after the last one
collected by the sub-algorithm in step 9, skip all
<a href=#white_space>White_Space</a> characters in the string (this might match
zero characters).</li>

<li>If there are still further characters in the string, and the
next character in the string is a <a href=#valid-denominator-punctuation-character>valid denominator
punctuation character</a>, return nothing and abort these
steps.</li>
<li><p>If the character indicated by <var title="">position</var>
(if any) is a <a href=#valid-denominator-punctuation-character>valid denominator punctuation character</a>,
return nothing and abort these steps.</li>

<li>If the string contains any other characters in the range U+0030
DIGIT ZERO (0) to U+0039 DIGIT NINE (9), return nothing and abort
these steps.</li>
<li><p>If there are any characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9) in <var title="">input</var> at or
after the character indicated by <var title="">position</var> (if
any), return nothing and abort these steps.</li>

<li>Otherwise, return <var title="">number1</var> and
<var title="">number2</var>.</li>
Expand All @@ -3133,27 +3125,25 @@ <h5 id=ratios><span class=secno>2.4.4.4 </span>Ratios</h5>
given a string and a starting position, and returns either nothing,
a number, or an error condition.</p>

<ol><li>Starting at the given starting position, ignore all characters
in the given string until the first character that is either a
U+002E FULL STOP or one of the ten characters in the range U+0030
DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</li>
<ol><li><p><a href=#collect-a-sequence-of-characters>Collect a sequence of characters</a> that are not
U+002E FULL STOP characters (.) and are not characters in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</li>

<li>If there are no such characters, return nothing and abort these
<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, then return nothing and abort these
steps.</li>

<li>Starting with the character matched in step 1, collect all the
consecutive characters that are either a U+002E FULL STOP or one of
the ten characters in the range U+0030 DIGIT ZERO (0) to U+0039
DIGIT NINE (9), and assign this string of one or more characters to
<var title="">string</var>.</li>
<li><p><a href=#collect-a-sequence-of-characters>Collect a sequence of characters</a> that are
either U+002E FULL STOP characters (.) or characters in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), and let that be
<var title="">s</var>.</li>

<li>If the first character or the last character of <var title="">string</var> is a U+002E FULL STOP character, or if <var title="">string</var> contains more than one U+002E FULL STOP
character, then return an error condition and abort these
steps.</li>
<li><p>If the first character or the last character of <var title="">s</var> is a U+002E FULL STOP character (.), or if <var title="">s</var> contains more than one U+002E FULL STOP character
(.), then return an error condition and abort these steps.</li>

<li>Parse <var title="">string</var> according to the <a href=#rules-for-parsing-floating-point-number-values>rules
for parsing floating point number values</a>, to obtain <var title="">number</var>. This step cannot fail (<var title="">string</var> is guaranteed to be a <a href=#valid-floating-point-number>valid floating
point number</a>).</li>
<li><p>Parse <var title="">s</var> according to the <a href=#rules-for-parsing-floating-point-number-values>rules for
parsing floating point number values</a>, to obtain <var title="">number</var>. This step cannot fail (<var title="">s</var>
is guaranteed to be a <a href=#valid-floating-point-number>valid floating point
number</a>).</li>

<li>Return <var title="">number</var>.</li>

Expand Down
106 changes: 48 additions & 58 deletions index
Expand Up @@ -2882,59 +2882,51 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
<p>The <dfn id=steps-for-finding-one-or-two-numbers-of-a-ratio-in-a-string>steps for finding one or two numbers of a ratio in a
string</dfn> are as follows:</p>

<ol><li>If the string is empty, then return nothing and abort these
steps.</li>

<li><a href=#find-a-number>Find a number</a> in the string according to the
algorithm below, starting at the start of the string.</li>
<ol><li><p>Let <var title="">input</var> be the string being
parsed.</li>

<li>If the sub-algorithm in step 2 returned nothing or returned an
error condition, return nothing and abort these steps.</li>
<li><p>Let <var title="">position</var> be a pointer into <var title="">input</var>, initially pointing at the start of the
string.</li>

<li>Set <var title="">number1</var> to the number returned by the
sub-algorithm in step 2.</li>
<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, then return nothing and abort these
steps.</li>

<li>Starting with the character immediately after the last one
collected by the sub-algorithm in step 2, skip all
<a href=#white_space>White_Space</a> characters in the string (this might match
zero characters).</li>
<li><p><a href=#find-a-number>Find a number</a> in the string according to the
algorithm below. If this returns a number, let <var title="">number1</var> be that number. Otherwise, if it returned
nothing or returned an error condition, return nothing and abort
these steps.</li>

<li>If there are still further characters in the string, and the
next character in the string is a <a href=#valid-denominator-punctuation-character>valid denominator
punctuation character</a>, set <var title="">denominator</var>
to that character.</li>
<li><p><a href=#skip-white_space-characters>Skip White_Space characters</a>.</li>

<li>If the string contains any other characters in the range U+0030
DIGIT ZERO (0) to U+0039 DIGIT NINE (9), but <var title="">denominator</var> was given a value in the step 6, return
<li><p>If the character indicated by <var title="">position</var>
(if any) is a <a href=#valid-denominator-punctuation-character>valid denominator punctuation character</a>,
let <var title="">denominator</var> be that character. Otherwise,
<var title="">denominator</var> has no value.</li>

<li><p>If there are any characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9) in <var title="">input</var> at or
after the character indicated by <var title="">position</var> (if
any), but <var title="">denominator</var> has a value, return
nothing and abort these steps.</li>

<li>Otherwise, if <var title="">denominator</var> was given a value
in step 6, return <var title="">number1</var> and <var title="">denominator</var> and abort these steps.</li>
<li><p>Otherwise, if <var title="">denominator</var> has value,
return <var title="">number1</var> and <var title="">denominator</var> and abort these steps.</li>

<li><a href=#find-a-number>Find a number</a> in the string again, starting
immediately after the last character that was collected by the
sub-algorithm in step 2.</li>
<li><p><a href=#find-a-number>Find a number</a> in the string again. If this
returns a number, let <var title="">number2</var> be that
number. Otherwise, if it returned nothing or an error condition,
return <var title="">number1</var> and abort these steps.</li>

<li>If the sub-algorithm in step 9 returned nothing or an error
condition, return <var title="">number1</var> and abort these
steps.</li>

<li>Set <var title="">number2</var> to the number returned by the
sub-algorithm in step 9.</li>
<li><p><a href=#skip-white_space-characters>Skip White_Space characters</a>.</li>

<li>Starting with the character immediately after the last one
collected by the sub-algorithm in step 9, skip all
<a href=#white_space>White_Space</a> characters in the string (this might match
zero characters).</li>

<li>If there are still further characters in the string, and the
next character in the string is a <a href=#valid-denominator-punctuation-character>valid denominator
punctuation character</a>, return nothing and abort these
steps.</li>
<li><p>If the character indicated by <var title="">position</var>
(if any) is a <a href=#valid-denominator-punctuation-character>valid denominator punctuation character</a>,
return nothing and abort these steps.</li>

<li>If the string contains any other characters in the range U+0030
DIGIT ZERO (0) to U+0039 DIGIT NINE (9), return nothing and abort
these steps.</li>
<li><p>If there are any characters in the range U+0030 DIGIT ZERO
(0) to U+0039 DIGIT NINE (9) in <var title="">input</var> at or
after the character indicated by <var title="">position</var> (if
any), return nothing and abort these steps.</li>

<li>Otherwise, return <var title="">number1</var> and
<var title="">number2</var>.</li>
Expand All @@ -2943,27 +2935,25 @@ a.setAttribute('href', 'http://example.com/'); // change the content attribute d
given a string and a starting position, and returns either nothing,
a number, or an error condition.</p>

<ol><li>Starting at the given starting position, ignore all characters
in the given string until the first character that is either a
U+002E FULL STOP or one of the ten characters in the range U+0030
DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</li>
<ol><li><p><a href=#collect-a-sequence-of-characters>Collect a sequence of characters</a> that are not
U+002E FULL STOP characters (.) and are not characters in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9).</li>

<li>If there are no such characters, return nothing and abort these
<li><p>If <var title="">position</var> is past the end of <var title="">input</var>, then return nothing and abort these
steps.</li>

<li>Starting with the character matched in step 1, collect all the
consecutive characters that are either a U+002E FULL STOP or one of
the ten characters in the range U+0030 DIGIT ZERO (0) to U+0039
DIGIT NINE (9), and assign this string of one or more characters to
<var title="">string</var>.</li>
<li><p><a href=#collect-a-sequence-of-characters>Collect a sequence of characters</a> that are
either U+002E FULL STOP characters (.) or characters in the range
U+0030 DIGIT ZERO (0) to U+0039 DIGIT NINE (9), and let that be
<var title="">s</var>.</li>

<li>If the first character or the last character of <var title="">string</var> is a U+002E FULL STOP character, or if <var title="">string</var> contains more than one U+002E FULL STOP
character, then return an error condition and abort these
steps.</li>
<li><p>If the first character or the last character of <var title="">s</var> is a U+002E FULL STOP character (.), or if <var title="">s</var> contains more than one U+002E FULL STOP character
(.), then return an error condition and abort these steps.</li>

<li>Parse <var title="">string</var> according to the <a href=#rules-for-parsing-floating-point-number-values>rules
for parsing floating point number values</a>, to obtain <var title="">number</var>. This step cannot fail (<var title="">string</var> is guaranteed to be a <a href=#valid-floating-point-number>valid floating
point number</a>).</li>
<li><p>Parse <var title="">s</var> according to the <a href=#rules-for-parsing-floating-point-number-values>rules for
parsing floating point number values</a>, to obtain <var title="">number</var>. This step cannot fail (<var title="">s</var>
is guaranteed to be a <a href=#valid-floating-point-number>valid floating point
number</a>).</li>

<li>Return <var title="">number</var>.</li>

Expand Down

0 comments on commit f4c4c8c

Please sign in to comment.