std: remove Encoder::emit_{owned,managed}_str and Decoder::read_{owned,managed}_str
This commit is contained in:
parent
1dd11c7179
commit
8b43c620b9
5 changed files with 20 additions and 72 deletions
|
@ -311,11 +311,8 @@ pub mod reader {
|
|||
fn read_f64(&self) -> f64 { fail!(~"read_f64()"); }
|
||||
fn read_f32(&self) -> f32 { fail!(~"read_f32()"); }
|
||||
fn read_float(&self) -> float { fail!(~"read_float()"); }
|
||||
|
||||
fn read_char(&self) -> char { fail!(~"read_char()"); }
|
||||
|
||||
fn read_owned_str(&self) -> ~str { doc_as_str(self.next_doc(EsStr)) }
|
||||
fn read_managed_str(&self) -> @str { fail!(~"read_managed_str()"); }
|
||||
fn read_str(&self) -> ~str { doc_as_str(self.next_doc(EsStr)) }
|
||||
|
||||
// Compound types:
|
||||
fn read_owned<T>(&self, f: &fn() -> T) -> T {
|
||||
|
@ -650,18 +647,10 @@ pub mod writer {
|
|||
fail!(~"Unimplemented: serializing a char");
|
||||
}
|
||||
|
||||
fn emit_borrowed_str(&self, v: &str) {
|
||||
fn emit_str(&self, v: &str) {
|
||||
self.wr_tagged_str(EsStr as uint, v)
|
||||
}
|
||||
|
||||
fn emit_owned_str(&self, v: &str) {
|
||||
self.emit_borrowed_str(v)
|
||||
}
|
||||
|
||||
fn emit_managed_str(&self, v: &str) {
|
||||
self.emit_borrowed_str(v)
|
||||
}
|
||||
|
||||
fn emit_borrowed(&self, f: &fn()) { f() }
|
||||
fn emit_owned(&self, f: &fn()) { f() }
|
||||
fn emit_managed(&self, f: &fn()) { f() }
|
||||
|
|
|
@ -105,20 +105,14 @@ impl serialize::Encoder for Encoder {
|
|||
self.wr.write_str(float::to_str_digits(v, 6u));
|
||||
}
|
||||
|
||||
fn emit_char(&self, v: char) { self.emit_borrowed_str(str::from_char(v)) }
|
||||
|
||||
fn emit_borrowed_str(&self, v: &str) { self.wr.write_str(escape_str(v)) }
|
||||
fn emit_owned_str(&self, v: &str) { self.emit_borrowed_str(v) }
|
||||
fn emit_managed_str(&self, v: &str) { self.emit_borrowed_str(v) }
|
||||
fn emit_char(&self, v: char) { self.emit_str(str::from_char(v)) }
|
||||
fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)) }
|
||||
|
||||
fn emit_borrowed(&self, f: &fn()) { f() }
|
||||
fn emit_owned(&self, f: &fn()) { f() }
|
||||
fn emit_managed(&self, f: &fn()) { f() }
|
||||
|
||||
fn emit_enum(&self, _name: &str, f: &fn()) {
|
||||
f()
|
||||
}
|
||||
|
||||
fn emit_enum(&self, _name: &str, f: &fn()) { f() }
|
||||
fn emit_enum_variant(&self, name: &str, _id: uint, cnt: uint, f: &fn()) {
|
||||
// enums are encoded as strings or vectors:
|
||||
// Bunny => "Bunny"
|
||||
|
@ -224,15 +218,8 @@ impl serialize::Encoder for PrettyEncoder {
|
|||
self.wr.write_str(float::to_str_digits(v, 6u));
|
||||
}
|
||||
|
||||
fn emit_char(&self, v: char) { self.emit_borrowed_str(str::from_char(v)) }
|
||||
|
||||
fn emit_borrowed_str(&self, v: &str) { self.wr.write_str(escape_str(v)); }
|
||||
fn emit_owned_str(&self, v: &str) { self.emit_borrowed_str(v) }
|
||||
fn emit_managed_str(&self, v: &str) { self.emit_borrowed_str(v) }
|
||||
|
||||
fn emit_borrowed(&self, f: &fn()) { f() }
|
||||
fn emit_owned(&self, f: &fn()) { f() }
|
||||
fn emit_managed(&self, f: &fn()) { f() }
|
||||
fn emit_char(&self, v: char) { self.emit_str(str::from_char(v)) }
|
||||
fn emit_str(&self, v: &str) { self.wr.write_str(escape_str(v)); }
|
||||
|
||||
fn emit_enum(&self, _name: &str, f: &fn()) { f() }
|
||||
fn emit_enum_variant(&self, name: &str, _id: uint, cnt: uint, f: &fn()) {
|
||||
|
@ -818,36 +805,19 @@ impl<'self> serialize::Decoder for Decoder<'self> {
|
|||
|
||||
fn read_char(&self) -> char {
|
||||
let mut v = ~[];
|
||||
for str::each_char(self.read_owned_str()) |c| { v.push(c) }
|
||||
for str::each_char(self.read_str()) |c| { v.push(c) }
|
||||
if v.len() != 1 { fail!(~"string must have one character") }
|
||||
v[0]
|
||||
}
|
||||
|
||||
fn read_owned_str(&self) -> ~str {
|
||||
debug!("read_owned_str");
|
||||
fn read_str(&self) -> ~str {
|
||||
debug!("read_str");
|
||||
match *self.pop() {
|
||||
String(ref s) => copy *s,
|
||||
ref json => fail!(fmt!("not a string: %?", *json))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_managed_str(&self) -> @str {
|
||||
debug!("read_managed_str");
|
||||
match *self.pop() {
|
||||
String(ref s) => s.to_managed(),
|
||||
ref json => fail!(fmt!("not a string: %?", *json))
|
||||
}
|
||||
}
|
||||
|
||||
fn read_owned<T>(&self, f: &fn() -> T) -> T {
|
||||
debug!("read_owned()");
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_managed<T>(&self, f: &fn() -> T) -> T {
|
||||
debug!("read_managed()");
|
||||
f()
|
||||
}
|
||||
|
||||
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T {
|
||||
debug!("read_enum(%s)", name);
|
||||
|
|
|
@ -38,9 +38,7 @@ pub trait Encoder {
|
|||
fn emit_f64(&self, v: f64);
|
||||
fn emit_f32(&self, v: f32);
|
||||
fn emit_char(&self, v: char);
|
||||
fn emit_borrowed_str(&self, v: &str);
|
||||
fn emit_owned_str(&self, v: &str);
|
||||
fn emit_managed_str(&self, v: &str);
|
||||
fn emit_str(&self, v: &str);
|
||||
|
||||
// Compound types:
|
||||
fn emit_borrowed(&self, f: &fn());
|
||||
|
@ -87,20 +85,16 @@ pub trait Decoder {
|
|||
fn read_f32(&self) -> f32;
|
||||
fn read_float(&self) -> float;
|
||||
fn read_char(&self) -> char;
|
||||
fn read_owned_str(&self) -> ~str;
|
||||
fn read_managed_str(&self) -> @str;
|
||||
fn read_str(&self) -> ~str;
|
||||
|
||||
// Compound types:
|
||||
fn read_enum<T>(&self, name: &str, f: &fn() -> T) -> T;
|
||||
|
||||
#[cfg(stage0)]
|
||||
fn read_enum_variant<T>(&self, f: &fn(uint) -> T) -> T;
|
||||
|
||||
#[cfg(stage1)]
|
||||
#[cfg(stage2)]
|
||||
#[cfg(stage3)]
|
||||
fn read_enum_variant<T>(&self, names: &[&str], f: &fn(uint) -> T) -> T;
|
||||
|
||||
fn read_enum_variant_arg<T>(&self, idx: uint, f: &fn() -> T) -> T;
|
||||
|
||||
fn read_owned<T>(&self, f: &fn() -> T) -> T;
|
||||
|
@ -230,27 +224,25 @@ impl<D:Decoder> Decodable<D> for i64 {
|
|||
}
|
||||
|
||||
impl<'self, S:Encoder> Encodable<S> for &'self str {
|
||||
fn encode(&self, s: &S) { s.emit_borrowed_str(*self) }
|
||||
fn encode(&self, s: &S) { s.emit_str(*self) }
|
||||
}
|
||||
|
||||
impl<S:Encoder> Encodable<S> for ~str {
|
||||
fn encode(&self, s: &S) { s.emit_owned_str(*self) }
|
||||
fn encode(&self, s: &S) { s.emit_str(*self) }
|
||||
}
|
||||
|
||||
impl<D:Decoder> Decodable<D> for ~str {
|
||||
fn decode(d: &D) -> ~str {
|
||||
d.read_owned_str()
|
||||
d.read_str()
|
||||
}
|
||||
}
|
||||
|
||||
impl<S:Encoder> Encodable<S> for @str {
|
||||
fn encode(&self, s: &S) { s.emit_managed_str(*self) }
|
||||
fn encode(&self, s: &S) { s.emit_str(*self) }
|
||||
}
|
||||
|
||||
impl<D:Decoder> Decodable<D> for @str {
|
||||
fn decode(d: &D) -> @str {
|
||||
d.read_managed_str()
|
||||
}
|
||||
fn decode(d: &D) -> @str { d.read_str().to_managed() }
|
||||
}
|
||||
|
||||
impl<S:Encoder> Encodable<S> for float {
|
||||
|
|
|
@ -70,7 +70,7 @@ impl<S:Encoder> Encodable<S> for ident {
|
|||
Some(intr) => intr
|
||||
};
|
||||
|
||||
s.emit_owned_str(*(*intr).get(*self));
|
||||
s.emit_str(*(*intr).get(*self));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,7 @@ impl<D:Decoder> Decodable<D> for ident {
|
|||
Some(intr) => intr
|
||||
};
|
||||
|
||||
(*intr).intern(@d.read_owned_str())
|
||||
(*intr).intern(@d.read_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1240,10 +1240,7 @@ mod test {
|
|||
fn emit_float(&self, +_v: float) { self.add_unknown_to_log(); }
|
||||
|
||||
fn emit_char(&self, +_v: char) { self.add_unknown_to_log(); }
|
||||
|
||||
fn emit_borrowed_str(&self, +_v: &str) { self.add_unknown_to_log(); }
|
||||
fn emit_owned_str(&self, +_v: &str) { self.add_unknown_to_log(); }
|
||||
fn emit_managed_str(&self, +_v: &str) { self.add_unknown_to_log(); }
|
||||
fn emit_str(&self, +_v: &str) { self.add_unknown_to_log(); }
|
||||
|
||||
fn emit_borrowed(&self, f: &fn()) { self.add_unknown_to_log(); f() }
|
||||
fn emit_owned(&self, f: &fn()) { self.add_unknown_to_log(); f() }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue