File tree 3 files changed +15
-1
lines changed
3 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 485
485
)
486
486
result
487
487
488
- :fun parse_i64! // TODO: Use something like Crystal's Char::Reader instead?
488
+ :fun parse_i64! I64 // TODO: Use something like Crystal's Char::Reader instead?
489
489
output I64 = 0
490
490
possible_negation I64 = 1
491
491
@each_byte_with_index -> (byte, index |
498
498
)
499
499
output * possible_negation
500
500
501
+ :fun parse_f64! F64 // TODO: Use something like Crystal's Char::Reader instead?
502
+ // TODO: Avoid FFI and use a pure Savi `strtod` implementation.
503
+ start_pointer = @cstring
504
+ end_pointer = CPointer(U8).null
505
+ value = _FFI.strtod(start_pointer, stack_address_of_variable end_pointer)
506
+ error! if value == 0 && end_pointer.address == start_pointer.address
507
+ error! if end_pointer.address != start_pointer.address + @size
508
+ value
509
+
501
510
:fun substring(from USize, to USize = 0) String'iso
502
511
if to == 0 || to > @_size (
503
512
to = @_size
Original file line number Diff line number Diff line change 3
3
:ffi strlen(string CPointer(U8)) USize
4
4
:ffi memset(pointer CPointer(U8), char I32, count USize) None
5
5
:ffi variadic snprintf(buffer CPointer(U8), buffer_size I32, fmt CPointer(U8)) I32
6
+ :ffi strtod(start_pointer CPointer(U8), end_pointer CPointer(CPointer(U8))) F64
6
7
7
8
:ffi pony_exitcode(code I32) None
8
9
:ffi pony_os_stdout_setup() None
Original file line number Diff line number Diff line change 306
306
assert: "-36".parse_i64! == -36
307
307
assert error: "36bad".parse_i64!
308
308
309
+ :it "parses a floating point from the string decimal representation"
310
+ assert: "36.3".parse_f64! == 36.3
311
+ assert error: "36.3bad".parse_f64!
312
+
309
313
:it "returns the unicode codepoint found at the given offset, if valid"
310
314
string = "नमस्ते"
311
315
assert: string.char_at!(0) == 'न' // valid
You can’t perform that action at this time.
0 commit comments