summaryrefslogtreecommitdiffstats
path: root/vendor/serde_json/src/de.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/serde_json/src/de.rs')
-rw-r--r--vendor/serde_json/src/de.rs154
1 files changed, 73 insertions, 81 deletions
diff --git a/vendor/serde_json/src/de.rs b/vendor/serde_json/src/de.rs
index ffd0d48c2..88d0f2624 100644
--- a/vendor/serde_json/src/de.rs
+++ b/vendor/serde_json/src/de.rs
@@ -14,7 +14,7 @@ use core::marker::PhantomData;
use core::result;
use core::str::FromStr;
use serde::de::{self, Expected, Unexpected};
-use serde::{forward_to_deserialize_any, serde_if_integer128};
+use serde::forward_to_deserialize_any;
#[cfg(feature = "arbitrary_precision")]
use crate::number::NumberDeserializer;
@@ -335,31 +335,25 @@ impl<'de, R: Read<'de>> Deserializer<R> {
}
}
- serde_if_integer128! {
- fn scan_integer128(&mut self, buf: &mut String) -> Result<()> {
- match tri!(self.next_char_or_null()) {
- b'0' => {
- buf.push('0');
- // There can be only one leading '0'.
- match tri!(self.peek_or_null()) {
- b'0'..=b'9' => {
- Err(self.peek_error(ErrorCode::InvalidNumber))
- }
- _ => Ok(()),
- }
+ fn scan_integer128(&mut self, buf: &mut String) -> Result<()> {
+ match tri!(self.next_char_or_null()) {
+ b'0' => {
+ buf.push('0');
+ // There can be only one leading '0'.
+ match tri!(self.peek_or_null()) {
+ b'0'..=b'9' => Err(self.peek_error(ErrorCode::InvalidNumber)),
+ _ => Ok(()),
}
- c @ b'1'..=b'9' => {
+ }
+ c @ b'1'..=b'9' => {
+ buf.push(c as char);
+ while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
+ self.eat_char();
buf.push(c as char);
- while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
- self.eat_char();
- buf.push(c as char);
- }
- Ok(())
- }
- _ => {
- Err(self.error(ErrorCode::InvalidNumber))
}
+ Ok(())
}
+ _ => Err(self.error(ErrorCode::InvalidNumber)),
}
}
@@ -457,30 +451,33 @@ impl<'de, R: Read<'de>> Deserializer<R> {
&mut self,
positive: bool,
mut significand: u64,
- mut exponent: i32,
+ exponent_before_decimal_point: i32,
) -> Result<f64> {
self.eat_char();
+ let mut exponent_after_decimal_point = 0;
while let c @ b'0'..=b'9' = tri!(self.peek_or_null()) {
let digit = (c - b'0') as u64;
if overflow!(significand * 10 + digit, u64::max_value()) {
+ let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
return self.parse_decimal_overflow(positive, significand, exponent);
}
self.eat_char();
significand = significand * 10 + digit;
- exponent -= 1;
+ exponent_after_decimal_point -= 1;
}
// Error if there is not at least one digit after the decimal point.
- if exponent == 0 {
+ if exponent_after_decimal_point == 0 {
match tri!(self.peek()) {
Some(_) => return Err(self.peek_error(ErrorCode::InvalidNumber)),
None => return Err(self.peek_error(ErrorCode::EofWhileParsingValue)),
}
}
+ let exponent = exponent_before_decimal_point + exponent_after_decimal_point;
match tri!(self.peek_or_null()) {
b'e' | b'E' => self.parse_exponent(positive, significand, exponent),
_ => self.f64_from_parts(positive, significand, exponent),
@@ -1437,67 +1434,65 @@ impl<'de, 'a, R: Read<'de>> de::Deserializer<'de> for &'a mut Deserializer<R> {
val
}
- serde_if_integer128! {
- fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value>
- where
- V: de::Visitor<'de>,
- {
- let mut buf = String::new();
-
- match tri!(self.parse_whitespace()) {
- Some(b'-') => {
- self.eat_char();
- buf.push('-');
- }
- Some(_) => {}
- None => {
- return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
- }
- };
+ fn deserialize_i128<V>(self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'de>,
+ {
+ let mut buf = String::new();
- tri!(self.scan_integer128(&mut buf));
+ match tri!(self.parse_whitespace()) {
+ Some(b'-') => {
+ self.eat_char();
+ buf.push('-');
+ }
+ Some(_) => {}
+ None => {
+ return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
+ }
+ };
- let value = match buf.parse() {
- Ok(int) => visitor.visit_i128(int),
- Err(_) => {
- return Err(self.error(ErrorCode::NumberOutOfRange));
- }
- };
+ tri!(self.scan_integer128(&mut buf));
- match value {
- Ok(value) => Ok(value),
- Err(err) => Err(self.fix_position(err)),
+ let value = match buf.parse() {
+ Ok(int) => visitor.visit_i128(int),
+ Err(_) => {
+ return Err(self.error(ErrorCode::NumberOutOfRange));
}
+ };
+
+ match value {
+ Ok(value) => Ok(value),
+ Err(err) => Err(self.fix_position(err)),
}
+ }
- fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value>
- where
- V: de::Visitor<'de>,
- {
- match tri!(self.parse_whitespace()) {
- Some(b'-') => {
- return Err(self.peek_error(ErrorCode::NumberOutOfRange));
- }
- Some(_) => {}
- None => {
- return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
- }
+ fn deserialize_u128<V>(self, visitor: V) -> Result<V::Value>
+ where
+ V: de::Visitor<'de>,
+ {
+ match tri!(self.parse_whitespace()) {
+ Some(b'-') => {
+ return Err(self.peek_error(ErrorCode::NumberOutOfRange));
}
+ Some(_) => {}
+ None => {
+ return Err(self.peek_error(ErrorCode::EofWhileParsingValue));
+ }
+ }
- let mut buf = String::new();
- tri!(self.scan_integer128(&mut buf));
-
- let value = match buf.parse() {
- Ok(int) => visitor.visit_u128(int),
- Err(_) => {
- return Err(self.error(ErrorCode::NumberOutOfRange));
- }
- };
+ let mut buf = String::new();
+ tri!(self.scan_integer128(&mut buf));
- match value {
- Ok(value) => Ok(value),
- Err(err) => Err(self.fix_position(err)),
+ let value = match buf.parse() {
+ Ok(int) => visitor.visit_u128(int),
+ Err(_) => {
+ return Err(self.error(ErrorCode::NumberOutOfRange));
}
+ };
+
+ match value {
+ Ok(value) => Ok(value),
+ Err(err) => Err(self.fix_position(err)),
}
}
@@ -2164,15 +2159,12 @@ where
deserialize_integer_key!(deserialize_i16 => visit_i16);
deserialize_integer_key!(deserialize_i32 => visit_i32);
deserialize_integer_key!(deserialize_i64 => visit_i64);
+ deserialize_integer_key!(deserialize_i128 => visit_i128);
deserialize_integer_key!(deserialize_u8 => visit_u8);
deserialize_integer_key!(deserialize_u16 => visit_u16);
deserialize_integer_key!(deserialize_u32 => visit_u32);
deserialize_integer_key!(deserialize_u64 => visit_u64);
-
- serde_if_integer128! {
- deserialize_integer_key!(deserialize_i128 => visit_i128);
- deserialize_integer_key!(deserialize_u128 => visit_u128);
- }
+ deserialize_integer_key!(deserialize_u128 => visit_u128);
#[inline]
fn deserialize_option<V>(self, visitor: V) -> Result<V::Value>