forked from M-Labs/ionpak-thermostat
command_parser: fix float parsing
This commit is contained in:
parent
6f36c682cd
commit
f3664f01be
@ -4,7 +4,7 @@ use nom::{
|
||||
branch::alt,
|
||||
bytes::complete::{is_a, tag, take_while1},
|
||||
character::{is_digit, complete::{char, one_of}},
|
||||
combinator::{complete, map, value},
|
||||
combinator::{complete, map, opt, value},
|
||||
sequence::{preceded, separated_pair},
|
||||
multi::{fold_many0, fold_many1},
|
||||
error::ErrorKind,
|
||||
@ -133,8 +133,8 @@ fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
|
||||
}
|
||||
|
||||
fn float(input: &[u8]) -> IResult<&[u8], Result<f32, Error>> {
|
||||
let (input, sign) = is_a("-")(input)?;
|
||||
let negative = sign.len() > 0;
|
||||
let (input, sign) = opt(is_a("-"))(input)?;
|
||||
let negative = sign.is_some();
|
||||
let (input, digits) = take_while1(|c| is_digit(c) || c == '.' as u8)(input)?;
|
||||
let result = lexical::parse(digits)
|
||||
.map(|result: f32| if negative { -result } else { result })
|
||||
|
@ -1,7 +1,10 @@
|
||||
#![feature(const_fn, proc_macro_hygiene)]
|
||||
#![no_std]
|
||||
#![cfg_attr(not(test), no_std)]
|
||||
#![cfg_attr(not(test), no_main)]
|
||||
|
||||
#[cfg(not(test))]
|
||||
extern crate std;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
use core::fmt::{self, Write};
|
||||
use smoltcp::time::Instant;
|
||||
|
Loading…
Reference in New Issue
Block a user