summary refs log tree commit diff stats
path: root/lib/pure/asyncnet.nim
diff options
context:
space:
mode:
authorTimothee Cour <timothee.cour2@gmail.com>2020-03-20 08:39:55 -0700
committerGitHub <noreply@github.com>2020-03-20 16:39:55 +0100
commit1d665adecde3b3bf16e64068e83c0b3cb0171856 (patch)
tree5081cb220073d43212c968af5861dfe3e3b0df4e /lib/pure/asyncnet.nim
parent8215c576664e0bd689c16739f72d5b79cf302ec8 (diff)
downloadNim-1d665adecde3b3bf16e64068e83c0b3cb0171856.tar.gz
[RFC] 'walkDir' now has a new 'checkDir' flag, to mimic behaviour of other languages (#13642)
Co-authored-by: narimiran
Diffstat (limited to 'lib/pure/asyncnet.nim')
0 files changed, 0 insertions, 0 deletions
cc767a658c6f61b12cd7461e21'>ae256ea1 ^
1f59be84 ^


6f8f9fb5 ^


ac0e9db5 ^
8ec12cbe ^
dd3bd122 ^
6f8f9fb5 ^








dd3bd122 ^





8ec12cbe ^


dd3bd122 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
                                 





                              
                                                   
 


                                    
                          
                                                                                            


                          


                                     
                                                            
                                                           
                                                  








                                                                    





                                


                             
 
//: Support literal non-integers.

:(scenarios load)
:(scenario noninteger_literal)
recipe main [
  1:number <- copy 3.14159
]
+parse:   ingredient: {"3.14159": "literal-number"}

:(after "Parsing reagent(string s)")
if (is_noninteger(s)) {
  name = s;
  type = new type_tree(0);
  properties.push_back(pair<string, string_tree*>(name, new string_tree("literal-number")));
  set_value(to_double(s));
  return;
}

:(code)
bool is_noninteger(const string& s) {
  return s.find_first_not_of("0123456789-.") == string::npos
      && s.find_first_of    ("0123456789-") != string::npos
      && std::count(s.begin(), s.end(), '.') == 1;
}

double to_double(string n) {
  char* end = NULL;
  // safe because string.c_str() is guaranteed to be null-terminated
  double result = strtod(n.c_str(), &end);
  assert(*end == '\0');
  return result;
}

void test_is_noninteger() {
  CHECK(!is_noninteger("1234"));
  CHECK(!is_noninteger("1a2"));
  CHECK(is_noninteger("234.0"));
  CHECK(!is_noninteger("..."));
  CHECK(!is_noninteger("."));
  CHECK(is_noninteger("2."));
  CHECK(is_noninteger(".2"));
}