mirror of
https://github.com/pezkuwichain/serde.git
synced 2026-06-18 16:41:03 +00:00
Merge pull request #71 from lifthrasiir/json-split-branch
Replace a redundant `escape` variable with nested matches.
This commit is contained in:
+11
-13
@@ -307,15 +307,23 @@ impl<Iter> Deserializer<Iter>
|
|||||||
fn parse_string(&mut self) -> Result<(), Error> {
|
fn parse_string(&mut self) -> Result<(), Error> {
|
||||||
self.str_buf.clear();
|
self.str_buf.clear();
|
||||||
|
|
||||||
let mut escape = false;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let ch = match try!(self.next_char()) {
|
let ch = match try!(self.next_char()) {
|
||||||
Some(ch) => ch,
|
Some(ch) => ch,
|
||||||
None => { return Err(self.error(ErrorCode::EOFWhileParsingString)); }
|
None => { return Err(self.error(ErrorCode::EOFWhileParsingString)); }
|
||||||
};
|
};
|
||||||
|
|
||||||
if escape {
|
match ch {
|
||||||
|
b'"' => {
|
||||||
|
try!(self.bump());
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
b'\\' => {
|
||||||
|
let ch = match try!(self.next_char()) {
|
||||||
|
Some(ch) => ch,
|
||||||
|
None => { return Err(self.error(ErrorCode::EOFWhileParsingString)); }
|
||||||
|
};
|
||||||
|
|
||||||
match ch {
|
match ch {
|
||||||
b'"' => self.str_buf.push(b'"'),
|
b'"' => self.str_buf.push(b'"'),
|
||||||
b'\\' => self.str_buf.push(b'\\'),
|
b'\\' => self.str_buf.push(b'\\'),
|
||||||
@@ -377,15 +385,6 @@ impl<Iter> Deserializer<Iter>
|
|||||||
return Err(self.error(ErrorCode::InvalidEscape));
|
return Err(self.error(ErrorCode::InvalidEscape));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
escape = false;
|
|
||||||
} else {
|
|
||||||
match ch {
|
|
||||||
b'"' => {
|
|
||||||
try!(self.bump());
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
b'\\' => {
|
|
||||||
escape = true;
|
|
||||||
}
|
}
|
||||||
ch => {
|
ch => {
|
||||||
self.str_buf.push(ch);
|
self.str_buf.push(ch);
|
||||||
@@ -393,7 +392,6 @@ impl<Iter> Deserializer<Iter>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn parse_object_colon(&mut self) -> Result<(), Error> {
|
fn parse_object_colon(&mut self) -> Result<(), Error> {
|
||||||
try!(self.parse_whitespace());
|
try!(self.parse_whitespace());
|
||||||
|
|||||||
Reference in New Issue
Block a user