diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2016-02-25 17:17:20 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2016-02-25 17:17:20 -0800 |
commit | dcc060c7d4ef56b978beb34ddce8d8ffcec94fa6 (patch) | |
tree | 7cbb9cd1d8544c7c6c65725fa195ca3821b04b07 /html/015literal_noninteger.cc.html | |
parent | 0f5a2f4e21046e319ce0fadec32cc5e89d2f4620 (diff) | |
download | mu-dcc060c7d4ef56b978beb34ddce8d8ffcec94fa6.tar.gz |
2706 - update html
Diffstat (limited to 'html/015literal_noninteger.cc.html')
-rw-r--r-- | html/015literal_noninteger.cc.html | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/html/015literal_noninteger.cc.html b/html/015literal_noninteger.cc.html index 4c0f8852..89a405df 100644 --- a/html/015literal_noninteger.cc.html +++ b/html/015literal_noninteger.cc.html @@ -38,22 +38,22 @@ body { font-family: monospace; color: #eeeeee; background-color: #080808; } recipe main [ <span class="Constant">1</span>:number<span class="Special"> <- </span>copy <span class="Constant">3.14159</span> ] -<span class="traceContains">+parse: ingredient: {"3.14159": "literal-number"}</span> +<span class="traceContains">+parse: ingredient: 3.14159: "literal-fractional-number"</span> <span class="Delimiter">:(after "Parsing reagent(string s)")</span> if <span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span>s<span class="Delimiter">))</span> <span class="Delimiter">{</span> name = s<span class="Delimiter">;</span> - type = new type_tree<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> - properties<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pair<string<span class="Delimiter">,</span> string_tree*><span class="Delimiter">(</span>name<span class="Delimiter">,</span> new string_tree<span class="Delimiter">(</span><span class="Constant">"literal-number"</span><span class="Delimiter">)));</span> + type = new type_tree<span class="Delimiter">(</span><span class="Constant">"literal-fractional-number"</span><span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> set_value<span class="Delimiter">(</span>to_double<span class="Delimiter">(</span>s<span class="Delimiter">));</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span class="Delimiter">:(code)</span> bool is_noninteger<span class="Delimiter">(</span>const string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> - <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-."</span><span class="Delimiter">)</span> == string::npos - && s<span class="Delimiter">.</span>find_first_of <span class="Delimiter">(</span><span class="Constant">"0123456789-"</span><span class="Delimiter">)</span> != string::npos - && std::count<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> s<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">'.'</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> + <span class="Identifier">return</span> s<span class="Delimiter">.</span>find_first_not_of<span class="Delimiter">(</span><span class="Constant">"0123456789-."</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// no other characters</span> + && s<span class="Delimiter">.</span>find_first_of<span class="Delimiter">(</span><span class="Constant">"0123456789"</span><span class="Delimiter">)</span> != string::npos <span class="Comment">// at least one digit</span> + && s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">'-'</span><span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">)</span> == string::npos <span class="Comment">// '-' only at first position</span> + && std::count<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> s<span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <span class="Constant">'.'</span><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// exactly one decimal point</span> <span class="Delimiter">}</span> double to_double<span class="Delimiter">(</span>string n<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -72,6 +72,11 @@ void test_is_noninteger<span class="Delimiter">()</span> <span class="Delimiter" CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"."</span><span class="Delimiter">));</span> CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"2."</span><span class="Delimiter">));</span> CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">".2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"-.2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>is_noninteger<span class="Delimiter">(</span><span class="Constant">"-2."</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"--.2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">".-2"</span><span class="Delimiter">));</span> + CHECK<span class="Delimiter">(</span>!is_noninteger<span class="Delimiter">(</span><span class="Constant">"..2"</span><span class="Delimiter">));</span> <span class="Delimiter">}</span> </pre> </body> |