ptmgr::ipc: Try an alternate approach to initial quotes.
This lets us use `chars()` rather than `char_indices()`.
This commit is contained in:
parent
a8b96534be
commit
cb7eb3b00d
|
@ -122,19 +122,14 @@ fn parse_one_value(from: &str) -> Result<(String, &str), &'static str> {
|
||||||
// FIXME(eta): This currently doesn't parse octal escape codes, even though the spec says
|
// FIXME(eta): This currently doesn't parse octal escape codes, even though the spec says
|
||||||
// we should. That's finicky, though, and probably not used.
|
// we should. That's finicky, though, and probably not used.
|
||||||
let mut ret = String::new();
|
let mut ret = String::new();
|
||||||
let mut char_indices = from.char_indices();
|
let mut chars = from.chars();
|
||||||
|
assert_eq!(chars.next(), Some('"')); // discard "
|
||||||
loop {
|
loop {
|
||||||
let (idx, ch) = char_indices
|
let ch = chars.next().ok_or("ran out of input parsing CString")?;
|
||||||
.next()
|
|
||||||
.ok_or("ran out of input parsing CString")?;
|
|
||||||
if idx == 0 {
|
|
||||||
continue; // ignore first quote
|
|
||||||
}
|
|
||||||
match ch {
|
match ch {
|
||||||
'\\' => match char_indices
|
'\\' => match chars
|
||||||
.next()
|
.next()
|
||||||
.ok_or("encountered trailing backslash in CString")?
|
.ok_or("encountered trailing backslash in CString")?
|
||||||
.1
|
|
||||||
{
|
{
|
||||||
'n' => ret.push('\n'),
|
'n' => ret.push('\n'),
|
||||||
'r' => ret.push('\r'),
|
'r' => ret.push('\r'),
|
||||||
|
@ -146,7 +141,7 @@ fn parse_one_value(from: &str) -> Result<(String, &str), &'static str> {
|
||||||
_ => ret.push(ch),
|
_ => ret.push(ch),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(ret, char_indices.as_str())
|
(ret, chars.as_str())
|
||||||
} else {
|
} else {
|
||||||
// Simple: just find the space
|
// Simple: just find the space
|
||||||
let space = from.find(' ').unwrap_or(from.len());
|
let space = from.find(' ').unwrap_or(from.len());
|
||||||
|
|
Loading…
Reference in New Issue