Inline and export json string escaping functions

This commit is contained in:
Erick Tryzelaar 2014-09-07 01:07:45 -07:00
parent 02bcb1c616
commit bb361086b3
2 changed files with 6 additions and 2 deletions
serde2/src/json

@ -1,4 +1,5 @@
pub use self::ser::Serializer;
pub use self::ser::{to_vec, to_string};
pub use self::ser::escape_str;
pub mod ser;

@ -166,7 +166,8 @@ impl<W: Writer> ser::VisitorState<io::IoResult<()>> for Serializer<W> {
}
}
fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> io::IoResult<()> {
#[inline]
pub fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> io::IoResult<()> {
try!(wr.write_str("\""));
let mut start = 0;
@ -199,10 +200,12 @@ fn escape_bytes<W: Writer>(wr: &mut W, bytes: &[u8]) -> io::IoResult<()> {
wr.write_str("\"")
}
fn escape_str<W: Writer>(wr: &mut W, value: &str) -> io::IoResult<()> {
#[inline]
pub fn escape_str<W: Writer>(wr: &mut W, value: &str) -> io::IoResult<()> {
escape_bytes(wr, value.as_bytes())
}
#[inline]
pub fn escape_char<W: Writer>(wr: &mut W, value: char) -> io::IoResult<()> {
let mut buf = [0, .. 4];
value.encode_utf8(buf);