mirror of
https://codeberg.org/icewind/php-literal-parser.git
synced 2026-06-03 18:44:07 +02:00
the bit of performance is not worth this unsafe
This commit is contained in:
parent
f1c1f99328
commit
06e43ddd9c
2 changed files with 4 additions and 6 deletions
|
|
@ -18,6 +18,7 @@
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
#![forbid(unsafe_code)]
|
||||||
mod error;
|
mod error;
|
||||||
mod lexer;
|
mod lexer;
|
||||||
mod num;
|
mod num;
|
||||||
|
|
|
||||||
|
|
@ -40,11 +40,8 @@ impl UnescapeState {
|
||||||
self.out.extend_from_slice(slice);
|
self.out.extend_from_slice(slice);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn finalize(self) -> String {
|
fn finalize(self) -> UnescapeResult<String> {
|
||||||
// this is safe because we only push bytes into the buffer that either
|
String::from_utf8(self.out).map_err(|_| UnescapeError)
|
||||||
// - come from the source &str, and are delimited a \
|
|
||||||
// - are validated unicode points, utf8 encoded
|
|
||||||
unsafe { String::from_utf8_unchecked(self.out) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,7 +166,7 @@ fn unescape<S: EscapedString>(s: &str) -> UnescapeResult<String> {
|
||||||
|
|
||||||
state.push_slice(&bytes[0..]);
|
state.push_slice(&bytes[0..]);
|
||||||
|
|
||||||
Ok(state.finalize())
|
state.finalize()
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PeekableBytes<'a> {
|
struct PeekableBytes<'a> {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue