Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
AdminXVII
calc
Commits
1504684e
Commit
1504684e
authored
Apr 11, 2019
by
AdminXVII
Browse files
Fix lone zero handling
parent
62378ccb
Pipeline
#3736
passed with stage
in 3 minutes and 1 second
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Cargo.lock
View file @
1504684e
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "ansi_term"
version = "0.9.0"
...
...
src/token.rs
View file @
1504684e
...
...
@@ -373,11 +373,14 @@ pub fn tokenize_polish(input: &str) -> Result<Vec<Token>, CalcError> {
Ok
(
tokens
)
}
fn
digits
<
I
>
(
input
:
&
mut
Peekable
<
I
>
,
radix
:
u32
)
->
String
fn
digits
<
I
>
(
input
:
&
mut
Peekable
<
I
>
,
radix
:
u32
,
has_zero
:
bool
)
->
String
where
I
:
Iterator
<
Item
=
char
>
,
{
let
mut
number
=
String
::
new
();
if
has_zero
{
number
.push
(
'0'
)
}
while
let
Some
(
&
c
)
=
input
.peek
()
{
if
c
.is_digit
(
radix
)
{
number
.push
(
c
);
...
...
@@ -393,27 +396,27 @@ fn consume_number<I>(input: &mut Peekable<I>) -> Result<Value, CalcError>
where
I
:
Iterator
<
Item
=
char
>
,
{
let
mut
has_zero
=
false
;
match
input
.peek
()
{
Some
(
&
'0'
)
=>
{
input
.next
();
match
input
.peek
()
{
Some
(
&
'x'
)
|
Some
(
&
'X'
)
=>
{
input
.next
();
let
digits
=
digits
(
input
,
16
);
let
digits
=
digits
(
input
,
16
,
false
);
let
num
=
Integral
::
from_str_radix
(
&
digits
,
16
)
?
;
return
Ok
(
Value
::
hex
(
num
));
}
Some
(
&
_
)
=>
(),
None
=>
return
Ok
(
Value
::
dec
(
0
)),
_
=>
has_zero
=
true
,
}
}
Some
(
_
)
=>
(),
None
=>
return
Err
(
CalcError
::
UnexpectedEndOfInput
),
}
let
whole
=
digits
(
input
,
10
);
let
whole
=
digits
(
input
,
10
,
has_zero
);
if
let
Some
(
&
'.'
)
=
input
.peek
()
{
input
.next
();
let
frac
=
digits
(
input
,
10
);
let
frac
=
digits
(
input
,
10
,
false
);
let
num
=
[
whole
,
"."
.into
(),
frac
]
.concat
()
.parse
::
<
d128
>
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment