Skip to content

Commit

Permalink
Changed DELIMITER (u8) into an array DELIMITERS (u8; 4) that holds va…
Browse files Browse the repository at this point in the history
…rious types of possible delimiters.
  • Loading branch information
JGM01 committed Feb 1, 2025
1 parent 8f91a9c commit b86f89a
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/de/simple_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::encoding::Decoder;
use crate::errors::serialize::DeError;
use crate::escape::unescape;
use crate::utils::CowRef;
use memchr::memchr;
use serde::de::value::UnitDeserializer;
use serde::de::{
DeserializeSeed, Deserializer, EnumAccess, IntoDeserializer, SeqAccess, VariantAccess, Visitor,
Expand Down Expand Up @@ -361,14 +360,17 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> {
T: DeserializeSeed<'de>,
{
if let Some(mut content) = self.content.take() {
const DELIMITER: u8 = b' ';
const DELIMETERS: [u8; 4] = [b' ', b'\t', b'\r', b'\n'];

loop {
let string = content.as_str();
if string.is_empty() {
return Ok(None);
}
return match memchr(DELIMITER, string.as_bytes()) {

let first_delimiter = string.as_bytes().iter().position(|c| DELIMETERS.contains(c));

return match first_delimiter {
// No delimiters in the `content`, deserialize it as a whole atomic
None => match content {
Content::Input(s) => seed.deserialize(AtomicDeserializer {
Expand All @@ -391,7 +393,7 @@ impl<'de, 'a> SeqAccess<'de> for ListIter<'de, 'a> {
// `content` started with a space, skip them all
Some(0) => {
// Skip all spaces
let start = string.as_bytes().iter().position(|ch| *ch != DELIMITER);
let start = string.as_bytes().iter().position(|c| !DELIMETERS.contains(c));
content = match (start, content) {
// We cannot find any non-space character, so string contains only spaces
(None, _) => return Ok(None),
Expand Down

0 comments on commit b86f89a

Please # to comment.