diff options
| author | Michael Sullivan <sully@msully.net> | 2012-07-13 22:57:48 -0700 |
|---|---|---|
| committer | Michael Sullivan <sully@msully.net> | 2012-07-14 01:03:43 -0700 |
| commit | 92743dc2a6a14d042d4b278e4a4dde5ca198c886 (patch) | |
| tree | 2626211c99906387257880f127f96fee66a0bb4e /src/libstd | |
| parent | 5c5065e8bdd1a7b28810fea4b940577ff17c112c (diff) | |
| download | rust-92743dc2a6a14d042d4b278e4a4dde5ca198c886.tar.gz rust-92743dc2a6a14d042d4b278e4a4dde5ca198c886.zip | |
Move the world over to using the new style string literals and types. Closes #2907.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/base64.rs | 48 | ||||
| -rw-r--r-- | src/libstd/bitv.rs | 10 | ||||
| -rw-r--r-- | src/libstd/ebml.rs | 46 | ||||
| -rw-r--r-- | src/libstd/getopts.rs | 351 | ||||
| -rw-r--r-- | src/libstd/json.rs | 433 | ||||
| -rw-r--r-- | src/libstd/list.rs | 2 | ||||
| -rw-r--r-- | src/libstd/map.rs | 130 | ||||
| -rw-r--r-- | src/libstd/md4.rs | 30 | ||||
| -rw-r--r-- | src/libstd/net_ip.rs | 60 | ||||
| -rw-r--r-- | src/libstd/net_tcp.rs | 208 | ||||
| -rw-r--r-- | src/libstd/par.rs | 6 | ||||
| -rw-r--r-- | src/libstd/prettyprint.rs | 40 | ||||
| -rw-r--r-- | src/libstd/rope.rs | 36 | ||||
| -rw-r--r-- | src/libstd/serialization.rs | 26 | ||||
| -rw-r--r-- | src/libstd/sha1.rs | 28 | ||||
| -rw-r--r-- | src/libstd/tempfile.rs | 6 | ||||
| -rw-r--r-- | src/libstd/term.rs | 6 | ||||
| -rw-r--r-- | src/libstd/test.rs | 104 | ||||
| -rw-r--r-- | src/libstd/time.rs | 591 | ||||
| -rw-r--r-- | src/libstd/timer.rs | 9 | ||||
| -rw-r--r-- | src/libstd/treemap.rs | 12 | ||||
| -rw-r--r-- | src/libstd/uv_global_loop.rs | 22 | ||||
| -rw-r--r-- | src/libstd/uv_iotask.rs | 10 | ||||
| -rw-r--r-- | src/libstd/uv_ll.rs | 109 |
24 files changed, 1166 insertions, 1157 deletions
diff --git a/src/libstd/base64.rs b/src/libstd/base64.rs index 3ca34c4b756..e2c8ad31344 100644 --- a/src/libstd/base64.rs +++ b/src/libstd/base64.rs @@ -1,17 +1,17 @@ import io::{reader, reader_util}; iface to_base64 { - fn to_base64() -> str; + fn to_base64() -> ~str; } impl of to_base64 for ~[u8] { - fn to_base64() -> str { + fn to_base64() -> ~str { let chars = str::chars( - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" + ~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" ); let len = self.len(); - let mut s = ""; + let mut s = ~""; str::reserve(s, ((len + 3u) / 4u) * 3u); let mut i = 0u; @@ -52,8 +52,8 @@ impl of to_base64 for ~[u8] { } } -impl of to_base64 for str { - fn to_base64() -> str { +impl of to_base64 for ~str { + fn to_base64() -> ~str { str::bytes(self).to_base64() } } @@ -64,7 +64,7 @@ iface from_base64 { impl of from_base64 for ~[u8] { fn from_base64() -> ~[u8] { - if self.len() % 4u != 0u { fail "invalid base64 length"; } + if self.len() % 4u != 0u { fail ~"invalid base64 length"; } let len = self.len(); let mut padding = 0u; @@ -107,11 +107,11 @@ impl of from_base64 for ~[u8] { ret copy r; } _ { - fail "invalid base64 padding"; + fail ~"invalid base64 padding"; } } } else { - fail "invalid base64 character"; + fail ~"invalid base64 character"; } i += 1u; @@ -126,7 +126,7 @@ impl of from_base64 for ~[u8] { } } -impl of from_base64 for str { +impl of from_base64 for ~str { fn from_base64() -> ~[u8] { str::bytes(self).from_base64() } @@ -136,23 +136,23 @@ impl of from_base64 for str { mod tests { #[test] fn test_to_base64() { - assert "".to_base64() == ""; - assert "f".to_base64() == "Zg=="; - assert "fo".to_base64() == "Zm8="; - assert "foo".to_base64() == "Zm9v"; - assert "foob".to_base64() == "Zm9vYg=="; - assert "fooba".to_base64() == "Zm9vYmE="; - assert "foobar".to_base64() == "Zm9vYmFy"; + assert (~"").to_base64() == ~""; + assert (~"f").to_base64() == ~"Zg=="; + assert (~"fo").to_base64() == ~"Zm8="; + assert (~"foo").to_base64() == ~"Zm9v"; + assert (~"foob").to_base64() == ~"Zm9vYg=="; + assert (~"fooba").to_base64() == ~"Zm9vYmE="; + assert (~"foobar").to_base64() == ~"Zm9vYmFy"; } #[test] fn test_from_base64() { - assert "".from_base64() == str::bytes(""); - assert "Zg==".from_base64() == str::bytes("f"); - assert "Zm8=".from_base64() == str::bytes("fo"); - assert "Zm9v".from_base64() == str::bytes("foo"); - assert "Zm9vYg==".from_base64() == str::bytes("foob"); - assert "Zm9vYmE=".from_base64() == str::bytes("fooba"); - assert "Zm9vYmFy".from_base64() == str::bytes("foobar"); + assert (~"").from_base64() == str::bytes(~""); + assert (~"Zg==").from_base64() == str::bytes(~"f"); + assert (~"Zm8=").from_base64() == str::bytes(~"fo"); + assert (~"Zm9v").from_base64() == str::bytes(~"foo"); + assert (~"Zm9vYg==").from_base64() == str::bytes(~"foob"); + assert (~"Zm9vYmE=").from_base64() == str::bytes(~"fooba"); + assert (~"Zm9vYmFy").from_base64() == str::bytes(~"foobar"); } } diff --git a/src/libstd/bitv.rs b/src/libstd/bitv.rs index f6c7b573f65..3816e415b96 100644 --- a/src/libstd/bitv.rs +++ b/src/libstd/bitv.rs @@ -213,9 +213,9 @@ fn each_storage(v: bitv, op: fn(&uint) -> bool) { * The resulting string has the same length as the bitvector, and each * character is either '0' or '1'. */ -fn to_str(v: bitv) -> str { - let mut rs = ""; - for each(v) |i| { if i { rs += "1"; } else { rs += "0"; } } +fn to_str(v: bitv) -> ~str { + let mut rs = ~""; + for each(v) |i| { if i { rs += ~"1"; } else { rs += ~"0"; } } ret rs; } @@ -243,10 +243,10 @@ mod tests { #[test] fn test_to_str() { let zerolen = bitv(0u, false); - assert to_str(zerolen) == ""; + assert to_str(zerolen) == ~""; let eightbits = bitv(8u, false); - assert to_str(eightbits) == "00000000"; + assert to_str(eightbits) == ~"00000000"; } #[test] diff --git a/src/libstd/ebml.rs b/src/libstd/ebml.rs index 69a4920a4ae..5f833a20e32 100644 --- a/src/libstd/ebml.rs +++ b/src/libstd/ebml.rs @@ -127,7 +127,7 @@ fn with_doc_data<T>(d: doc, f: fn(x: &[u8]) -> T) -> T { ret f(vec::slice::<u8>(*d.data, d.start, d.end)); } -fn doc_as_str(d: doc) -> str { ret str::from_bytes(doc_data(d)); } +fn doc_as_str(d: doc) -> ~str { ret str::from_bytes(doc_data(d)); } fn doc_as_u8(d: doc) -> u8 { assert d.end == d.start + 1u; @@ -271,7 +271,7 @@ impl writer for writer { self.wr_tagged_bytes(tag_id, &[v as u8]); } - fn wr_tagged_str(tag_id: uint, v: str) { + fn wr_tagged_str(tag_id: uint, v: ~str) { // Lame: can't use str::as_bytes() here because the resulting // vector is NULL-terminated. Annoyingly, the underlying // writer interface doesn't permit us to write a slice of a @@ -286,7 +286,7 @@ impl writer for writer { self.writer.write(b); } - fn wr_str(s: str) { + fn wr_str(s: ~str) { #debug["Write str: %?", s]; self.writer.write(str::bytes(s)); } @@ -320,7 +320,7 @@ impl serializer of serialization::serializer for ebml::writer { self.wr_tagged_u32(t as uint, v as u32); } - fn _emit_label(label: str) { + fn _emit_label(label: ~str) { // There are various strings that we have access to, such as // the name of a record field, which do not actually appear in // the serialized EBML (normally). This is just for @@ -345,17 +345,17 @@ impl serializer of serialization::serializer for ebml::writer { fn emit_bool(v: bool) { self.wr_tagged_u8(es_bool as uint, v as u8) } // FIXME (#2742): implement these - fn emit_f64(_v: f64) { fail "Unimplemented: serializing an f64"; } - fn emit_f32(_v: f32) { fail "Unimplemented: serializing an f32"; } - fn emit_float(_v: float) { fail "Unimplemented: serializing a float"; } + fn emit_f64(_v: f64) { fail ~"Unimplemented: serializing an f64"; } + fn emit_f32(_v: f32) { fail ~"Unimplemented: serializing an f32"; } + fn emit_float(_v: float) { fail ~"Unimplemented: serializing a float"; } - fn emit_str(v: str) { self.wr_tagged_str(es_str as uint, v) } + fn emit_str(v: ~str) { self.wr_tagged_str(es_str as uint, v) } - fn emit_enum(name: str, f: fn()) { + fn emit_enum(name: ~str, f: fn()) { self._emit_label(name); self.wr_tag(es_enum as uint, f) } - fn emit_enum_variant(_v_name: str, v_id: uint, _cnt: uint, f: fn()) { + fn emit_enum_variant(_v_name: ~str, v_id: uint, _cnt: uint, f: fn()) { self._emit_tagged_uint(es_enum_vid, v_id); self.wr_tag(es_enum_body as uint, f) } @@ -375,7 +375,7 @@ impl serializer of serialization::serializer for ebml::writer { fn emit_box(f: fn()) { f() } fn emit_uniq(f: fn()) { f() } fn emit_rec(f: fn()) { f() } - fn emit_rec_field(f_name: str, _f_idx: uint, f: fn()) { + fn emit_rec_field(f_name: ~str, _f_idx: uint, f: fn()) { self._emit_label(f_name); f() } @@ -391,7 +391,7 @@ fn ebml_deserializer(d: ebml::doc) -> ebml_deserializer { } impl deserializer of serialization::deserializer for ebml_deserializer { - fn _check_label(lbl: str) { + fn _check_label(lbl: ~str) { if self.pos < self.parent.end { let {tag: r_tag, doc: r_doc} = ebml::doc_at(self.parent.data, self.pos); @@ -408,7 +408,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer { fn next_doc(exp_tag: ebml_serializer_tag) -> ebml::doc { #debug[". next_doc(exp_tag=%?)", exp_tag]; if self.pos >= self.parent.end { - fail "no more documents in current node!"; + fail ~"no more documents in current node!"; } let {tag: r_tag, doc: r_doc} = ebml::doc_at(self.parent.data, self.pos); @@ -472,14 +472,14 @@ impl deserializer of serialization::deserializer for ebml_deserializer { fn read_bool() -> bool { ebml::doc_as_u8(self.next_doc(es_bool)) as bool } - fn read_f64() -> f64 { fail "read_f64()"; } - fn read_f32() -> f32 { fail "read_f32()"; } - fn read_float() -> float { fail "read_float()"; } + fn read_f64() -> f64 { fail ~"read_f64()"; } + fn read_f32() -> f32 { fail ~"read_f32()"; } + fn read_float() -> float { fail ~"read_float()"; } - fn read_str() -> str { ebml::doc_as_str(self.next_doc(es_str)) } + fn read_str() -> ~str { ebml::doc_as_str(self.next_doc(es_str)) } // Compound types: - fn read_enum<T:copy>(name: str, f: fn() -> T) -> T { + fn read_enum<T:copy>(name: ~str, f: fn() -> T) -> T { #debug["read_enum(%s)", name]; self._check_label(name); self.push_doc(self.next_doc(es_enum), f) @@ -528,7 +528,7 @@ impl deserializer of serialization::deserializer for ebml_deserializer { f() } - fn read_rec_field<T:copy>(f_name: str, f_idx: uint, f: fn() -> T) -> T { + fn read_rec_field<T:copy>(f_name: ~str, f_idx: uint, f: fn() -> T) -> T { #debug["read_rec_field(%s, idx=%u)", f_name, f_idx]; self._check_label(f_name); f() @@ -556,13 +556,13 @@ fn test_option_int() { } fn serialize_0<S: serialization::serializer>(s: S, v: option<int>) { - do s.emit_enum("core::option::t") { + do s.emit_enum(~"core::option::t") { alt v { none { - s.emit_enum_variant("core::option::none", 0u, 0u, || { } ); + s.emit_enum_variant(~"core::option::none", 0u, 0u, || { } ); } some(v0) { - do s.emit_enum_variant("core::option::some", 1u, 1u) { + do s.emit_enum_variant(~"core::option::some", 1u, 1u) { s.emit_enum_variant_arg(0u, || serialize_1(s, v0)); } } @@ -575,7 +575,7 @@ fn test_option_int() { } fn deserialize_0<S: serialization::deserializer>(s: S) -> option<int> { - do s.read_enum("core::option::t") { + do s.read_enum(~"core::option::t") { do s.read_enum_variant |i| { alt check i { 0u { none } diff --git a/src/libstd/getopts.rs b/src/libstd/getopts.rs index e6df8e1d898..8ba2dc16b76 100644 --- a/src/libstd/getopts.rs +++ b/src/libstd/getopts.rs @@ -84,7 +84,7 @@ export opt_maybe_str; export opt_default; export result; //NDM -enum name { long(str), short(char), } +enum name { long(~str), short(char), } enum hasarg { yes, no, maybe, } @@ -93,29 +93,29 @@ enum occur { req, optional, multi, } /// A description of a possible option type opt = {name: name, hasarg: hasarg, occur: occur}; -fn mkname(nm: str) -> name { +fn mkname(nm: ~str) -> name { ret if str::len(nm) == 1u { short(str::char_at(nm, 0u)) } else { long(nm) }; } /// Create an option that is required and takes an argument -fn reqopt(name: str) -> opt { +fn reqopt(name: ~str) -> opt { ret {name: mkname(name), hasarg: yes, occur: req}; } /// Create an option that is optional and takes an argument -fn optopt(name: str) -> opt { +fn optopt(name: ~str) -> opt { ret {name: mkname(name), hasarg: yes, occur: optional}; } /// Create an option that is optional and does not take an argument -fn optflag(name: str) -> opt { +fn optflag(name: ~str) -> opt { ret {name: mkname(name), hasarg: no, occur: optional}; } /// Create an option that is optional and takes an optional argument -fn optflagopt(name: str) -> opt { +fn optflagopt(name: ~str) -> opt { ret {name: mkname(name), hasarg: maybe, occur: optional}; } @@ -123,23 +123,23 @@ fn optflagopt(name: str) -> opt { * Create an option that is optional, takes an argument, and may occur * multiple times */ -fn optmulti(name: str) -> opt { +fn optmulti(name: ~str) -> opt { ret {name: mkname(name), hasarg: yes, occur: multi}; } -enum optval { val(str), given, } +enum optval { val(~str), given, } /** * The result of checking command line arguments. Contains a vector * of matches and a vector of free strings. */ -type match = {opts: ~[opt], vals: ~[~[optval]], free: ~[str]}; +type match = {opts: ~[opt], vals: ~[~[optval]], free: ~[~str]}; -fn is_arg(arg: str) -> bool { +fn is_arg(arg: ~str) -> bool { ret str::len(arg) > 1u && arg[0] == '-' as u8; } -fn name_str(nm: name) -> str { +fn name_str(nm: name) -> ~str { ret alt nm { short(ch) { str::from_char(ch) } long(s) { s } }; } @@ -152,24 +152,26 @@ fn find_opt(opts: ~[opt], nm: name) -> option<uint> { * expected format. Pass this value to <fail_str> to get an error message. */ enum fail_ { - argument_missing(str), - unrecognized_option(str), - option_missing(str), - option_duplicated(str), - unexpected_argument(str), + argument_missing(~str), + unrecognized_option(~str), + option_missing(~str), + option_duplicated(~str), + unexpected_argument(~str), } /// Convert a `fail_` enum into an error string -fn fail_str(f: fail_) -> str { +fn fail_str(f: fail_) -> ~str { ret alt f { - argument_missing(nm) { "Argument to option '" + nm + "' missing." } - unrecognized_option(nm) { "Unrecognized option: '" + nm + "'." } - option_missing(nm) { "Required option '" + nm + "' missing." } + argument_missing(nm) { + ~"Argument to option '" + nm + ~"' missing." + } + unrecognized_option(nm) { ~"Unrecognized option: '" + nm + ~"'." } + option_missing(nm) { ~"Required option '" + nm + ~"' missing." } option_duplicated(nm) { - "Option '" + nm + "' given more than once." + ~"Option '" + nm + ~"' given more than once." } unexpected_argument(nm) { - "Option " + nm + " does not take an argument." + ~"Option " + nm + ~" does not take an argument." } }; } @@ -187,11 +189,11 @@ type result = result::result<match, fail_>; * `opt_str`, etc. to interrogate results. Returns `err(fail_)` on failure. * Use <fail_str> to get an error message. */ -fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe { +fn getopts(args: ~[~str], opts: ~[opt]) -> result unsafe { let n_opts = vec::len::<opt>(opts); fn f(_x: uint) -> ~[optval] { ret ~[]; } let vals = vec::to_mut(vec::from_fn(n_opts, f)); - let mut free: ~[str] = ~[]; + let mut free: ~[~str] = ~[]; let l = vec::len(args); let mut i = 0u; while i < l { @@ -199,13 +201,13 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe { let curlen = str::len(cur); if !is_arg(cur) { vec::push(free, cur); - } else if str::eq(cur, "--") { + } else if str::eq(cur, ~"--") { let mut j = i + 1u; while j < l { vec::push(free, args[j]); j += 1u; } break; } else { let mut names; - let mut i_arg = option::none::<str>; + let mut i_arg = option::none::<~str>; if cur[1] == '-' as u8 { let tail = str::slice(cur, 2u, curlen); let tail_eq = str::splitn_char(tail, '=', 1u); @@ -215,7 +217,7 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe { names = ~[long(tail_eq[0])]; i_arg = - option::some::<str>(tail_eq[1]); + option::some::<~str>(tail_eq[1]); } } else { let mut j = 1u; @@ -264,13 +266,13 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe { }; alt opts[optid].hasarg { no { - if !option::is_none::<str>(i_arg) { + if !option::is_none::<~str>(i_arg) { ret err(unexpected_argument(name_str(nm))); } vec::push(vals[optid], given); } maybe { - if !option::is_none::<str>(i_arg) { + if !option::is_none::<~str>(i_arg) { vec::push(vals[optid], val(option::get(i_arg))); } else if name_pos < vec::len::<name>(names) || i + 1u == l || is_arg(args[i + 1u]) { @@ -278,9 +280,9 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe { } else { i += 1u; vec::push(vals[optid], val(args[i])); } } yes { - if !option::is_none::<str>(i_arg) { + if !option::is_none::<~str>(i_arg) { vec::push(vals[optid], - val(option::get::<str>(i_arg))); + val(option::get::<~str>(i_arg))); } else if i + 1u == l { ret err(argument_missing(name_str(nm))); } else { i += 1u; vec::push(vals[optid], val(args[i])); } @@ -309,22 +311,22 @@ fn getopts(args: ~[str], opts: ~[opt]) -> result unsafe { ret ok({opts: opts, vals: vec::from_mut(vals), free: free}); } -fn opt_vals(m: match, nm: str) -> ~[optval] { +fn opt_vals(m: match, nm: ~str) -> ~[optval] { ret alt find_opt(m.opts, mkname(nm)) { some(id) { m.vals[id] } none { #error("No option '%s' defined", nm); fail } }; } -fn opt_val(m: match, nm: str) -> optval { ret opt_vals(m, nm)[0]; } +fn opt_val(m: match, nm: ~str) -> optval { ret opt_vals(m, nm)[0]; } /// Returns true if an option was matched -fn opt_present(m: match, nm: str) -> bool { +fn opt_present(m: match, nm: ~str) -> bool { ret vec::len::<optval>(opt_vals(m, nm)) > 0u; } /// Returns true if any of several options were matched -fn opts_present(m: match, names: ~[str]) -> bool { +fn opts_present(m: match, names: ~[~str]) -> bool { for vec::each(names) |nm| { alt find_opt(m.opts, mkname(nm)) { some(_) { ret true; } @@ -341,7 +343,7 @@ fn opts_present(m: match, names: ~[str]) -> bool { * Fails if the option was not matched or if the match did not take an * argument */ -fn opt_str(m: match, nm: str) -> str { +fn opt_str(m: match, nm: ~str) -> ~str { ret alt opt_val(m, nm) { val(s) { s } _ { fail } }; } @@ -351,7 +353,7 @@ fn opt_str(m: match, nm: str) -> str { * Fails if the no option was provided from the given list, or if the no such * option took an argument */ -fn opts_str(m: match, names: ~[str]) -> str { +fn opts_str(m: match, names: ~[~str]) -> ~str { for vec::each(names) |nm| { alt opt_val(m, nm) { val(s) { ret s } @@ -368,8 +370,8 @@ fn opts_str(m: match, names: ~[str]) -> str { * * Used when an option accepts multiple values. */ -fn opt_strs(m: match, nm: str) -> ~[str] { - let mut acc: ~[str] = ~[]; +fn opt_strs(m: match, nm: ~str) -> ~[~str] { + let mut acc: ~[~str] = ~[]; for vec::each(opt_vals(m, nm)) |v| { alt v { val(s) { vec::push(acc, s); } _ { } } } @@ -377,10 +379,10 @@ fn opt_strs(m: match, nm: str) -> ~[str] { } /// Returns the string argument supplied to a matching option or none -fn opt_maybe_str(m: match, nm: str) -> option<str> { +fn opt_maybe_str(m: match, nm: ~str) -> option<~str> { let vals = opt_vals(m, nm); - if vec::len::<optval>(vals) == 0u { ret none::<str>; } - ret alt vals[0] { val(s) { some::<str>(s) } _ { none::<str> } }; + if vec::len::<optval>(vals) == 0u { ret none::<~str>; } + ret alt vals[0] { val(s) { some::<~str>(s) } _ { none::<~str> } }; } @@ -391,10 +393,10 @@ fn opt_maybe_str(m: match, nm: str) -> option<str> { * present but no argument was provided, and the argument if the option was * present and an argument was provided. */ -fn opt_default(m: match, nm: str, def: str) -> option<str> { +fn opt_default(m: match, nm: ~str, def: ~str) -> option<~str> { let vals = opt_vals(m, nm); - if vec::len::<optval>(vals) == 0u { ret none::<str>; } - ret alt vals[0] { val(s) { some::<str>(s) } _ { some::<str>(def) } } + if vec::len::<optval>(vals) == 0u { ret none::<~str>; } + ret alt vals[0] { val(s) { some::<~str>(s) } _ { some::<~str>(def) } } } #[cfg(test)] @@ -424,21 +426,21 @@ mod tests { // Tests for reqopt #[test] fn test_reqopt_long() { - let args = ~["--test=20"]; - let opts = ~[reqopt("test")]; + let args = ~[~"--test=20"]; + let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt check rs { ok(m) { - assert (opt_present(m, "test")); - assert (opt_str(m, "test") == "20"); + assert (opt_present(m, ~"test")); + assert (opt_str(m, ~"test") == ~"20"); } } } #[test] fn test_reqopt_long_missing() { - let args = ~["blah"]; - let opts = ~[reqopt("test")]; + let args = ~[~"blah"]; + let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_missing_); } @@ -448,8 +450,8 @@ mod tests { #[test] fn test_reqopt_long_no_arg() { - let args = ~["--test"]; - let opts = ~[reqopt("test")]; + let args = ~[~"--test"]; + let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, argument_missing_); } @@ -459,8 +461,8 @@ mod tests { #[test] fn test_reqopt_long_multi() { - let args = ~["--test=20", "--test=30"]; - let opts = ~[reqopt("test")]; + let args = ~[~"--test=20", ~"--test=30"]; + let opts = ~[reqopt(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_duplicated_); } @@ -470,13 +472,13 @@ mod tests { #[test] fn test_reqopt_short() { - let args = ~["-t", "20"]; - let opts = ~[reqopt("t")]; + let args = ~[~"-t", ~"20"]; + let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "t")); - assert (opt_str(m, "t") == "20"); + assert (opt_present(m, ~"t")); + assert (opt_str(m, ~"t") == ~"20"); } _ { fail; } } @@ -484,8 +486,8 @@ mod tests { #[test] fn test_reqopt_short_missing() { - let args = ~["blah"]; - let opts = ~[reqopt("t")]; + let args = ~[~"blah"]; + let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_missing_); } @@ -495,8 +497,8 @@ mod tests { #[test] fn test_reqopt_short_no_arg() { - let args = ~["-t"]; - let opts = ~[reqopt("t")]; + let args = ~[~"-t"]; + let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, argument_missing_); } @@ -506,8 +508,8 @@ mod tests { #[test] fn test_reqopt_short_multi() { - let args = ~["-t", "20", "-t", "30"]; - let opts = ~[reqopt("t")]; + let args = ~[~"-t", ~"20", ~"-t", ~"30"]; + let opts = ~[reqopt(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_duplicated_); } @@ -519,13 +521,13 @@ mod tests { // Tests for optopt #[test] fn test_optopt_long() { - let args = ~["--test=20"]; - let opts = ~[optopt("test")]; + let args = ~[~"--test=20"]; + let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "test")); - assert (opt_str(m, "test") == "20"); + assert (opt_present(m, ~"test")); + assert (opt_str(m, ~"test") == ~"20"); } _ { fail; } } @@ -533,19 +535,19 @@ mod tests { #[test] fn test_optopt_long_missing() { - let args = ~["blah"]; - let opts = ~[optopt("test")]; + let args = ~[~"blah"]; + let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, "test")); } + ok(m) { assert (!opt_present(m, ~"test")); } _ { fail; } } } #[test] fn test_optopt_long_no_arg() { - let args = ~["--test"]; - let opts = ~[optopt("test")]; + let args = ~[~"--test"]; + let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, argument_missing_); } @@ -555,8 +557,8 @@ mod tests { #[test] fn test_optopt_long_multi() { - let args = ~["--test=20", "--test=30"]; - let opts = ~[optopt("test")]; + let args = ~[~"--test=20", ~"--test=30"]; + let opts = ~[optopt(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_duplicated_); } @@ -566,13 +568,13 @@ mod tests { #[test] fn test_optopt_short() { - let args = ~["-t", "20"]; - let opts = ~[optopt("t")]; + let args = ~[~"-t", ~"20"]; + let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "t")); - assert (opt_str(m, "t") == "20"); + assert (opt_present(m, ~"t")); + assert (opt_str(m, ~"t") == ~"20"); } _ { fail; } } @@ -580,19 +582,19 @@ mod tests { #[test] fn test_optopt_short_missing() { - let args = ~["blah"]; - let opts = ~[optopt("t")]; + let args = ~[~"blah"]; + let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, "t")); } + ok(m) { assert (!opt_present(m, ~"t")); } _ { fail; } } } #[test] fn test_optopt_short_no_arg() { - let args = ~["-t"]; - let opts = ~[optopt("t")]; + let args = ~[~"-t"]; + let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, argument_missing_); } @@ -602,8 +604,8 @@ mod tests { #[test] fn test_optopt_short_multi() { - let args = ~["-t", "20", "-t", "30"]; - let opts = ~[optopt("t")]; + let args = ~[~"-t", ~"20", ~"-t", ~"30"]; + let opts = ~[optopt(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_duplicated_); } @@ -615,30 +617,30 @@ mod tests { // Tests for optflag #[test] fn test_optflag_long() { - let args = ~["--test"]; - let opts = ~[optflag("test")]; + let args = ~[~"--test"]; + let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (opt_present(m, "test")); } + ok(m) { assert (opt_present(m, ~"test")); } _ { fail; } } } #[test] fn test_optflag_long_missing() { - let args = ~["blah"]; - let opts = ~[optflag("test")]; + let args = ~[~"blah"]; + let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, "test")); } + ok(m) { assert (!opt_present(m, ~"test")); } _ { fail; } } } #[test] fn test_optflag_long_arg() { - let args = ~["--test=20"]; - let opts = ~[optflag("test")]; + let args = ~[~"--test=20"]; + let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { @@ -651,8 +653,8 @@ mod tests { #[test] fn test_optflag_long_multi() { - let args = ~["--test", "--test"]; - let opts = ~[optflag("test")]; + let args = ~[~"--test", ~"--test"]; + let opts = ~[optflag(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_duplicated_); } @@ -662,36 +664,36 @@ mod tests { #[test] fn test_optflag_short() { - let args = ~["-t"]; - let opts = ~[optflag("t")]; + let args = ~[~"-t"]; + let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (opt_present(m, "t")); } + ok(m) { assert (opt_present(m, ~"t")); } _ { fail; } } } #[test] fn test_optflag_short_missing() { - let args = ~["blah"]; - let opts = ~[optflag("t")]; + let args = ~[~"blah"]; + let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, "t")); } + ok(m) { assert (!opt_present(m, ~"t")); } _ { fail; } } } #[test] fn test_optflag_short_arg() { - let args = ~["-t", "20"]; - let opts = ~[optflag("t")]; + let args = ~[~"-t", ~"20"]; + let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { ok(m) { // The next variable after the flag is just a free argument - assert (m.free[0] == "20"); + assert (m.free[0] == ~"20"); } _ { fail; } } @@ -699,8 +701,8 @@ mod tests { #[test] fn test_optflag_short_multi() { - let args = ~["-t", "-t"]; - let opts = ~[optflag("t")]; + let args = ~[~"-t", ~"-t"]; + let opts = ~[optflag(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, option_duplicated_); } @@ -712,13 +714,13 @@ mod tests { // Tests for optmulti #[test] fn test_optmulti_long() { - let args = ~["--test=20"]; - let opts = ~[optmulti("test")]; + let args = ~[~"--test=20"]; + let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "test")); - assert (opt_str(m, "test") == "20"); + assert (opt_present(m, ~"test")); + assert (opt_str(m, ~"test") == ~"20"); } _ { fail; } } @@ -726,19 +728,19 @@ mod tests { #[test] fn test_optmulti_long_missing() { - let args = ~["blah"]; - let opts = ~[optmulti("test")]; + let args = ~[~"blah"]; + let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, "test")); } + ok(m) { assert (!opt_present(m, ~"test")); } _ { fail; } } } #[test] fn test_optmulti_long_no_arg() { - let args = ~["--test"]; - let opts = ~[optmulti("test")]; + let args = ~[~"--test"]; + let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, argument_missing_); } @@ -748,15 +750,15 @@ mod tests { #[test] fn test_optmulti_long_multi() { - let args = ~["--test=20", "--test=30"]; - let opts = ~[optmulti("test")]; + let args = ~[~"--test=20", ~"--test=30"]; + let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "test")); - assert (opt_str(m, "test") == "20"); - assert (opt_strs(m, "test")[0] == "20"); - assert (opt_strs(m, "test")[1] == "30"); + assert (opt_present(m, ~"test")); + assert (opt_str(m, ~"test") == ~"20"); + assert (opt_strs(m, ~"test")[0] == ~"20"); + assert (opt_strs(m, ~"test")[1] == ~"30"); } _ { fail; } } @@ -764,13 +766,13 @@ mod tests { #[test] fn test_optmulti_short() { - let args = ~["-t", "20"]; - let opts = ~[optmulti("t")]; + let args = ~[~"-t", ~"20"]; + let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "t")); - assert (opt_str(m, "t") == "20"); + assert (opt_present(m, ~"t")); + assert (opt_str(m, ~"t") == ~"20"); } _ { fail; } } @@ -778,19 +780,19 @@ mod tests { #[test] fn test_optmulti_short_missing() { - let args = ~["blah"]; - let opts = ~[optmulti("t")]; + let args = ~[~"blah"]; + let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { - ok(m) { assert (!opt_present(m, "t")); } + ok(m) { assert (!opt_present(m, ~"t")); } _ { fail; } } } #[test] fn test_optmulti_short_no_arg() { - let args = ~["-t"]; - let opts = ~[optmulti("t")]; + let args = ~[~"-t"]; + let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, argument_missing_); } @@ -800,15 +802,15 @@ mod tests { #[test] fn test_optmulti_short_multi() { - let args = ~["-t", "20", "-t", "30"]; - let opts = ~[optmulti("t")]; + let args = ~[~"-t", ~"20", ~"-t", ~"30"]; + let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (opt_present(m, "t")); - assert (opt_str(m, "t") == "20"); - assert (opt_strs(m, "t")[0] == "20"); - assert (opt_strs(m, "t")[1] == "30"); + assert (opt_present(m, ~"t")); + assert (opt_str(m, ~"t") == ~"20"); + assert (opt_strs(m, ~"t")[0] == ~"20"); + assert (opt_strs(m, ~"t")[1] == ~"30"); } _ { fail; } } @@ -816,8 +818,8 @@ mod tests { #[test] fn test_unrecognized_option_long() { - let args = ~["--untest"]; - let opts = ~[optmulti("t")]; + let args = ~[~"--untest"]; + let opts = ~[optmulti(~"t")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, unrecognized_option_); } @@ -827,8 +829,8 @@ mod tests { #[test] fn test_unrecognized_option_short() { - let args = ~["-t"]; - let opts = ~[optmulti("test")]; + let args = ~[~"-t"]; + let opts = ~[optmulti(~"test")]; let rs = getopts(args, opts); alt rs { err(f) { check_fail_type(f, unrecognized_option_); } @@ -839,27 +841,28 @@ mod tests { #[test] fn test_combined() { let args = - ~["prog", "free1", "-s", "20", "free2", "--flag", "--long=30", - "-f", "-m", "40", "-m", "50", "-n", "-A B", "-n", "-60 70"]; + ~[~"prog", ~"free1", ~"-s", ~"20", ~"free2", + ~"--flag", ~"--long=30", ~"-f", ~"-m", ~"40", + ~"-m", ~"50", ~"-n", ~"-A B", ~"-n", ~"-60 70"]; let opts = - ~[optopt("s"), optflag("flag"), reqopt("long"), - optflag("f"), optmulti("m"), optmulti("n"), - optopt("notpresent")]; + ~[optopt(~"s"), optflag(~"flag"), reqopt(~"long"), + optflag(~"f"), optmulti(~"m"), optmulti(~"n"), + optopt(~"notpresent")]; let rs = getopts(args, opts); alt rs { ok(m) { - assert (m.free[0] == "prog"); - assert (m.free[1] == "free1"); - assert (opt_str(m, "s") == "20"); - assert (m.free[2] == "free2"); - assert (opt_present(m, "flag")); - assert (opt_str(m, "long") == "30"); - assert (opt_present(m, "f")); - assert (opt_strs(m, "m")[0] == "40"); - assert (opt_strs(m, "m")[1] == "50"); - assert (opt_strs(m, "n")[0] == "-A B"); - assert (opt_strs(m, "n")[1] == "-60 70"); - assert (!opt_present(m, "notpresent")); + assert (m.free[0] == ~"prog"); + assert (m.free[1] == ~"free1"); + assert (opt_str(m, ~"s") == ~"20"); + assert (m.free[2] == ~"free2"); + assert (opt_present(m, ~"flag")); + assert (opt_str(m, ~"long") == ~"30"); + assert (opt_present(m, ~"f")); + assert (opt_strs(m, ~"m")[0] == ~"40"); + assert (opt_strs(m, ~"m")[1] == ~"50"); + assert (opt_strs(m, ~"n")[0] == ~"-A B"); + assert (opt_strs(m, ~"n")[1] == ~"-60 70"); + assert (!opt_present(m, ~"notpresent")); } _ { fail; } } @@ -867,35 +870,35 @@ mod tests { #[test] fn test_multi() { - let args = ~["-e", "foo", "--encrypt", "foo"]; - let opts = ~[optopt("e"), optopt("encrypt")]; + let args = ~[~"-e", ~"foo", ~"--encrypt", ~"foo"]; + let opts = ~[optopt(~"e"), optopt(~"encrypt")]; let match = alt getopts(args, opts) { result::ok(m) { m } result::err(f) { fail; } }; - assert opts_present(match, ~["e"]); - assert opts_present(match, ~["encrypt"]); - assert opts_present(match, ~["encrypt", "e"]); - assert opts_present(match, ~["e", "encrypt"]); - assert !opts_present(match, ~["thing"]); + assert opts_present(match, ~[~"e"]); + assert opts_present(match, ~[~"encrypt"]); + assert opts_present(match, ~[~"encrypt", ~"e"]); + assert opts_present(match, ~[~"e", ~"encrypt"]); + assert !opts_present(match, ~[~"thing"]); assert !opts_present(match, ~[]); - assert opts_str(match, ~["e"]) == "foo"; - assert opts_str(match, ~["encrypt"]) == "foo"; - assert opts_str(match, ~["e", "encrypt"]) == "foo"; - assert opts_str(match, ~["encrypt", "e"]) == "foo"; + assert opts_str(match, ~[~"e"]) == ~"foo"; + assert opts_str(match, ~[~"encrypt"]) == ~"foo"; + assert opts_str(match, ~[~"e", ~"encrypt"]) == ~"foo"; + assert opts_str(match, ~[~"encrypt", ~"e"]) == ~"foo"; } #[test] fn test_nospace() { - let args = ~["-Lfoo"]; - let opts = ~[optmulti("L")]; + let args = ~[~"-Lfoo"]; + let opts = ~[optmulti(~"L")]; let match = alt getopts(args, opts) { result::ok(m) { m } result::err(f) { fail; } }; - assert opts_present(match, ~["L"]); - assert opts_str(match, ~["L"]) == "foo"; + assert opts_present(match, ~[~"L"]); + assert opts_str(match, ~[~"L"]) == ~"foo"; } } diff --git a/src/libstd/json.rs b/src/libstd/json.rs index eab42a52b59..f8194204626 100644 --- a/src/libstd/json.rs +++ b/src/libstd/json.rs @@ -29,17 +29,17 @@ export null; /// Represents a json value enum json { num(float), - string(@str/~), + string(@~str), boolean(bool), list(@~[json]), - dict(map::hashmap<str, json>), + dict(map::hashmap<~str, json>), null, } type error = { line: uint, col: uint, - msg: @str/~, + msg: @~str, }; /// Serializes a json value into a io::writer @@ -50,14 +50,14 @@ fn to_writer(wr: io::writer, j: json) { wr.write_str(escape_str(*s)); } boolean(b) { - wr.write_str(if b { "true" } else { "false" }); + wr.write_str(if b { ~"true" } else { ~"false" }); } list(v) { wr.write_char('['); let mut first = true; for (*v).each |item| { if !first { - wr.write_str(", "); + wr.write_str(~", "); } first = false; to_writer(wr, item); @@ -66,51 +66,51 @@ fn to_writer(wr: io::writer, j: json) { } dict(d) { if d.size() == 0u { - wr.write_str("{}"); + wr.write_str(~"{}"); ret; } - wr.write_str("{ "); + wr.write_str(~"{ "); let mut first = true; for d.each |key, value| { if !first { - wr.write_str(", "); + wr.write_str(~", "); } first = false; wr.write_str(escape_str(key)); - wr.write_str(": "); + wr.write_str(~": "); to_writer(wr, value); }; - wr.write_str(" }"); + wr.write_str(~" }"); } null { - wr.write_str("null"); + wr.write_str(~"null"); } } } -fn escape_str(s: str) -> str { - let mut escaped = "\""; +fn escape_str(s: ~str) -> ~str { + let mut escaped = ~"\""; do str::chars_iter(s) |c| { alt c { - '"' { escaped += "\\\""; } - '\\' { escaped += "\\\\"; } - '\x08' { escaped += "\\b"; } - '\x0c' { escaped += "\\f"; } - '\n' { escaped += "\\n"; } - '\r' { escaped += "\\r"; } - '\t' { escaped += "\\t"; } + '"' { escaped += ~"\\\""; } + '\\' { escaped += ~"\\\\"; } + '\x08' { escaped += ~"\\b"; } + '\x0c' { escaped += ~"\\f"; } + '\n' { escaped += ~"\\n"; } + '\r' { escaped += ~"\\r"; } + '\t' { escaped += ~"\\t"; } _ { escaped += str::from_char(c); } } }; - escaped += "\""; + escaped += ~"\""; escaped } /// Serializes a json value into a string -fn to_str(j: json) -> str { +fn to_str(j: json) -> ~str { io::with_str_writer(|wr| to_writer(wr, j)) } @@ -140,7 +140,7 @@ impl parser for parser { self.ch } - fn error<T>(+msg: str) -> result<T, error> { + fn error<T>(+msg: ~str) -> result<T, error> { err({ line: self.line, col: self.col, msg: @msg }) } @@ -153,7 +153,7 @@ impl parser for parser { if self.eof() { ok(value) } else { - self.error("trailing characters") + self.error(~"trailing characters") } } e { e } @@ -163,12 +163,12 @@ impl parser for parser { fn parse_value() -> result<json, error> { self.parse_whitespace(); - if self.eof() { ret self.error("EOF while parsing value"); } + if self.eof() { ret self.error(~"EOF while parsing value"); } alt self.ch { - 'n' { self.parse_ident("ull", null) } - 't' { self.parse_ident("rue", boolean(true)) } - 'f' { self.parse_ident("alse", boolean(false)) } + 'n' { self.parse_ident(~"ull", null) } + 't' { self.parse_ident(~"rue", boolean(true)) } + 'f' { self.parse_ident(~"alse", boolean(false)) } '0' to '9' | '-' { self.parse_number() } '"' { alt self.parse_str() { @@ -178,7 +178,7 @@ impl parser for parser { } '[' { self.parse_list() } '{' { self.parse_object() } - _ { self.error("invalid syntax") } + _ { self.error(~"invalid syntax") } } } @@ -186,12 +186,12 @@ impl parser for parser { while char::is_whitespace(self.ch) { self.bump(); } } - fn parse_ident(ident: str, value: json) -> result<json, error> { + fn parse_ident(ident: ~str, value: json) -> result<json, error> { if str::all(ident, |c| c == self.next_char()) { self.bump(); ok(value) } else { - self.error("invalid syntax") + self.error(~"invalid syntax") } } @@ -234,7 +234,7 @@ impl parser for parser { // There can be only one leading '0'. alt self.ch { - '0' to '9' { ret self.error("invalid number"); } + '0' to '9' { ret self.error(~"invalid number"); } _ {} } } @@ -251,7 +251,7 @@ impl parser for parser { } } } - _ { ret self.error("invalid number"); } + _ { ret self.error(~"invalid number"); } } ok(res) @@ -263,7 +263,7 @@ impl parser for parser { // Make sure a digit follows the decimal place. alt self.ch { '0' to '9' {} - _ { ret self.error("invalid number"); } + _ { ret self.error(~"invalid number"); } } let mut res = res; @@ -299,7 +299,7 @@ impl parser for parser { // Make sure a digit follows the exponent place. alt self.ch { '0' to '9' {} - _ { ret self.error("invalid number"); } + _ { ret self.error(~"invalid number"); } } while !self.eof() { @@ -324,9 +324,9 @@ impl parser for parser { ok(res) } - fn parse_str() -> result<@str/~, error> { + fn parse_str() -> result<@~str, error> { let mut escape = false; - let mut res = ""; + let mut res = ~""; while !self.eof() { self.bump(); @@ -351,19 +351,19 @@ impl parser for parser { n = n * 10u + (self.ch as uint) - ('0' as uint); } - _ { ret self.error("invalid \\u escape"); } + _ { ret self.error(~"invalid \\u escape"); } } i += 1u; } // Error out if we didn't parse 4 digits. if i != 4u { - ret self.error("invalid \\u escape"); + ret self.error(~"invalid \\u escape"); } str::push_char(res, n as char); } - _ { ret self.error("invalid escape"); } + _ { ret self.error(~"invalid escape"); } } escape = false; } else if self.ch == '\\' { @@ -377,7 +377,7 @@ impl parser for parser { } } - self.error("EOF while parsing string") + self.error(~"EOF while parsing string") } fn parse_list() -> result<json, error> { @@ -399,13 +399,13 @@ impl parser for parser { self.parse_whitespace(); if self.eof() { - ret self.error("EOF while parsing list"); + ret self.error(~"EOF while parsing list"); } alt self.ch { ',' { self.bump(); } ']' { self.bump(); ret ok(list(@values)); } - _ { ret self.error("expected `,` or `]`"); } + _ { ret self.error(~"expected `,` or `]`"); } } }; } @@ -425,7 +425,7 @@ impl parser for parser { self.parse_whitespace(); if self.ch != '"' { - ret self.error("key must be a string"); + ret self.error(~"key must be a string"); } let key = alt self.parse_str() { @@ -437,7 +437,7 @@ impl parser for parser { if self.ch != ':' { if self.eof() { break; } - ret self.error("expected `:`"); + ret self.error(~"expected `:`"); } self.bump(); @@ -452,12 +452,12 @@ impl parser for parser { '}' { self.bump(); ret ok(dict(values)); } _ { if self.eof() { break; } - ret self.error("expected `,` or `}`"); + ret self.error(~"expected `,` or `}`"); } } } - ret self.error("EOF while parsing object"); + ret self.error(~"EOF while parsing object"); } } @@ -474,7 +474,7 @@ fn from_reader(rdr: io::reader) -> result<json, error> { } /// Deserializes a json value from a string -fn from_str(s: str) -> result<json, error> { +fn from_str(s: ~str) -> result<json, error> { io::with_str_reader(s, from_reader) } @@ -575,11 +575,11 @@ impl of to_json for bool { fn to_json() -> json { boolean(self) } } -impl of to_json for str { +impl of to_json for ~str { fn to_json() -> json { string(@copy self) } } -impl of to_json for @str/~ { +impl of to_json for @~str { fn to_json() -> json { string(self) } } @@ -602,7 +602,7 @@ impl <A: to_json> of to_json for ~[A] { fn to_json() -> json { list(@self.map(|elt| elt.to_json())) } } -impl <A: to_json copy> of to_json for hashmap<str, A> { +impl <A: to_json copy> of to_json for hashmap<~str, A> { fn to_json() -> json { let d = map::str_hash(); for self.each() |key, value| { @@ -622,18 +622,18 @@ impl <A: to_json> of to_json for option<A> { } impl of to_str::to_str for json { - fn to_str() -> str { to_str(self) } + fn to_str() -> ~str { to_str(self) } } impl of to_str::to_str for error { - fn to_str() -> str { + fn to_str() -> ~str { #fmt("%u:%u: %s", self.line, self.col, *self.msg) } } #[cfg(test)] mod tests { - fn mk_dict(items: ~[(str, json)]) -> json { + fn mk_dict(items: ~[(~str, json)]) -> json { let d = map::str_hash(); do vec::iter(items) |item| { @@ -646,229 +646,230 @@ mod tests { #[test] fn test_write_null() { - assert to_str(null) == "null"; + assert to_str(null) == ~"null"; } #[test] fn test_write_num() { - assert to_str(num(3f)) == "3"; - assert to_str(num(3.1f)) == "3.1"; - assert to_str(num(-1.5f)) == "-1.5"; - assert to_str(num(0.5f)) == "0.5"; + assert to_str(num(3f)) == ~"3"; + assert to_str(num(3.1f)) == ~"3.1"; + assert to_str(num(-1.5f)) == ~"-1.5"; + assert to_str(num(0.5f)) == ~"0.5"; } #[test] fn test_write_str() { - assert to_str(string(@""/~)) == "\"\""/~; - assert to_str(string(@"foo"/~)) == "\"foo\""/~; + assert to_str(string(@~"")) == ~"\"\""; + assert to_str(string(@~"foo")) == ~"\"foo\""; } #[test] fn test_write_bool() { - assert to_str(boolean(true)) == "true"; - assert to_str(boolean(false)) == "false"; + assert to_str(boolean(true)) == ~"true"; + assert to_str(boolean(false)) == ~"false"; } #[test] fn test_write_list() { - assert to_str(list(@~[])) == "[]"; - assert to_str(list(@~[boolean(true)])) == "[true]"; + assert to_str(list(@~[])) == ~"[]"; + assert to_str(list(@~[boolean(true)])) == ~"[true]"; assert to_str(list(@~[ boolean(false), null, - list(@~[string(@"foo\nbar"/~), num(3.5f)]) - ])) == "[false, null, [\"foo\\nbar\", 3.5]]"; + list(@~[string(@~"foo\nbar"), num(3.5f)]) + ])) == ~"[false, null, [\"foo\\nbar\", 3.5]]"; } #[test] fn test_write_dict() { - assert to_str(mk_dict(~[])) == "{}"; - assert to_str(mk_dict(~[("a", boolean(true))])) == "{ \"a\": true }"; + assert to_str(mk_dict(~[])) == ~"{}"; + assert to_str(mk_dict(~[(~"a", boolean(true))])) + == ~"{ \"a\": true }"; assert to_str(mk_dict(~[ - ("a", boolean(true)), - ("b", list(@~[ - mk_dict(~[("c", string(@"\x0c\r"/~))]), - mk_dict(~[("d", string(@""/~))]) + (~"a", boolean(true)), + (~"b", list(@~[ + mk_dict(~[(~"c", string(@~"\x0c\r"))]), + mk_dict(~[(~"d", string(@~""))]) ])) ])) == - "{ " + - "\"a\": true, " + - "\"b\": [" + - "{ \"c\": \"\\f\\r\" }, " + - "{ \"d\": \"\" }" + - "]" + - " }"; + ~"{ " + + ~"\"a\": true, " + + ~"\"b\": [" + + ~"{ \"c\": \"\\f\\r\" }, " + + ~"{ \"d\": \"\" }" + + ~"]" + + ~" }"; } #[test] fn test_trailing_characters() { - assert from_str("nulla") == - err({line: 1u, col: 5u, msg: @"trailing characters"/~}); - assert from_str("truea") == - err({line: 1u, col: 5u, msg: @"trailing characters"/~}); - assert from_str("falsea") == - err({line: 1u, col: 6u, msg: @"trailing characters"/~}); - assert from_str("1a") == - err({line: 1u, col: 2u, msg: @"trailing characters"/~}); - assert from_str("[]a") == - err({line: 1u, col: 3u, msg: @"trailing characters"/~}); - assert from_str("{}a") == - err({line: 1u, col: 3u, msg: @"trailing characters"/~}); + assert from_str(~"nulla") == + err({line: 1u, col: 5u, msg: @~"trailing characters"}); + assert from_str(~"truea") == + err({line: 1u, col: 5u, msg: @~"trailing characters"}); + assert from_str(~"falsea") == + err({line: 1u, col: 6u, msg: @~"trailing characters"}); + assert from_str(~"1a") == + err({line: 1u, col: 2u, msg: @~"trailing characters"}); + assert from_str(~"[]a") == + err({line: 1u, col: 3u, msg: @~"trailing characters"}); + assert from_str(~"{}a") == + err({line: 1u, col: 3u, msg: @~"trailing characters"}); } #[test] fn test_read_identifiers() { - assert from_str("n") == - err({line: 1u, col: 2u, msg: @"invalid syntax"/~}); - assert from_str("nul") == - err({line: 1u, col: 4u, msg: @"invalid syntax"/~}); + assert from_str(~"n") == + err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + assert from_str(~"nul") == + err({line: 1u, col: 4u, msg: @~"invalid syntax"}); - assert from_str("t") == - err({line: 1u, col: 2u, msg: @"invalid syntax"/~}); - assert from_str("truz") == - err({line: 1u, col: 4u, msg: @"invalid syntax"/~}); + assert from_str(~"t") == + err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + assert from_str(~"truz") == + err({line: 1u, col: 4u, msg: @~"invalid syntax"}); - assert from_str("f") == - err({line: 1u, col: 2u, msg: @"invalid syntax"/~}); - assert from_str("faz") == - err({line: 1u, col: 3u, msg: @"invalid syntax"/~}); + assert from_str(~"f") == + err({line: 1u, col: 2u, msg: @~"invalid syntax"}); + assert from_str(~"faz") == + err({line: 1u, col: 3u, msg: @~"invalid syntax"}); - assert from_str("null") == ok(null); - assert from_str("true") == ok(boolean(true)); - assert from_str("false") == ok(boolean(false)); - assert from_str(" null ") == ok(null); - assert from_str(" true ") == ok(boolean(true)); - assert from_str(" false ") == ok(boolean(false)); + assert from_str(~"null") == ok(null); + assert from_str(~"true") == ok(boolean(true)); + assert from_str(~"false") == ok(boolean(false)); + assert from_str(~" null ") == ok(null); + assert from_str(~" true ") == ok(boolean(true)); + assert from_str(~" false ") == ok(boolean(false)); } #[test] fn test_read_num() { - assert from_str("+") == - err({line: 1u, col: 1u, msg: @"invalid syntax"/~}); - assert from_str(".") == - err({line: 1u, col: 1u, msg: @"invalid syntax"/~}); - - assert from_str("-") == - err({line: 1u, col: 2u, msg: @"invalid number"/~}); - assert from_str("00") == - err({line: 1u, col: 2u, msg: @"invalid number"/~}); - assert from_str("1.") == - err({line: 1u, col: 3u, msg: @"invalid number"/~}); - assert from_str("1e") == - err({line: 1u, col: 3u, msg: @"invalid number"/~}); - assert from_str("1e+") == - err({line: 1u, col: 4u, msg: @"invalid number"/~}); - - assert from_str("3") == ok(num(3f)); - assert from_str("3.1") == ok(num(3.1f)); - assert from_str("-1.2") == ok(num(-1.2f)); - assert from_str("0.4") == ok(num(0.4f)); - assert from_str("0.4e5") == ok(num(0.4e5f)); - assert from_str("0.4e+15") == ok(num(0.4e15f)); - assert from_str("0.4e-01") == ok(num(0.4e-01f)); - assert from_str(" 3 ") == ok(num(3f)); + assert from_str(~"+") == + err({line: 1u, col: 1u, msg: @~"invalid syntax"}); + assert from_str(~".") == + err({line: 1u, col: 1u, msg: @~"invalid syntax"}); + + assert from_str(~"-") == + err({line: 1u, col: 2u, msg: @~"invalid number"}); + assert from_str(~"00") == + err({line: 1u, col: 2u, msg: @~"invalid number"}); + assert from_str(~"1.") == + err({line: 1u, col: 3u, msg: @~"invalid number"}); + assert from_str(~"1e") == + err({line: 1u, col: 3u, msg: @~"invalid number"}); + assert from_str(~"1e+") == + err({line: 1u, col: 4u, msg: @~"invalid number"}); + + assert from_str(~"3") == ok(num(3f)); + assert from_str(~"3.1") == ok(num(3.1f)); + assert from_str(~"-1.2") == ok(num(-1.2f)); + assert from_str(~"0.4") == ok(num(0.4f)); + assert from_str(~"0.4e5") == ok(num(0.4e5f)); + assert from_str(~"0.4e+15") == ok(num(0.4e15f)); + assert from_str(~"0.4e-01") == ok(num(0.4e-01f)); + assert from_str(~" 3 ") == ok(num(3f)); } #[test] fn test_read_str() { - assert from_str("\"") == - err({line: 1u, col: 2u, msg: @"EOF while parsing string"/~}); - assert from_str("\"lol") == - err({line: 1u, col: 5u, msg: @"EOF while parsing string"/~}); + assert from_str(~"\"") == + err({line: 1u, col: 2u, msg: @~"EOF while parsing string"}); + assert from_str(~"\"lol") == + err({line: 1u, col: 5u, msg: @~"EOF while parsing string"}); - assert from_str("\"\"") == ok(string(@""/~)); - assert from_str("\"foo\"") == ok(string(@"foo"/~)); - assert from_str("\"\\\"\"") == ok(string(@"\""/~)); - assert from_str("\"\\b\"") == ok(string(@"\x08"/~)); - assert from_str("\"\\n\"") == ok(string(@"\n"/~)); - assert from_str("\"\\r\"") == ok(string(@"\r"/~)); - assert from_str("\"\\t\"") == ok(string(@"\t"/~)); - assert from_str(" \"foo\" ") == ok(string(@"foo"/~)); + assert from_str(~"\"\"") == ok(string(@~"")); + assert from_str(~"\"foo\"") == ok(string(@~"foo")); + assert from_str(~"\"\\\"\"") == ok(string(@~"\"")); + assert from_str(~"\"\\b\"") == ok(string(@~"\x08")); + assert from_str(~"\"\\n\"") == ok(string(@~"\n")); + assert from_str(~"\"\\r\"") == ok(string(@~"\r")); + assert from_str(~"\"\\t\"") == ok(string(@~"\t")); + assert from_str(~" \"foo\" ") == ok(string(@~"foo")); } #[test] fn test_read_list() { - assert from_str("[") == - err({line: 1u, col: 2u, msg: @"EOF while parsing value"/~}); - assert from_str("[1") == - err({line: 1u, col: 3u, msg: @"EOF while parsing list"/~}); - assert from_str("[1,") == - err({line: 1u, col: 4u, msg: @"EOF while parsing value"/~}); - assert from_str("[1,]") == - err({line: 1u, col: 4u, msg: @"invalid syntax"/~}); - assert from_str("[6 7]") == - err({line: 1u, col: 4u, msg: @"expected `,` or `]`"/~}); - - assert from_str("[]") == ok(list(@~[])); - assert from_str("[ ]") == ok(list(@~[])); - assert from_str("[true]") == ok(list(@~[boolean(true)])); - assert from_str("[ false ]") == ok(list(@~[boolean(false)])); - assert from_str("[null]") == ok(list(@~[null])); - assert from_str("[3, 1]") == ok(list(@~[num(3f), num(1f)])); - assert from_str("\n[3, 2]\n") == ok(list(@~[num(3f), num(2f)])); - assert from_str("[2, [4, 1]]") == + assert from_str(~"[") == + err({line: 1u, col: 2u, msg: @~"EOF while parsing value"}); + assert from_str(~"[1") == + err({line: 1u, col: 3u, msg: @~"EOF while parsing list"}); + assert from_str(~"[1,") == + err({line: 1u, col: 4u, msg: @~"EOF while parsing value"}); + assert from_str(~"[1,]") == + err({line: 1u, col: 4u, msg: @~"invalid syntax"}); + assert from_str(~"[6 7]") == + err({line: 1u, col: 4u, msg: @~"expected `,` or `]`"}); + + assert from_str(~"[]") == ok(list(@~[])); + assert from_str(~"[ ]") == ok(list(@~[])); + assert from_str(~"[true]") == ok(list(@~[boolean(true)])); + assert from_str(~"[ false ]") == ok(list(@~[boolean(false)])); + assert from_str(~"[null]") == ok(list(@~[null])); + assert from_str(~"[3, 1]") == ok(list(@~[num(3f), num(1f)])); + assert from_str(~"\n[3, 2]\n") == ok(list(@~[num(3f), num(2f)])); + assert from_str(~"[2, [4, 1]]") == ok(list(@~[num(2f), list(@~[num(4f), num(1f)])])); } #[test] fn test_read_dict() { - assert from_str("{") == - err({line: 1u, col: 2u, msg: @"EOF while parsing object"/~}); - assert from_str("{ ") == - err({line: 1u, col: 3u, msg: @"EOF while parsing object"/~}); - assert from_str("{1") == - err({line: 1u, col: 2u, msg: @"key must be a string"/~}); - assert from_str("{ \"a\"") == - err({line: 1u, col: 6u, msg: @"EOF while parsing object"/~}); - assert from_str("{\"a\"") == - err({line: 1u, col: 5u, msg: @"EOF while parsing object"/~}); - assert from_str("{\"a\" ") == - err({line: 1u, col: 6u, msg: @"EOF while parsing object"/~}); - - assert from_str("{\"a\" 1") == - err({line: 1u, col: 6u, msg: @"expected `:`"/~}); - assert from_str("{\"a\":") == - err({line: 1u, col: 6u, msg: @"EOF while parsing value"/~}); - assert from_str("{\"a\":1") == - err({line: 1u, col: 7u, msg: @"EOF while parsing object"/~}); - assert from_str("{\"a\":1 1") == - err({line: 1u, col: 8u, msg: @"expected `,` or `}`"/~}); - assert from_str("{\"a\":1,") == - err({line: 1u, col: 8u, msg: @"EOF while parsing object"/~}); - - assert eq(result::get(from_str("{}")), mk_dict(~[])); - assert eq(result::get(from_str("{\"a\": 3}")), - mk_dict(~[("a", num(3.0f))])); - - assert eq(result::get(from_str("{ \"a\": null, \"b\" : true }")), + assert from_str(~"{") == + err({line: 1u, col: 2u, msg: @~"EOF while parsing object"}); + assert from_str(~"{ ") == + err({line: 1u, col: 3u, msg: @~"EOF while parsing object"}); + assert from_str(~"{1") == + err({line: 1u, col: 2u, msg: @~"key must be a string"}); + assert from_str(~"{ \"a\"") == + err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); + assert from_str(~"{\"a\"") == + err({line: 1u, col: 5u, msg: @~"EOF while parsing object"}); + assert from_str(~"{\"a\" ") == + err({line: 1u, col: 6u, msg: @~"EOF while parsing object"}); + + assert from_str(~"{\"a\" 1") == + err({line: 1u, col: 6u, msg: @~"expected `:`"}); + assert from_str(~"{\"a\":") == + err({line: 1u, col: 6u, msg: @~"EOF while parsing value"}); + assert from_str(~"{\"a\":1") == + err({line: 1u, col: 7u, msg: @~"EOF while parsing object"}); + assert from_str(~"{\"a\":1 1") == + err({line: 1u, col: 8u, msg: @~"expected `,` or `}`"}); + assert from_str(~"{\"a\":1,") == + err({line: 1u, col: 8u, msg: @~"EOF while parsing object"}); + + assert eq(result::get(from_str(~"{}")), mk_dict(~[])); + assert eq(result::get(from_str(~"{\"a\": 3}")), + mk_dict(~[(~"a", num(3.0f))])); + + assert eq(result::get(from_str(~"{ \"a\": null, \"b\" : true }")), mk_dict(~[ - ("a", null), - ("b", boolean(true))])); - assert eq(result::get(from_str("\n{ \"a\": null, \"b\" : true }\n")), + (~"a", null), + (~"b", boolean(true))])); + assert eq(result::get(from_str(~"\n{ \"a\": null, \"b\" : true }\n")), mk_dict(~[ - ("a", null), - ("b", boolean(true))])); - assert eq(result::get(from_str("{\"a\" : 1.0 ,\"b\": [ true ]}")), + (~"a", null), + (~"b", boolean(true))])); + assert eq(result::get(from_str(~"{\"a\" : 1.0 ,\"b\": [ true ]}")), mk_dict(~[ - ("a", num(1.0)), - ("b", list(@~[boolean(true)])) + (~"a", num(1.0)), + (~"b", list(@~[boolean(true)])) ])); assert eq(result::get(from_str( - "{" + - "\"a\": 1.0, " + - "\"b\": [" + - "true," + - "\"foo\\nbar\", " + - "{ \"c\": {\"d\": null} } " + - "]" + - "}")), + ~"{" + + ~"\"a\": 1.0, " + + ~"\"b\": [" + + ~"true," + + ~"\"foo\\nbar\", " + + ~"{ \"c\": {\"d\": null} } " + + ~"]" + + ~"}")), mk_dict(~[ - ("a", num(1.0f)), - ("b", list(@~[ + (~"a", num(1.0f)), + (~"b", list(@~[ boolean(true), - string(@"foo\nbar"/~), + string(@~"foo\nbar"), mk_dict(~[ - ("c", mk_dict(~[("d", null)])) + (~"c", mk_dict(~[(~"d", null)])) ]) ])) ])); @@ -876,7 +877,7 @@ mod tests { #[test] fn test_multiline_errors() { - assert from_str("{\n \"foo\":\n \"bar\"") == - err({line: 3u, col: 8u, msg: @"EOF while parsing object"/~}); + assert from_str(~"{\n \"foo\":\n \"bar\"") == + err({line: 3u, col: 8u, msg: @~"EOF while parsing object"}); } } diff --git a/src/libstd/list.rs b/src/libstd/list.rs index 3a7b0ffd79a..46bb01250fe 100644 --- a/src/libstd/list.rs +++ b/src/libstd/list.rs @@ -85,7 +85,7 @@ fn len<T>(ls: @list<T>) -> uint { pure fn tail<T: copy>(ls: @list<T>) -> @list<T> { alt *ls { cons(_, tl) { ret tl; } - nil { fail "list empty" } + nil { fail ~"list empty" } } } diff --git a/src/libstd/map.rs b/src/libstd/map.rs index cc88a91bcf2..bce843224d1 100644 --- a/src/libstd/map.rs +++ b/src/libstd/map.rs @@ -237,7 +237,7 @@ mod chained { } fn get(k: K) -> V { - self.find(k).expect("Key not found in table") + self.find(k).expect(~"Key not found in table") } fn [](k: K) -> V { @@ -305,13 +305,13 @@ fn hashmap<K: const, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) } /// Construct a hashmap for string keys -fn str_hash<V: copy>() -> hashmap<str, V> { +fn str_hash<V: copy>() -> hashmap<~str, V> { ret hashmap(str::hash, str::eq); } /// Construct a hashmap for boxed string keys -fn box_str_hash<V: copy>() -> hashmap<@str/~, V> { - ret hashmap(|x: @str/~| str::hash(*x), |x,y| str::eq(*x,*y)); +fn box_str_hash<V: copy>() -> hashmap<@~str, V> { + ret hashmap(|x: @~str| str::hash(*x), |x,y| str::eq(*x,*y)); } /// Construct a hashmap for byte string keys @@ -356,7 +356,7 @@ fn hash_from_vec<K: const copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>, } /// Construct a hashmap from a vector with string keys -fn hash_from_strs<V: copy>(items: ~[(str, V)]) -> hashmap<str, V> { +fn hash_from_strs<V: copy>(items: ~[(~str, V)]) -> hashmap<~str, V> { hash_from_vec(str::hash, str::eq, items) } @@ -385,8 +385,8 @@ mod tests { fn uint_id(&&x: uint) -> uint { x } let hasher_uint: map::hashfn<uint> = uint_id; let eqer_uint: map::eqfn<uint> = eq_uint; - let hasher_str: map::hashfn<str> = str::hash; - let eqer_str: map::eqfn<str> = str::eq; + let hasher_str: map::hashfn<~str> = str::hash; + let eqer_str: map::eqfn<~str> = str::eq; #debug("uint -> uint"); let hm_uu: map::hashmap<uint, uint> = map::hashmap::<uint, uint>(hasher_uint, eqer_uint); @@ -400,49 +400,49 @@ mod tests { assert (hm_uu.get(12u) == 14u); assert (!hm_uu.insert(12u, 12u)); assert (hm_uu.get(12u) == 12u); - let ten: str = "ten"; - let eleven: str = "eleven"; - let twelve: str = "twelve"; + let ten: ~str = ~"ten"; + let eleven: ~str = ~"eleven"; + let twelve: ~str = ~"twelve"; #debug("str -> uint"); - let hm_su: map::hashmap<str, uint> = - map::hashmap::<str, uint>(hasher_str, eqer_str); - assert (hm_su.insert("ten", 12u)); + let hm_su: map::hashmap<~str, uint> = + map::hashmap::<~str, uint>(hasher_str, eqer_str); + assert (hm_su.insert(~"ten", 12u)); assert (hm_su.insert(eleven, 13u)); - assert (hm_su.insert("twelve", 14u)); + assert (hm_su.insert(~"twelve", 14u)); assert (hm_su.get(eleven) == 13u); - assert (hm_su.get("eleven") == 13u); - assert (hm_su.get("twelve") == 14u); - assert (hm_su.get("ten") == 12u); - assert (!hm_su.insert("twelve", 14u)); - assert (hm_su.get("twelve") == 14u); - assert (!hm_su.insert("twelve", 12u)); - assert (hm_su.get("twelve") == 12u); + assert (hm_su.get(~"eleven") == 13u); + assert (hm_su.get(~"twelve") == 14u); + assert (hm_su.get(~"ten") == 12u); + assert (!hm_su.insert(~"twelve", 14u)); + assert (hm_su.get(~"twelve") == 14u); + assert (!hm_su.insert(~"twelve", 12u)); + assert (hm_su.get(~"twelve") == 12u); #debug("uint -> str"); - let hm_us: map::hashmap<uint, str> = - map::hashmap::<uint, str>(hasher_uint, eqer_uint); - assert (hm_us.insert(10u, "twelve")); - assert (hm_us.insert(11u, "thirteen")); - assert (hm_us.insert(12u, "fourteen")); - assert (str::eq(hm_us.get(11u), "thirteen")); - assert (str::eq(hm_us.get(12u), "fourteen")); - assert (str::eq(hm_us.get(10u), "twelve")); - assert (!hm_us.insert(12u, "fourteen")); - assert (str::eq(hm_us.get(12u), "fourteen")); - assert (!hm_us.insert(12u, "twelve")); - assert (str::eq(hm_us.get(12u), "twelve")); + let hm_us: map::hashmap<uint, ~str> = + map::hashmap::<uint, ~str>(hasher_uint, eqer_uint); + assert (hm_us.insert(10u, ~"twelve")); + assert (hm_us.insert(11u, ~"thirteen")); + assert (hm_us.insert(12u, ~"fourteen")); + assert (str::eq(hm_us.get(11u), ~"thirteen")); + assert (str::eq(hm_us.get(12u), ~"fourteen")); + assert (str::eq(hm_us.get(10u), ~"twelve")); + assert (!hm_us.insert(12u, ~"fourteen")); + assert (str::eq(hm_us.get(12u), ~"fourteen")); + assert (!hm_us.insert(12u, ~"twelve")); + assert (str::eq(hm_us.get(12u), ~"twelve")); #debug("str -> str"); - let hm_ss: map::hashmap<str, str> = - map::hashmap::<str, str>(hasher_str, eqer_str); - assert (hm_ss.insert(ten, "twelve")); - assert (hm_ss.insert(eleven, "thirteen")); - assert (hm_ss.insert(twelve, "fourteen")); - assert (str::eq(hm_ss.get("eleven"), "thirteen")); - assert (str::eq(hm_ss.get("twelve"), "fourteen")); - assert (str::eq(hm_ss.get("ten"), "twelve")); - assert (!hm_ss.insert("twelve", "fourteen")); - assert (str::eq(hm_ss.get("twelve"), "fourteen")); - assert (!hm_ss.insert("twelve", "twelve")); - assert (str::eq(hm_ss.get("twelve"), "twelve")); + let hm_ss: map::hashmap<~str, ~str> = + map::hashmap::<~str, ~str>(hasher_str, eqer_str); + assert (hm_ss.insert(ten, ~"twelve")); + assert (hm_ss.insert(eleven, ~"thirteen")); + assert (hm_ss.insert(twelve, ~"fourteen")); + assert (str::eq(hm_ss.get(~"eleven"), ~"thirteen")); + assert (str::eq(hm_ss.get(~"twelve"), ~"fourteen")); + assert (str::eq(hm_ss.get(~"ten"), ~"twelve")); + assert (!hm_ss.insert(~"twelve", ~"fourteen")); + assert (str::eq(hm_ss.get(~"twelve"), ~"fourteen")); + assert (!hm_ss.insert(~"twelve", ~"twelve")); + assert (str::eq(hm_ss.get(~"twelve"), ~"twelve")); #debug("*** finished test_simple"); } @@ -484,10 +484,10 @@ mod tests { i += 1u; } #debug("str -> str"); - let hasher_str: map::hashfn<str> = str::hash; - let eqer_str: map::eqfn<str> = str::eq; - let hm_ss: map::hashmap<str, str> = - map::hashmap::<str, str>(hasher_str, eqer_str); + let hasher_str: map::hashfn<~str> = str::hash; + let eqer_str: map::eqfn<~str> = str::eq; + let hm_ss: map::hashmap<~str, ~str> = + map::hashmap::<~str, ~str>(hasher_str, eqer_str); i = 0u; while i < num_to_insert { assert hm_ss.insert(uint::to_str(i, 2u), uint::to_str(i * i, 2u)); @@ -602,27 +602,27 @@ mod tests { #[test] fn test_contains_key() { - let key = "k"; - let map = map::hashmap::<str, str>(str::hash, str::eq); + let key = ~"k"; + let map = map::hashmap::<~str, ~str>(str::hash, str::eq); assert (!map.contains_key(key)); - map.insert(key, "val"); + map.insert(key, ~"val"); assert (map.contains_key(key)); } #[test] fn test_find() { - let key = "k"; - let map = map::hashmap::<str, str>(str::hash, str::eq); + let key = ~"k"; + let map = map::hashmap::<~str, ~str>(str::hash, str::eq); assert (option::is_none(map.find(key))); - map.insert(key, "val"); - assert (option::get(map.find(key)) == "val"); + map.insert(key, ~"val"); + assert (option::get(map.find(key)) == ~"val"); } #[test] fn test_clear() { - let key = "k"; - let map = map::hashmap::<str, str>(str::hash, str::eq); - map.insert(key, "val"); + let key = ~"k"; + let map = map::hashmap::<~str, ~str>(str::hash, str::eq); + map.insert(key, ~"val"); assert (map.size() == 1); assert (map.contains_key(key)); map.clear(); @@ -633,13 +633,13 @@ mod tests { #[test] fn test_hash_from_vec() { let map = map::hash_from_strs(~[ - ("a", 1), - ("b", 2), - ("c", 3) + (~"a", 1), + (~"b", 2), + (~"c", 3) ]); assert map.size() == 3u; - assert map.get("a") == 1; - assert map.get("b") == 2; - assert map.get("c") == 3; + assert map.get(~"a") == 1; + assert map.get(~"b") == 2; + assert map.get(~"c") == 3; } } diff --git a/src/libstd/md4.rs b/src/libstd/md4.rs index d7bd7ed811a..134091dfd1d 100644 --- a/src/libstd/md4.rs +++ b/src/libstd/md4.rs @@ -82,17 +82,17 @@ fn md4(msg: ~[u8]) -> {a: u32, b: u32, c: u32, d: u32} { ret {a: a, b: b, c: c, d: d}; } -fn md4_str(msg: ~[u8]) -> str { +fn md4_str(msg: ~[u8]) -> ~str { let {a, b, c, d} = md4(msg); fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) { f(a); f(b); f(c); f(d); } - let mut result = ""; + let mut result = ~""; do app(a, b, c, d) |u| { let mut i = 0u32; while i < 4u32 { let byte = (u >> (i * 8u32)) as u8; - if byte <= 16u8 { result += "0"; } + if byte <= 16u8 { result += ~"0"; } result += uint::to_str(byte as uint, 16u); i += 1u32; } @@ -100,19 +100,19 @@ fn md4_str(msg: ~[u8]) -> str { result } -fn md4_text(msg: str) -> str { md4_str(str::bytes(msg)) } +fn md4_text(msg: ~str) -> ~str { md4_str(str::bytes(msg)) } #[test] fn test_md4() { - assert md4_text("") == "31d6cfe0d16ae931b73c59d7e0c089c0"; - assert md4_text("a") == "bde52cb31de33e46245e05fbdbd6fb24"; - assert md4_text("abc") == "a448017aaf21d8525fc10ae87aa6729d"; - assert md4_text("message digest") == "d9130a8164549fe818874806e1c7014b"; - assert md4_text("abcdefghijklmnopqrstuvwxyz") == - "d79e1c308aa5bbcdeea8ed63df412da9"; - assert md4_text("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123\ - 456789") == "043f8582f241db351ce627e153e7f0e4"; - assert md4_text("12345678901234567890123456789012345678901234567890123456\ - 789012345678901234567890") == - "e33b4ddc9c38f2199c3e7b164fcc0536"; + assert md4_text(~"") == ~"31d6cfe0d16ae931b73c59d7e0c089c0"; + assert md4_text(~"a") == ~"bde52cb31de33e46245e05fbdbd6fb24"; + assert md4_text(~"abc") == ~"a448017aaf21d8525fc10ae87aa6729d"; + assert md4_text(~"message digest") == ~"d9130a8164549fe818874806e1c7014b"; + assert md4_text(~"abcdefghijklmnopqrstuvwxyz") == + ~"d79e1c308aa5bbcdeea8ed63df412da9"; + assert md4_text(~"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\ + 0123456789") == ~"043f8582f241db351ce627e153e7f0e4"; + assert md4_text(~"1234567890123456789012345678901234567890123456789\ + 0123456789012345678901234567890") == + ~"e33b4ddc9c38f2199c3e7b164fcc0536"; } diff --git a/src/libstd/net_ip.rs b/src/libstd/net_ip.rs index abb548655d4..a78b6a5f172 100644 --- a/src/libstd/net_ip.rs +++ b/src/libstd/net_ip.rs @@ -36,7 +36,7 @@ enum ip_addr { /// Human-friendly feedback on why a parse_addr attempt failed type parse_addr_err = { - err_msg: str + err_msg: ~str }; /** @@ -46,13 +46,13 @@ type parse_addr_err = { * * * ip - a `std::net::ip::ip_addr` */ -fn format_addr(ip: ip_addr) -> str { +fn format_addr(ip: ip_addr) -> ~str { alt ip { ipv4(addr) { unsafe { let result = uv_ip4_name(&addr); - if result == "" { - fail "failed to convert inner sockaddr_in address to str" + if result == ~"" { + fail ~"failed to convert inner sockaddr_in address to str" } result } @@ -60,8 +60,8 @@ fn format_addr(ip: ip_addr) -> str { ipv6(addr) { unsafe { let result = uv_ip6_name(&addr); - if result == "" { - fail "failed to convert inner sockaddr_in address to str" + if result == ~"" { + fail ~"failed to convert inner sockaddr_in address to str" } result } @@ -88,7 +88,7 @@ enum ip_get_addr_err { * a vector of `ip_addr` results, in the case of success, or an error * object in the case of failure */ -fn get_addr(++node: str, iotask: iotask) +fn get_addr(++node: ~str, iotask: iotask) -> result::result<~[ip_addr], ip_get_addr_err> unsafe { do comm::listen |output_ch| { do str::unpack_slice(node) |node_ptr, len| { @@ -137,7 +137,7 @@ mod v4 { * * * an `ip_addr` of the `ipv4` variant */ - fn parse_addr(ip: str) -> ip_addr { + fn parse_addr(ip: ~str) -> ip_addr { alt try_parse_addr(ip) { result::ok(addr) { copy(addr) } result::err(err_data) { @@ -154,7 +154,7 @@ mod v4 { *((ptr::addr_of(self)) as *u32) } } - fn parse_to_ipv4_rep(ip: str) -> result::result<ipv4_rep, str> { + fn parse_to_ipv4_rep(ip: ~str) -> result::result<ipv4_rep, ~str> { let parts = vec::map(str::split_char(ip, '.'), |s| { alt uint::from_str(s) { some(n) if n <= 255u { n } @@ -172,7 +172,7 @@ mod v4 { c: parts[2] as u8, d: parts[3] as u8}) } } - fn try_parse_addr(ip: str) -> result::result<ip_addr,parse_addr_err> { + fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> { unsafe { let INADDR_NONE = ll::get_INADDR_NONE(); let ip_rep_result = parse_to_ipv4_rep(ip); @@ -196,7 +196,7 @@ mod v4 { if result::get(ref_ip_rep_result).as_u32() == INADDR_NONE && !input_is_inaddr_none { ret result::err( - {err_msg: "uv_ip4_name produced invalid result."}) + {err_msg: ~"uv_ip4_name produced invalid result."}) } else { result::ok(ipv4(copy(new_addr))) @@ -220,7 +220,7 @@ mod v6 { * * * an `ip_addr` of the `ipv6` variant */ - fn parse_addr(ip: str) -> ip_addr { + fn parse_addr(ip: ~str) -> ip_addr { alt try_parse_addr(ip) { result::ok(addr) { copy(addr) } result::err(err_data) { @@ -228,7 +228,7 @@ mod v6 { } } } - fn try_parse_addr(ip: str) -> result::result<ip_addr,parse_addr_err> { + fn try_parse_addr(ip: ~str) -> result::result<ip_addr,parse_addr_err> { unsafe { // need to figure out how to establish a parse failure.. let new_addr = uv_ip6_addr(ip, 22); @@ -237,7 +237,7 @@ mod v6 { ip, reparsed_name)); // '::' appears to be uv_ip6_name() returns for bogus // parses.. - if ip != "::" && reparsed_name == "::" { + if ip != ~"::" && reparsed_name == ~"::" { result::err({err_msg:#fmt("failed to parse '%s'", ip)}) } @@ -254,7 +254,7 @@ type get_addr_data = { extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, res: *addrinfo) unsafe { - log(debug, "in get_addr_cb"); + log(debug, ~"in get_addr_cb"); let handle_data = get_data_for_req(handle) as *get_addr_data; if status == 0i32 { @@ -272,8 +272,8 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, *ll::addrinfo_as_sockaddr_in6(curr_addr)))) } else { - log(debug, "curr_addr is not of family AF_INET or "+ - "AF_INET6. Error."); + log(debug, ~"curr_addr is not of family AF_INET or "+ + ~"AF_INET6. Error."); (*handle_data).output_ch.send( result::err(get_addr_unknown_error)); break; @@ -282,7 +282,7 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, let next_addr = ll::get_next_addrinfo(curr_addr); if next_addr == ptr::null::<addrinfo>() as *addrinfo { - log(debug, "null next_addr encountered. no mas"); + log(debug, ~"null next_addr encountered. no mas"); break; } else { @@ -295,33 +295,33 @@ extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int, (*handle_data).output_ch.send(result::ok(out_vec)); } else { - log(debug, "addrinfo pointer is NULL"); + log(debug, ~"addrinfo pointer is NULL"); (*handle_data).output_ch.send( result::err(get_addr_unknown_error)); } } else { - log(debug, "status != 0 error in get_addr_cb"); + log(debug, ~"status != 0 error in get_addr_cb"); (*handle_data).output_ch.send( result::err(get_addr_unknown_error)); } if res != (ptr::null::<addrinfo>()) { uv_freeaddrinfo(res); } - log(debug, "leaving get_addr_cb"); + log(debug, ~"leaving get_addr_cb"); } #[cfg(test)] mod test { #[test] fn test_ip_ipv4_parse_and_format_ip() { - let localhost_str = "127.0.0.1"; + let localhost_str = ~"127.0.0.1"; assert (format_addr(v4::parse_addr(localhost_str)) == localhost_str) } #[test] fn test_ip_ipv6_parse_and_format_ip() { - let localhost_str = "::1"; + let localhost_str = ~"::1"; let format_result = format_addr(v6::parse_addr(localhost_str)); log(debug, #fmt("results: expected: '%s' actual: '%s'", localhost_str, format_result)); @@ -329,7 +329,7 @@ mod test { } #[test] fn test_ip_ipv4_bad_parse() { - alt v4::try_parse_addr("b4df00d") { + alt v4::try_parse_addr(~"b4df00d") { result::err(err_info) { log(debug, #fmt("got error as expected %?", err_info)); assert true; @@ -342,7 +342,7 @@ mod test { #[test] #[ignore(target_os="win32")] fn test_ip_ipv6_bad_parse() { - alt v6::try_parse_addr("::,~2234k;") { + alt v6::try_parse_addr(~"::,~2234k;") { result::err(err_info) { log(debug, #fmt("got error as expected %?", err_info)); assert true; @@ -355,11 +355,11 @@ mod test { #[test] #[ignore(reason = "valgrind says it's leaky")] fn test_ip_get_addr() { - let localhost_name = "localhost"; + let localhost_name = ~"localhost"; let iotask = uv::global_loop::get(); let ga_result = get_addr(localhost_name, iotask); if result::is_err(ga_result) { - fail "got err result from net::ip::get_addr();" + fail ~"got err result from net::ip::get_addr();" } // note really sure how to realiably test/assert // this.. mostly just wanting to see it work, atm. @@ -369,10 +369,10 @@ mod test { for vec::each(results) |r| { let ipv_prefix = alt r { ipv4(_) { - "IPv4" + ~"IPv4" } ipv6(_) { - "IPv6" + ~"IPv6" } }; log(debug, #fmt("test_get_addr: result %s: '%s'", @@ -385,7 +385,7 @@ mod test { #[test] #[ignore(reason = "valgrind says it's leaky")] fn test_ip_get_addr_bad_input() { - let localhost_name = "sjkl234m,./sdf"; + let localhost_name = ~"sjkl234m,./sdf"; let iotask = uv::global_loop::get(); let ga_result = get_addr(localhost_name, iotask); assert result::is_err(ga_result); diff --git a/src/libstd/net_tcp.rs b/src/libstd/net_tcp.rs index 17ffae1b5f4..31b8841933b 100644 --- a/src/libstd/net_tcp.rs +++ b/src/libstd/net_tcp.rs @@ -62,8 +62,8 @@ class tcp_socket_buf { /// Contains raw, string-based, error information returned from libuv type tcp_err_data = { - err_name: str, - err_msg: str + err_name: ~str, + err_msg: ~str }; /// Details returned as part of a `result::err` result from `tcp::listen` enum tcp_listen_err_data { @@ -71,7 +71,7 @@ enum tcp_listen_err_data { * Some unplanned-for error. The first and second fields correspond * to libuv's `err_name` and `err_msg` fields, respectively. */ - generic_listen_err(str, str), + generic_listen_err(~str, ~str), /** * Failed to bind to the requested IP/Port, because it is already in use. * @@ -98,7 +98,7 @@ enum tcp_connect_err_data { * Some unplanned-for error. The first and second fields correspond * to libuv's `err_name` and `err_msg` fields, respectively. */ - generic_connect_err(str, str), + generic_connect_err(~str, ~str), /// Invalid IP or invalid port connection_refused } @@ -147,15 +147,15 @@ fn connect(-input_ip: ip::ip_addr, port: uint, log(debug, #fmt("stream_handle_ptr outside interact %?", stream_handle_ptr)); do iotask::interact(iotask) |loop_ptr| { - log(debug, "in interact cb for tcp client connect.."); + log(debug, ~"in interact cb for tcp client connect.."); log(debug, #fmt("stream_handle_ptr in interact %?", stream_handle_ptr)); alt uv::ll::tcp_init( loop_ptr, stream_handle_ptr) { 0i32 { - log(debug, "tcp_init successful"); + log(debug, ~"tcp_init successful"); alt input_ip { ipv4 { - log(debug, "dealing w/ ipv4 connection.."); + log(debug, ~"dealing w/ ipv4 connection.."); let connect_req_ptr = ptr::addr_of((*socket_data_ptr).connect_req); let addr_str = ip::format_addr(input_ip); @@ -186,7 +186,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, }; alt connect_result { 0i32 { - log(debug, "tcp_connect successful"); + log(debug, ~"tcp_connect successful"); // reusable data that we'll have for the // duration.. uv::ll::set_data_for_uv_handle(stream_handle_ptr, @@ -196,7 +196,7 @@ fn connect(-input_ip: ip::ip_addr, port: uint, // outcome.. uv::ll::set_data_for_req(connect_req_ptr, conn_data_ptr); - log(debug, "leaving tcp_connect interact cb..."); + log(debug, ~"leaving tcp_connect interact cb..."); // let tcp_connect_on_connect_cb send on // the result_ch, now.. } @@ -224,17 +224,17 @@ fn connect(-input_ip: ip::ip_addr, port: uint, }; alt comm::recv(result_po) { conn_success { - log(debug, "tcp::connect - received success on result_po"); + log(debug, ~"tcp::connect - received success on result_po"); result::ok(tcp_socket(socket_data)) } conn_failure(err_data) { comm::recv(closed_signal_po); - log(debug, "tcp::connect - received failure on result_po"); + log(debug, ~"tcp::connect - received failure on result_po"); // still have to free the malloc'd stream handle.. rustrt::rust_uv_current_kernel_free(stream_handle_ptr as *libc::c_void); let tcp_conn_err = alt err_data.err_name { - "ECONNREFUSED" { connection_refused } + ~"ECONNREFUSED" { connection_refused } _ { generic_connect_err(err_data.err_name, err_data.err_msg) } }; result::err(tcp_conn_err) @@ -497,31 +497,31 @@ fn accept(new_conn: tcp_new_connection) // the rules here because this always has to be // called within the context of a listen() new_connect_cb // callback (or it will likely fail and drown your cat) - log(debug, "in interact cb for tcp::accept"); + log(debug, ~"in interact cb for tcp::accept"); let loop_ptr = uv::ll::get_loop_for_uv_handle( server_handle_ptr); alt uv::ll::tcp_init(loop_ptr, client_stream_handle_ptr) { 0i32 { - log(debug, "uv_tcp_init successful for client stream"); + log(debug, ~"uv_tcp_init successful for client stream"); alt uv::ll::accept( server_handle_ptr as *libc::c_void, client_stream_handle_ptr as *libc::c_void) { 0i32 { - log(debug, "successfully accepted client connection"); + log(debug, ~"successfully accepted client connection"); uv::ll::set_data_for_uv_handle(client_stream_handle_ptr, client_socket_data_ptr as *libc::c_void); comm::send(result_ch, none); } _ { - log(debug, "failed to accept client conn"); + log(debug, ~"failed to accept client conn"); comm::send(result_ch, some( uv::ll::get_last_err_data(loop_ptr).to_tcp_err())); } } } _ { - log(debug, "failed to init client stream"); + log(debug, ~"failed to init client stream"); comm::send(result_ch, some( uv::ll::get_last_err_data(loop_ptr).to_tcp_err())); } @@ -642,21 +642,21 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, comm::send(setup_ch, none); } _ { - log(debug, "failure to uv_listen()"); + log(debug, ~"failure to uv_listen()"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(setup_ch, some(err_data)); } } } _ { - log(debug, "failure to uv_tcp_bind"); + log(debug, ~"failure to uv_tcp_bind"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(setup_ch, some(err_data)); } } } _ { - log(debug, "failure to uv_tcp_init"); + log(debug, ~"failure to uv_tcp_init"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(setup_ch, some(err_data)); } @@ -674,12 +674,12 @@ fn listen_common(-host_ip: ip::ip_addr, port: uint, backlog: uint, }; stream_closed_po.recv(); alt err_data.err_name { - "EACCES" { - log(debug, "Got EACCES error"); + ~"EACCES" { + log(debug, ~"Got EACCES error"); result::err(access_denied) } - "EADDRINUSE" { - log(debug, "Got EADDRINUSE error"); + ~"EADDRINUSE" { + log(debug, ~"Got EADDRINUSE error"); result::err(address_in_use) } _ { @@ -855,13 +855,13 @@ fn tear_down_socket_data(socket_data: @tcp_socket_data) unsafe { log(debug, #fmt("about to free socket_data at %?", socket_data)); rustrt::rust_uv_current_kernel_free(stream_handle_ptr as *libc::c_void); - log(debug, "exiting dtor for tcp_socket"); + log(debug, ~"exiting dtor for tcp_socket"); } // shared implementation for tcp::read fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) -> result::result<~[u8],tcp_err_data> unsafe { - log(debug, "starting tcp::read"); + log(debug, ~"starting tcp::read"); let iotask = (*socket_data).iotask; let rs_result = read_start_common_impl(socket_data); if result::is_err(rs_result) { @@ -869,26 +869,26 @@ fn read_common_impl(socket_data: *tcp_socket_data, timeout_msecs: uint) result::err(err_data) } else { - log(debug, "tcp::read before recv_timeout"); + log(debug, ~"tcp::read before recv_timeout"); let read_result = if timeout_msecs > 0u { timer::recv_timeout( iotask, timeout_msecs, result::get(rs_result)) } else { some(comm::recv(result::get(rs_result))) }; - log(debug, "tcp::read after recv_timeout"); + log(debug, ~"tcp::read after recv_timeout"); alt read_result { none { - log(debug, "tcp::read: timed out.."); + log(debug, ~"tcp::read: timed out.."); let err_data = { - err_name: "TIMEOUT", - err_msg: "req timed out" + err_name: ~"TIMEOUT", + err_msg: ~"req timed out" }; read_stop_common_impl(socket_data); result::err(err_data) } some(data_result) { - log(debug, "tcp::read got data"); + log(debug, ~"tcp::read got data"); read_stop_common_impl(socket_data); data_result } @@ -903,14 +903,14 @@ fn read_stop_common_impl(socket_data: *tcp_socket_data) -> let stop_po = comm::port::<option<tcp_err_data>>(); let stop_ch = comm::chan(stop_po); do iotask::interact((*socket_data).iotask) |loop_ptr| { - log(debug, "in interact cb for tcp::read_stop"); + log(debug, ~"in interact cb for tcp::read_stop"); alt uv::ll::read_stop(stream_handle_ptr as *uv::ll::uv_stream_t) { 0i32 { - log(debug, "successfully called uv_read_stop"); + log(debug, ~"successfully called uv_read_stop"); comm::send(stop_ch, none); } _ { - log(debug, "failure in calling uv_read_stop"); + log(debug, ~"failure in calling uv_read_stop"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(stop_ch, some(err_data.to_tcp_err())); } @@ -933,18 +933,18 @@ fn read_start_common_impl(socket_data: *tcp_socket_data) let stream_handle_ptr = (*socket_data).stream_handle_ptr; let start_po = comm::port::<option<uv::ll::uv_err_data>>(); let start_ch = comm::chan(start_po); - log(debug, "in tcp::read_start before interact loop"); + log(debug, ~"in tcp::read_start before interact loop"); do iotask::interact((*socket_data).iotask) |loop_ptr| { log(debug, #fmt("in tcp::read_start interact cb %?", loop_ptr)); alt uv::ll::read_start(stream_handle_ptr as *uv::ll::uv_stream_t, on_alloc_cb, on_tcp_read_cb) { 0i32 { - log(debug, "success doing uv_read_start"); + log(debug, ~"success doing uv_read_start"); comm::send(start_ch, none); } _ { - log(debug, "error attempting uv_read_start"); + log(debug, ~"error attempting uv_read_start"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send(start_ch, some(err_data)); } @@ -985,11 +985,11 @@ fn write_common_impl(socket_data_ptr: *tcp_socket_data, write_buf_vec_ptr, tcp_write_complete_cb) { 0i32 { - log(debug, "uv_write() invoked successfully"); + log(debug, ~"uv_write() invoked successfully"); uv::ll::set_data_for_req(write_req_ptr, write_data_ptr); } _ { - log(debug, "error invoking uv_write()"); + log(debug, ~"error invoking uv_write()"); let err_data = uv::ll::get_last_err_data(loop_ptr); comm::send((*write_data_ptr).result_ch, tcp_write_error(err_data.to_tcp_err())); @@ -1113,13 +1113,13 @@ extern fn on_tcp_read_cb(stream: *uv::ll::uv_stream_t, } } uv::ll::free_base_of_buf(buf); - log(debug, "exiting on_tcp_read_cb"); + log(debug, ~"exiting on_tcp_read_cb"); } extern fn on_alloc_cb(handle: *libc::c_void, ++suggested_size: size_t) -> uv::ll::uv_buf_t unsafe { - log(debug, "tcp read on_alloc_cb!"); + log(debug, ~"tcp read on_alloc_cb!"); let char_ptr = uv::ll::malloc_buf_base_of(suggested_size); log(debug, #fmt("tcp read on_alloc_cb h: %? char_ptr: %u sugsize: %u", handle, @@ -1137,7 +1137,7 @@ extern fn tcp_socket_dtor_close_cb(handle: *uv::ll::uv_tcp_t) unsafe { as *tcp_socket_close_data; let closed_ch = (*data).closed_ch; comm::send(closed_ch, ()); - log(debug, "tcp_socket_dtor_close_cb exiting.."); + log(debug, ~"tcp_socket_dtor_close_cb exiting.."); } extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t, @@ -1145,14 +1145,14 @@ extern fn tcp_write_complete_cb(write_req: *uv::ll::uv_write_t, let write_data_ptr = uv::ll::get_data_for_req(write_req) as *write_req_data; if status == 0i32 { - log(debug, "successful write complete"); + log(debug, ~"successful write complete"); comm::send((*write_data_ptr).result_ch, tcp_write_success); } else { let stream_handle_ptr = uv::ll::get_stream_handle_from_write_req( write_req); let loop_ptr = uv::ll::get_loop_for_uv_handle(stream_handle_ptr); let err_data = uv::ll::get_last_err_data(loop_ptr); - log(debug, "failure to write"); + log(debug, ~"failure to write"); comm::send((*write_data_ptr).result_ch, tcp_write_error(err_data)); } } @@ -1187,11 +1187,11 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t, uv::ll::get_stream_handle_from_connect_req(connect_req_ptr); alt status { 0i32 { - log(debug, "successful tcp connection!"); + log(debug, ~"successful tcp connection!"); comm::send(result_ch, conn_success); } _ { - log(debug, "error in tcp_connect_on_connect_cb"); + log(debug, ~"error in tcp_connect_on_connect_cb"); let loop_ptr = uv::ll::get_loop_for_uv_handle(tcp_stream_ptr); let err_data = uv::ll::get_last_err_data(loop_ptr); log(debug, #fmt("err_data %? %?", err_data.err_name, @@ -1202,7 +1202,7 @@ extern fn tcp_connect_on_connect_cb(connect_req_ptr: *uv::ll::uv_connect_t, uv::ll::close(tcp_stream_ptr, stream_error_close_cb); } } - log(debug, "leaving tcp_connect_on_connect_cb"); + log(debug, ~"leaving tcp_connect_on_connect_cb"); } enum conn_attempt { @@ -1287,12 +1287,12 @@ mod test { } fn impl_gl_tcp_ipv4_server_and_client() { let hl_loop = uv::global_loop::get(); - let server_ip = "127.0.0.1"; + let server_ip = ~"127.0.0.1"; let server_port = 8888u; - let expected_req = "ping"; - let expected_resp = "pong"; + let expected_req = ~"ping"; + let expected_resp = ~"pong"; - let server_result_po = comm::port::<str>(); + let server_result_po = comm::port::<~str>(); let server_result_ch = comm::chan(server_result_po); let cont_po = comm::port::<()>(); @@ -1312,7 +1312,7 @@ mod test { }; comm::recv(cont_po); // client - log(debug, "server started, firing up client.."); + log(debug, ~"server started, firing up client.."); let actual_resp_result = do comm::listen |client_ch| { run_tcp_test_client( server_ip, @@ -1333,11 +1333,11 @@ mod test { } fn impl_gl_tcp_ipv4_client_error_connection_refused() { let hl_loop = uv::global_loop::get(); - let server_ip = "127.0.0.1"; + let server_ip = ~"127.0.0.1"; let server_port = 8889u; - let expected_req = "ping"; + let expected_req = ~"ping"; // client - log(debug, "firing up client.."); + log(debug, ~"firing up client.."); let actual_resp_result = do comm::listen |client_ch| { run_tcp_test_client( server_ip, @@ -1350,18 +1350,18 @@ mod test { connection_refused { } _ { - fail "unknown error.. expected connection_refused" + fail ~"unknown error.. expected connection_refused" } } } fn impl_gl_tcp_ipv4_server_address_in_use() { let hl_loop = uv::global_loop::get(); - let server_ip = "127.0.0.1"; + let server_ip = ~"127.0.0.1"; let server_port = 8890u; - let expected_req = "ping"; - let expected_resp = "pong"; + let expected_req = ~"ping"; + let expected_resp = ~"pong"; - let server_result_po = comm::port::<str>(); + let server_result_po = comm::port::<~str>(); let server_result_ch = comm::chan(server_result_po); let cont_po = comm::port::<()>(); @@ -1386,7 +1386,7 @@ mod test { server_port, hl_loop); // client.. just doing this so that the first server tears down - log(debug, "server started, firing up client.."); + log(debug, ~"server started, firing up client.."); do comm::listen |client_ch| { run_tcp_test_client( server_ip, @@ -1400,14 +1400,14 @@ mod test { assert true; } _ { - fail "expected address_in_use listen error,"+ - "but got a different error varient. check logs."; + fail ~"expected address_in_use listen error,"+ + ~"but got a different error varient. check logs."; } } } fn impl_gl_tcp_ipv4_server_access_denied() { let hl_loop = uv::global_loop::get(); - let server_ip = "127.0.0.1"; + let server_ip = ~"127.0.0.1"; let server_port = 80u; // this one should fail.. let listen_err = run_tcp_test_server_fail( @@ -1419,19 +1419,19 @@ mod test { assert true; } _ { - fail "expected address_in_use listen error,"+ - "but got a different error varient. check logs."; + fail ~"expected address_in_use listen error,"+ + ~"but got a different error varient. check logs."; } } } fn impl_gl_tcp_ipv4_server_client_reader_writer() { let iotask = uv::global_loop::get(); - let server_ip = "127.0.0.1"; + let server_ip = ~"127.0.0.1"; let server_port = 8891u; - let expected_req = "ping"; - let expected_resp = "pong"; + let expected_req = ~"ping"; + let expected_resp = ~"pong"; - let server_result_po = comm::port::<str>(); + let server_result_po = comm::port::<~str>(); let server_result_ch = comm::chan(server_result_po); let cont_po = comm::port::<()>(); @@ -1474,7 +1474,7 @@ mod test { assert str::contains(actual_resp, expected_resp); } - fn buf_write(+w: io::writer, val: str) { + fn buf_write(+w: io::writer, val: ~str) { log(debug, #fmt("BUF_WRITE: val len %?", str::len(val))); do str::byte_slice(val) |b_slice| { log(debug, #fmt("BUF_WRITE: b_slice len %?", @@ -1483,17 +1483,17 @@ mod test { } } - fn buf_read(+r: io::reader, len: uint) -> str { + fn buf_read(+r: io::reader, len: uint) -> ~str { let new_bytes = r.read_bytes(len); log(debug, #fmt("in buf_read.. new_bytes len: %?", vec::len(new_bytes))); str::from_bytes(new_bytes) } - fn run_tcp_test_server(server_ip: str, server_port: uint, resp: str, - server_ch: comm::chan<str>, + fn run_tcp_test_server(server_ip: ~str, server_port: uint, resp: ~str, + server_ch: comm::chan<~str>, cont_ch: comm::chan<()>, - iotask: iotask) -> str { + iotask: iotask) -> ~str { let server_ip_addr = ip::v4::parse_addr(server_ip); let listen_result = listen(server_ip_addr, server_port, 128u, iotask, // on_establish_cb -- called when listener is set up @@ -1505,55 +1505,55 @@ mod test { // risky to run this on the loop, but some users // will want the POWER |new_conn, kill_ch| { - log(debug, "SERVER: new connection!"); + log(debug, ~"SERVER: new connection!"); do comm::listen |cont_ch| { do task::spawn_sched(task::manual_threads(1u)) { - log(debug, "SERVER: starting worker for new req"); + log(debug, ~"SERVER: starting worker for new req"); let accept_result = accept(new_conn); - log(debug, "SERVER: after accept()"); + log(debug, ~"SERVER: after accept()"); if result::is_err(accept_result) { - log(debug, "SERVER: error accept connection"); + log(debug, ~"SERVER: error accept connection"); let err_data = result::get_err(accept_result); comm::send(kill_ch, some(err_data)); log(debug, - "SERVER/WORKER: send on err cont ch"); + ~"SERVER/WORKER: send on err cont ch"); cont_ch.send(()); } else { log(debug, - "SERVER/WORKER: send on cont ch"); + ~"SERVER/WORKER: send on cont ch"); cont_ch.send(()); let sock = result::unwrap(accept_result); - log(debug, "SERVER: successfully accepted"+ - "connection!"); + log(debug, ~"SERVER: successfully accepted"+ + ~"connection!"); let received_req_bytes = read(sock, 0u); alt received_req_bytes { result::ok(data) { - log(debug, "SERVER: got REQ str::from_bytes.."); + log(debug, ~"SERVER: got REQ str::from_bytes.."); log(debug, #fmt("SERVER: REQ data len: %?", vec::len(data))); server_ch.send( str::from_bytes(data)); - log(debug, "SERVER: before write"); + log(debug, ~"SERVER: before write"); tcp_write_single(sock, str::bytes(resp)); - log(debug, "SERVER: after write.. die"); + log(debug, ~"SERVER: after write.. die"); comm::send(kill_ch, none); } result::err(err_data) { log(debug, #fmt("SERVER: error recvd: %s %s", err_data.err_name, err_data.err_msg)); comm::send(kill_ch, some(err_data)); - server_ch.send(""); + server_ch.send(~""); } } - log(debug, "SERVER: worker spinning down"); + log(debug, ~"SERVER: worker spinning down"); } } - log(debug, "SERVER: waiting to recv on cont_ch"); + log(debug, ~"SERVER: waiting to recv on cont_ch"); cont_ch.recv() }; - log(debug, "SERVER: recv'd on cont_ch..leaving listen cb"); + log(debug, ~"SERVER: recv'd on cont_ch..leaving listen cb"); }); // err check on listen_result if result::is_err(listen_result) { @@ -1563,10 +1563,10 @@ mod test { name, msg); } access_denied { - fail "SERVER: exited abnormally, got access denied.."; + fail ~"SERVER: exited abnormally, got access denied.."; } address_in_use { - fail "SERVER: exited abnormally, got address in use..."; + fail ~"SERVER: exited abnormally, got address in use..."; } } } @@ -1575,7 +1575,7 @@ mod test { ret_val } - fn run_tcp_test_server_fail(server_ip: str, server_port: uint, + fn run_tcp_test_server_fail(server_ip: ~str, server_port: uint, iotask: iotask) -> tcp_listen_err_data { let server_ip_addr = ip::v4::parse_addr(server_ip); let listen_result = listen(server_ip_addr, server_port, 128u, iotask, @@ -1593,20 +1593,20 @@ mod test { result::get_err(listen_result) } else { - fail "SERVER: did not fail as expected" + fail ~"SERVER: did not fail as expected" } } - fn run_tcp_test_client(server_ip: str, server_port: uint, resp: str, - client_ch: comm::chan<str>, - iotask: iotask) -> result::result<str, + fn run_tcp_test_client(server_ip: ~str, server_port: uint, resp: ~str, + client_ch: comm::chan<~str>, + iotask: iotask) -> result::result<~str, tcp_connect_err_data> { let server_ip_addr = ip::v4::parse_addr(server_ip); - log(debug, "CLIENT: starting.."); + log(debug, ~"CLIENT: starting.."); let connect_result = connect(server_ip_addr, server_port, iotask); if result::is_err(connect_result) { - log(debug, "CLIENT: failed to connect"); + log(debug, ~"CLIENT: failed to connect"); let err_data = result::get_err(connect_result); err(err_data) } @@ -1616,8 +1616,8 @@ mod test { tcp_write_single(sock, resp_bytes); let read_result = sock.read(0u); if read_result.is_err() { - log(debug, "CLIENT: failure to read"); - ok("") + log(debug, ~"CLIENT: failure to read"); + ok(~"") } else { client_ch.send(str::from_bytes(read_result.get())); @@ -1633,12 +1633,12 @@ mod test { let write_result_future = sock.write_future(val); let write_result = write_result_future.get(); if result::is_err(write_result) { - log(debug, "tcp_write_single: write failed!"); + log(debug, ~"tcp_write_single: write failed!"); let err_data = result::get_err(write_result); log(debug, #fmt("tcp_write_single err name: %s msg: %s", err_data.err_name, err_data.err_msg)); // meh. torn on what to do here. - fail "tcp_write_single failed"; + fail ~"tcp_write_single failed"; } } } diff --git a/src/libstd/par.rs b/src/libstd/par.rs index 9bf6a021282..ce78bc945db 100644 --- a/src/libstd/par.rs +++ b/src/libstd/par.rs @@ -31,7 +31,7 @@ fn map_slices<A: copy send, B: copy send>( let len = xs.len(); if len < min_granularity { - log(info, "small slice"); + log(info, ~"small slice"); // This is a small vector, fall back on the normal map. ~[f()(0u, xs)] } @@ -42,7 +42,7 @@ fn map_slices<A: copy send, B: copy send>( let mut futures = ~[]; let mut base = 0u; - log(info, "spawning tasks"); + log(info, ~"spawning tasks"); while base < len { let end = uint::min(len, base + items_per_task); // FIXME: why is the ::<A, ()> annotation required here? (#2617) @@ -66,7 +66,7 @@ fn map_slices<A: copy send, B: copy send>( }; base += items_per_task; } - log(info, "tasks spawned"); + log(info, ~"tasks spawned"); log(info, #fmt("num_tasks: %?", (num_tasks, futures.len()))); assert(num_tasks == futures.len()); diff --git a/src/libstd/prettyprint.rs b/src/libstd/prettyprint.rs index 497ed8f0c06..dbeb5ab6381 100644 --- a/src/libstd/prettyprint.rs +++ b/src/libstd/prettyprint.rs @@ -4,7 +4,7 @@ import serialization::serializer; impl of serializer for writer { fn emit_nil() { - self.write_str("()") + self.write_str(~"()") } fn emit_uint(v: uint) { @@ -63,68 +63,68 @@ impl of serializer for writer { self.write_str(#fmt["%?_f32", v]); } - fn emit_str(v: str) { + fn emit_str(v: ~str) { self.write_str(#fmt["%?", v]); } - fn emit_enum(_name: str, f: fn()) { + fn emit_enum(_name: ~str, f: fn()) { f(); } - fn emit_enum_variant(v_name: str, _v_id: uint, sz: uint, f: fn()) { + fn emit_enum_variant(v_name: ~str, _v_id: uint, sz: uint, f: fn()) { self.write_str(v_name); - if sz > 0u { self.write_str("("); } + if sz > 0u { self.write_str(~"("); } f(); - if sz > 0u { self.write_str(")"); } + if sz > 0u { self.write_str(~")"); } } fn emit_enum_variant_arg(idx: uint, f: fn()) { - if idx > 0u { self.write_str(", "); } + if idx > 0u { self.write_str(~", "); } f(); } fn emit_vec(_len: uint, f: fn()) { - self.write_str("["); + self.write_str(~"["); f(); - self.write_str("]"); + self.write_str(~"]"); } fn emit_vec_elt(idx: uint, f: fn()) { - if idx > 0u { self.write_str(", "); } + if idx > 0u { self.write_str(~", "); } f(); } fn emit_box(f: fn()) { - self.write_str("@"); + self.write_str(~"@"); f(); } fn emit_uniq(f: fn()) { - self.write_str("~"); + self.write_str(~"~"); f(); } fn emit_rec(f: fn()) { - self.write_str("{"); + self.write_str(~"{"); f(); - self.write_str("}"); + self.write_str(~"}"); } - fn emit_rec_field(f_name: str, f_idx: uint, f: fn()) { - if f_idx > 0u { self.write_str(", "); } + fn emit_rec_field(f_name: ~str, f_idx: uint, f: fn()) { + if f_idx > 0u { self.write_str(~", "); } self.write_str(f_name); - self.write_str(": "); + self.write_str(~": "); f(); } fn emit_tup(_sz: uint, f: fn()) { - self.write_str("("); + self.write_str(~"("); f(); - self.write_str(")"); + self.write_str(~")"); } fn emit_tup_elt(idx: uint, f: fn()) { - if idx > 0u { self.write_str(", "); } + if idx > 0u { self.write_str(~", "); } f(); } } \ No newline at end of file diff --git a/src/libstd/rope.rs b/src/libstd/rope.rs index 917adfaaecd..dbca5ae4e76 100644 --- a/src/libstd/rope.rs +++ b/src/libstd/rope.rs @@ -53,7 +53,7 @@ fn empty() -> rope { * * this operation does not copy the string; * * the function runs in linear time. */ -fn of_str(str: @str/~) -> rope { +fn of_str(str: @~str) -> rope { ret of_substr(str, 0u, str::len(*str)); } @@ -79,7 +79,7 @@ fn of_str(str: @str/~) -> rope { * * this function does _not_ check the validity of the substring; * * this function fails if `byte_offset` or `byte_len` do not match `str`. */ -fn of_substr(str: @str/~, byte_offset: uint, byte_len: uint) -> rope { +fn of_substr(str: @~str, byte_offset: uint, byte_len: uint) -> rope { if byte_len == 0u { ret node::empty; } if byte_offset + byte_len > str::len(*str) { fail; } ret node::content(node::of_substr(str, byte_offset, byte_len)); @@ -107,7 +107,7 @@ fn append_char(rope: rope, char: char) -> rope { * * * this function executes in near-linear time */ -fn append_str(rope: rope, str: @str/~) -> rope { +fn append_str(rope: rope, str: @~str) -> rope { ret append_rope(rope, of_str(str)) } @@ -127,7 +127,7 @@ fn prepend_char(rope: rope, char: char) -> rope { * # Performance note * * this function executes in near-linear time */ -fn prepend_str(rope: rope, str: @str/~) -> rope { +fn prepend_str(rope: rope, str: @~str) -> rope { ret append_rope(of_str(str), rope) } @@ -567,7 +567,7 @@ mod node { byte_offset: uint, byte_len: uint, char_len: uint, - content: @str/~ + content: @~str }; /** @@ -627,7 +627,7 @@ mod node { * Performance note: The complexity of this function is linear in * the length of `str`. */ - fn of_str(str: @str/~) -> @node { + fn of_str(str: @~str) -> @node { ret of_substr(str, 0u, str::len(*str)); } @@ -648,7 +648,7 @@ mod node { * Behavior is undefined if `byte_start` or `byte_len` do not represent * valid positions in `str` */ - fn of_substr(str: @str/~, byte_start: uint, byte_len: uint) -> @node { + fn of_substr(str: @~str, byte_start: uint, byte_len: uint) -> @node { ret of_substr_unsafer(str, byte_start, byte_len, str::count_chars(*str, byte_start, byte_len)); } @@ -674,7 +674,7 @@ mod node { * * Behavior is undefined if `char_len` does not accurately represent the * number of chars between byte_start and byte_start+byte_len */ - fn of_substr_unsafer(str: @str/~, byte_start: uint, byte_len: uint, + fn of_substr_unsafer(str: @~str, byte_start: uint, byte_len: uint, char_len: uint) -> @node { assert(byte_start + byte_len <= str::len(*str)); let candidate = @leaf({ @@ -799,7 +799,7 @@ mod node { ret forest[0]; } - fn serialize_node(node: @node) -> str unsafe { + fn serialize_node(node: @node) -> ~str unsafe { let mut buf = vec::to_mut(vec::from_elem(byte_len(node), 0u8)); let mut offset = 0u;//Current position in the buffer let it = leaf_iterator::start(node); @@ -1237,11 +1237,11 @@ mod node { mod tests { //Utility function, used for sanity check - fn rope_to_string(r: rope) -> str { + fn rope_to_string(r: rope) -> ~str { alt(r) { - node::empty { ret "" } + node::empty { ret ~"" } node::content(x) { - let str = @mut ""; + let str = @mut ~""; fn aux(str: @mut str, node: @node::node) unsafe { alt(*node) { node::leaf(x) { @@ -1270,7 +1270,7 @@ mod tests { #[test] fn of_string1() { - let sample = @"0123456789ABCDE"/~; + let sample = @~"0123456789ABCDE"; let r = of_str(sample); assert char_len(r) == str::char_len(*sample); @@ -1279,7 +1279,7 @@ mod tests { #[test] fn of_string2() { - let buf = @ mut "1234567890"; + let buf = @ mut ~"1234567890"; let mut i = 0; while i < 10 { *buf = *buf + *buf; i+=1;} let sample = @*buf; @@ -1310,7 +1310,7 @@ mod tests { #[test] fn iter1() { - let buf = @ mut "1234567890"; + let buf = @ mut ~"1234567890"; let mut i = 0; while i < 10 { *buf = *buf + *buf; i+=1;} let sample = @*buf; @@ -1330,7 +1330,7 @@ mod tests { #[test] fn bal1() { - let init = @"1234567890"/~; + let init = @~"1234567890"; let buf = @mut * init; let mut i = 0; while i < 8 { *buf = *buf + *buf; i+=1;} @@ -1352,7 +1352,7 @@ mod tests { #[ignore] fn char_at1() { //Generate a large rope - let mut r = of_str(@"123456789"/~); + let mut r = of_str(@~"123456789"); for uint::range(0u, 10u) |_i| { r = append_rope(r, r); } @@ -1384,7 +1384,7 @@ mod tests { #[test] fn concat1() { //Generate a reasonable rope - let chunk = of_str(@"123456789"/~); + let chunk = of_str(@~"123456789"); let mut r = empty(); for uint::range(0u, 10u) |_i| { r = append_rope(r, chunk); diff --git a/src/libstd/serialization.rs b/src/libstd/serialization.rs index aafe31ec011..ba20ff88e3d 100644 --- a/src/libstd/serialization.rs +++ b/src/libstd/serialization.rs @@ -23,18 +23,18 @@ iface serializer { fn emit_float(v: float); fn emit_f64(v: f64); fn emit_f32(v: f32); - fn emit_str(v: str); + fn emit_str(v: ~str); // Compound types: - fn emit_enum(name: str, f: fn()); - fn emit_enum_variant(v_name: str, v_id: uint, sz: uint, f: fn()); + fn emit_enum(name: ~str, f: fn()); + fn emit_enum_variant(v_name: ~str, v_id: uint, sz: uint, f: fn()); fn emit_enum_variant_arg(idx: uint, f: fn()); fn emit_vec(len: uint, f: fn()); fn emit_vec_elt(idx: uint, f: fn()); fn emit_box(f: fn()); fn emit_uniq(f: fn()); fn emit_rec(f: fn()); - fn emit_rec_field(f_name: str, f_idx: uint, f: fn()); + fn emit_rec_field(f_name: ~str, f_idx: uint, f: fn()); fn emit_tup(sz: uint, f: fn()); fn emit_tup_elt(idx: uint, f: fn()); } @@ -58,14 +58,14 @@ iface deserializer { fn read_bool() -> bool; - fn read_str() -> str; + fn read_str() -> ~str; fn read_f64() -> f64; fn read_f32() -> f32; fn read_float() -> float; // Compound types: - fn read_enum<T:copy>(name: str, f: fn() -> T) -> T; + fn read_enum<T:copy>(name: ~str, f: fn() -> T) -> T; fn read_enum_variant<T:copy>(f: fn(uint) -> T) -> T; fn read_enum_variant_arg<T:copy>(idx: uint, f: fn() -> T) -> T; fn read_vec<T:copy>(f: fn(uint) -> T) -> T; @@ -73,7 +73,7 @@ iface deserializer { fn read_box<T:copy>(f: fn() -> T) -> T; fn read_uniq<T:copy>(f: fn() -> T) -> T; fn read_rec<T:copy>(f: fn() -> T) -> T; - fn read_rec_field<T:copy>(f_name: str, f_idx: uint, f: fn() -> T) -> T; + fn read_rec_field<T:copy>(f_name: ~str, f_idx: uint, f: fn() -> T) -> T; fn read_tup<T:copy>(sz: uint, f: fn() -> T) -> T; fn read_tup_elt<T:copy>(idx: uint, f: fn() -> T) -> T; } @@ -193,11 +193,11 @@ fn deserialize_i64<D: deserializer>(d: D) -> i64 { d.read_i64() } -fn serialize_str<S: serializer>(s: S, v: str) { +fn serialize_str<S: serializer>(s: S, v: ~str) { s.emit_str(v); } -fn deserialize_str<D: deserializer>(d: D) -> str { +fn deserialize_str<D: deserializer>(d: D) -> ~str { d.read_str() } @@ -234,15 +234,15 @@ fn deserialize_bool<D: deserializer>(d: D) -> bool { } fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) { - do s.emit_enum("option") { + do s.emit_enum(~"option") { alt v { none { - do s.emit_enum_variant("none", 0u, 0u) { + do s.emit_enum_variant(~"none", 0u, 0u) { } } some(v) { - do s.emit_enum_variant("some", 1u, 1u) { + do s.emit_enum_variant(~"some", 1u, 1u) { do s.emit_enum_variant_arg(0u) { st(v) } @@ -254,7 +254,7 @@ fn serialize_option<S: serializer,T>(s: S, v: option<T>, st: fn(T)) { fn deserialize_option<D: deserializer,T: copy>(d: D, st: fn() -> T) -> option<T> { - do d.read_enum("option") { + do d.read_enum(~"option") { do d.read_enum_variant |i| { alt check i { 0u { // none diff --git a/src/libstd/sha1.rs b/src/libstd/sha1.rs index dc136af639a..71f8fff2857 100644 --- a/src/libstd/sha1.rs +++ b/src/libstd/sha1.rs @@ -24,7 +24,7 @@ iface sha1 { /// Provide message input as bytes fn input(~[u8]); /// Provide message input as string - fn input_str(str); + fn input_str(~str); /** * Read the digest as a vector of 20 bytes. After calling this no further * input may be provided until reset is called. @@ -34,7 +34,7 @@ iface sha1 { * Read the digest as a hex string. After calling this no further * input may be provided until reset is called. */ - fn result_str() -> str; + fn result_str() -> ~str; /// Reset the SHA-1 state for reuse fn reset(); } @@ -232,11 +232,11 @@ fn sha1() -> sha1 { self.computed = false; } fn input(msg: ~[u8]) { add_input(self, msg); } - fn input_str(msg: str) { add_input(self, str::bytes(msg)); } + fn input_str(msg: ~str) { add_input(self, str::bytes(msg)); } fn result() -> ~[u8] { ret mk_result(self); } - fn result_str() -> str { + fn result_str() -> ~str { let r = mk_result(self); - let mut s = ""; + let mut s = ~""; for vec::each(r) |b| { s += uint::to_str(b as uint, 16u); } ret s; } @@ -260,18 +260,18 @@ mod tests { #[test] fn test() unsafe { - type test = {input: str, output: ~[u8]}; + type test = {input: ~str, output: ~[u8]}; - fn a_million_letter_a() -> str { + fn a_million_letter_a() -> ~str { let mut i = 0; - let mut rs = ""; - while i < 100000 { str::push_str(rs, "aaaaaaaaaa"); i += 1; } + let mut rs = ~""; + while i < 100000 { str::push_str(rs, ~"aaaaaaaaaa"); i += 1; } ret rs; } // Test messages from FIPS 180-1 let fips_180_1_tests: ~[test] = - ~[{input: "abc", + ~[{input: ~"abc", output: ~[0xA9u8, 0x99u8, 0x3Eu8, 0x36u8, 0x47u8, 0x06u8, 0x81u8, 0x6Au8, @@ -279,8 +279,8 @@ mod tests { 0x78u8, 0x50u8, 0xC2u8, 0x6Cu8, 0x9Cu8, 0xD0u8, 0xD8u8, 0x9Du8]}, {input: - "abcdbcdecdefdefgefghfghighij" + - "hijkijkljklmklmnlmnomnopnopq", + ~"abcdbcdecdefdefgefghfghighij" + + ~"hijkijkljklmklmnlmnomnopnopq", output: ~[0x84u8, 0x98u8, 0x3Eu8, 0x44u8, 0x1Cu8, 0x3Bu8, 0xD2u8, 0x6Eu8, @@ -297,14 +297,14 @@ mod tests { // Examples from wikipedia let wikipedia_tests: ~[test] = - ~[{input: "The quick brown fox jumps over the lazy dog", + ~[{input: ~"The quick brown fox jumps over the lazy dog", output: ~[0x2fu8, 0xd4u8, 0xe1u8, 0xc6u8, 0x7au8, 0x2du8, 0x28u8, 0xfcu8, 0xedu8, 0x84u8, 0x9eu8, 0xe1u8, 0xbbu8, 0x76u8, 0xe7u8, 0x39u8, 0x1bu8, 0x93u8, 0xebu8, 0x12u8]}, - {input: "The quick brown fox jumps over the lazy cog", + {input: ~"The quick brown fox jumps over the lazy cog", output: ~[0xdeu8, 0x9fu8, 0x2cu8, 0x7fu8, 0xd2u8, 0x5eu8, 0x1bu8, 0x3au8, diff --git a/src/libstd/tempfile.rs b/src/libstd/tempfile.rs index 536f633f8a7..b6f5c81f57e 100644 --- a/src/libstd/tempfile.rs +++ b/src/libstd/tempfile.rs @@ -5,7 +5,7 @@ import option::{none, some}; import rand; import core::rand::extensions; -fn mkdtemp(prefix: str, suffix: str) -> option<str> { +fn mkdtemp(prefix: ~str, suffix: ~str) -> option<~str> { let r = rand::rng(); let mut i = 0u; while (i < 1000u) { @@ -20,11 +20,11 @@ fn mkdtemp(prefix: str, suffix: str) -> option<str> { #[test] fn test_mkdtemp() { - let r = mkdtemp("./", "foobar"); + let r = mkdtemp(~"./", ~"foobar"); alt r { some(p) { os::remove_dir(p); - assert(str::ends_with(p, "foobar")); + assert(str::ends_with(p, ~"foobar")); } _ { assert(false); } } diff --git a/src/libstd/term.rs b/src/libstd/term.rs index 24d0442dfe2..aa2d52822be 100644 --- a/src/libstd/term.rs +++ b/src/libstd/term.rs @@ -33,9 +33,9 @@ fn reset(writer: io::writer) { /// Returns true if the terminal supports color fn color_supported() -> bool { - let supported_terms = ~["xterm-color", "xterm", - "screen-bce", "xterm-256color"]; - ret alt os::getenv("TERM") { + let supported_terms = ~[~"xterm-color", ~"xterm", + ~"screen-bce", ~"xterm-256color"]; + ret alt os::getenv(~"TERM") { option::some(env) { for vec::each(supported_terms) |term| { if str::eq(term, env) { ret true; } diff --git a/src/libstd/test.rs b/src/libstd/test.rs index a4acc097ab2..d42bca74508 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -30,7 +30,7 @@ extern mod rustrt { // paths; i.e. it should be a series of identifiers seperated by double // colons. This way if some test runner wants to arrange the tests // hierarchically it may. -type test_name = str; +type test_name = ~str; // A function that runs a test. If the function returns successfully, // the test succeeds; if the function fails then the test fails. We @@ -49,24 +49,24 @@ type test_desc = { // The default console test runner. It accepts the command line // arguments and a vector of test_descs (generated at compile time). -fn test_main(args: ~[str], tests: ~[test_desc]) { +fn test_main(args: ~[~str], tests: ~[test_desc]) { let opts = alt parse_opts(args) { either::left(o) { o } either::right(m) { fail m } }; - if !run_tests_console(opts, tests) { fail "Some tests failed"; } + if !run_tests_console(opts, tests) { fail ~"Some tests failed"; } } -type test_opts = {filter: option<str>, run_ignored: bool, - logfile: option<str>}; +type test_opts = {filter: option<~str>, run_ignored: bool, + logfile: option<~str>}; -type opt_res = either<test_opts, str>; +type opt_res = either<test_opts, ~str>; // Parses command line arguments into test options -fn parse_opts(args: ~[str]) -> opt_res { +fn parse_opts(args: ~[~str]) -> opt_res { let args_ = vec::tail(args); - let opts = ~[getopts::optflag("ignored"), getopts::optopt("logfile")]; + let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")]; let match = alt getopts::getopts(args_, opts) { ok(m) { m } @@ -78,8 +78,8 @@ fn parse_opts(args: ~[str]) -> opt_res { option::some(match.free[0]) } else { option::none }; - let run_ignored = getopts::opt_present(match, "ignored"); - let logfile = getopts::opt_maybe_str(match, "logfile"); + let run_ignored = getopts::opt_present(match, ~"ignored"); + let logfile = getopts::opt_maybe_str(match, ~"logfile"); let test_opts = {filter: filter, run_ignored: run_ignored, logfile: logfile}; @@ -107,7 +107,7 @@ fn run_tests_console(opts: test_opts, alt event { te_filtered(filtered_tests) { st.total = vec::len(filtered_tests); - let noun = if st.total != 1u { "tests" } else { "test" }; + let noun = if st.total != 1u { ~"tests" } else { ~"test" }; st.out.write_line(#fmt["\nrunning %u %s", st.total, noun]); } te_wait(test) { st.out.write_str(#fmt["test %s ... ", test.name]); } @@ -122,18 +122,18 @@ fn run_tests_console(opts: test_opts, tr_ok { st.passed += 1u; write_ok(st.out, st.use_color); - st.out.write_line(""); + st.out.write_line(~""); } tr_failed { st.failed += 1u; write_failed(st.out, st.use_color); - st.out.write_line(""); + st.out.write_line(~""); vec::push(st.failures, copy test); } tr_ignored { st.ignored += 1u; write_ignored(st.out, st.use_color); - st.out.write_line(""); + st.out.write_line(~""); } } } @@ -184,25 +184,25 @@ fn run_tests_console(opts: test_opts, fn write_log(out: io::writer, result: test_result, test: test_desc) { out.write_line(#fmt("%s %s", alt result { - tr_ok { "ok" } - tr_failed { "failed" } - tr_ignored { "ignored" } + tr_ok { ~"ok" } + tr_failed { ~"failed" } + tr_ignored { ~"ignored" } }, test.name)); } fn write_ok(out: io::writer, use_color: bool) { - write_pretty(out, "ok", term::color_green, use_color); + write_pretty(out, ~"ok", term::color_green, use_color); } fn write_failed(out: io::writer, use_color: bool) { - write_pretty(out, "FAILED", term::color_red, use_color); + write_pretty(out, ~"FAILED", term::color_red, use_color); } fn write_ignored(out: io::writer, use_color: bool) { - write_pretty(out, "ignored", term::color_yellow, use_color); + write_pretty(out, ~"ignored", term::color_yellow, use_color); } - fn write_pretty(out: io::writer, word: str, color: u8, use_color: bool) { + fn write_pretty(out: io::writer, word: ~str, color: u8, use_color: bool) { if use_color && term::color_supported() { term::fg(out, color); } @@ -214,7 +214,7 @@ fn run_tests_console(opts: test_opts, } fn print_failures(st: console_test_state) { - st.out.write_line("\nfailures:"); + st.out.write_line(~"\nfailures:"); let failures = copy st.failures; let failures = vec::map(failures, |test| test.name); let failures = sort::merge_sort(str::le, failures); @@ -229,14 +229,14 @@ fn should_sort_failures_before_printing_them() { let writer = io::mem_buffer_writer(buffer); let test_a = { - name: "a", + name: ~"a", fn: fn~() { }, ignore: false, should_fail: false }; let test_b = { - name: "b", + name: ~"b", fn: fn~() { }, ignore: false, should_fail: false @@ -256,8 +256,8 @@ fn should_sort_failures_before_printing_them() { let s = io::mem_buffer_str(buffer); - let apos = option::get(str::find_str(s, "a")); - let bpos = option::get(str::find_str(s, "b")); + let apos = option::get(str::find_str(s, ~"a")); + let bpos = option::get(str::find_str(s, ~"b")); assert apos < bpos; } @@ -339,10 +339,10 @@ fn filter_tests(opts: test_opts, let filter_str = alt opts.filter { option::some(f) { f } - option::none { "" } + option::none { ~"" } }; - fn filter_fn(test: test_desc, filter_str: str) -> + fn filter_fn(test: test_desc, filter_str: ~str) -> option<test_desc> { if str::contains(test.name, filter_str) { ret option::some(copy test); @@ -419,7 +419,7 @@ mod tests { fn do_not_run_ignored_tests() { fn f() { fail; } let desc = { - name: "whatever", + name: ~"whatever", fn: f, ignore: true, should_fail: false @@ -435,7 +435,7 @@ mod tests { fn ignored_tests_result_in_ignored() { fn f() { } let desc = { - name: "whatever", + name: ~"whatever", fn: f, ignore: true, should_fail: false @@ -452,7 +452,7 @@ mod tests { fn test_should_fail() { fn f() { fail; } let desc = { - name: "whatever", + name: ~"whatever", fn: f, ignore: false, should_fail: true @@ -468,7 +468,7 @@ mod tests { fn test_should_fail_but_succeeds() { fn f() { } let desc = { - name: "whatever", + name: ~"whatever", fn: f, ignore: false, should_fail: true @@ -482,17 +482,17 @@ mod tests { #[test] fn first_free_arg_should_be_a_filter() { - let args = ~["progname", "filter"]; + let args = ~[~"progname", ~"filter"]; let opts = alt parse_opts(args) { either::left(o) { o } - _ { fail "Malformed arg in first_free_arg_should_be_a_filter"; } }; - assert (str::eq("filter", option::get(opts.filter))); + _ { fail ~"Malformed arg in first_free_arg_should_be_a_filter"; } }; + assert (str::eq(~"filter", option::get(opts.filter))); } #[test] fn parse_ignored_flag() { - let args = ~["progname", "filter", "--ignored"]; + let args = ~[~"progname", ~"filter", ~"--ignored"]; let opts = alt parse_opts(args) { either::left(o) { o } - _ { fail "Malformed arg in parse_ignored_flag"; } }; + _ { fail ~"Malformed arg in parse_ignored_flag"; } }; assert (opts.run_ignored); } @@ -504,12 +504,12 @@ mod tests { let opts = {filter: option::none, run_ignored: true, logfile: option::none}; let tests = - ~[{name: "1", fn: fn~() { }, ignore: true, should_fail: false}, - {name: "2", fn: fn~() { }, ignore: false, should_fail: false}]; + ~[{name: ~"1", fn: fn~() { }, ignore: true, should_fail: false}, + {name: ~"2", fn: fn~() { }, ignore: false, should_fail: false}]; let filtered = filter_tests(opts, tests); assert (vec::len(filtered) == 1u); - assert (filtered[0].name == "1"); + assert (filtered[0].name == ~"1"); assert (filtered[0].ignore == false); } @@ -519,12 +519,12 @@ mod tests { logfile: option::none}; let names = - ~["sha1::test", "int::test_to_str", "int::test_pow", - "test::do_not_run_ignored_tests", - "test::ignored_tests_result_in_ignored", - "test::first_free_arg_should_be_a_filter", - "test::parse_ignored_flag", "test::filter_for_ignored_option", - "test::sort_tests"]; + ~[~"sha1::test", ~"int::test_to_str", ~"int::test_pow", + ~"test::do_not_run_ignored_tests", + ~"test::ignored_tests_result_in_ignored", + ~"test::first_free_arg_should_be_a_filter", + ~"test::parse_ignored_flag", ~"test::filter_for_ignored_option", + ~"test::sort_tests"]; let tests = { let testfn = fn~() { }; @@ -539,11 +539,13 @@ mod tests { let filtered = filter_tests(opts, tests); let expected = - ~["int::test_pow", "int::test_to_str", "sha1::test", - "test::do_not_run_ignored_tests", "test::filter_for_ignored_option", - "test::first_free_arg_should_be_a_filter", - "test::ignored_tests_result_in_ignored", "test::parse_ignored_flag", - "test::sort_tests"]; + ~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test", + ~"test::do_not_run_ignored_tests", + ~"test::filter_for_ignored_option", + ~"test::first_free_arg_should_be_a_filter", + ~"test::ignored_tests_result_in_ignored", + ~"test::parse_ignored_flag", + ~"test::sort_tests"]; let pairs = vec::zip(expected, filtered); diff --git a/src/libstd/time.rs b/src/libstd/time.rs index 3f3749cb064..553592b10bd 100644 --- a/src/libstd/time.rs +++ b/src/libstd/time.rs @@ -76,7 +76,7 @@ type tm = { tm_yday: i32, // days since January 1 ~[0-365] tm_isdst: i32, // Daylight Savings Time flag tm_gmtoff: i32, // offset from UTC in seconds - tm_zone: str, // timezone abbreviation + tm_zone: ~str, // timezone abbreviation tm_nsec: i32, // nanoseconds }; @@ -92,7 +92,7 @@ fn empty_tm() -> tm { tm_yday: 0_i32, tm_isdst: 0_i32, tm_gmtoff: 0_i32, - tm_zone: "", + tm_zone: ~"", tm_nsec: 0_i32, } } @@ -124,7 +124,7 @@ fn now() -> tm { } /// Parses the time from the string according to the format string. -fn strptime(s: str, format: str) -> result<tm, str> { +fn strptime(s: ~str, format: ~str) -> result<tm, ~str> { type tm_mut = { mut tm_sec: i32, mut tm_min: i32, @@ -136,11 +136,11 @@ fn strptime(s: str, format: str) -> result<tm, str> { mut tm_yday: i32, mut tm_isdst: i32, mut tm_gmtoff: i32, - mut tm_zone: str, + mut tm_zone: ~str, mut tm_nsec: i32, }; - fn match_str(s: str, pos: uint, needle: str) -> bool { + fn match_str(s: ~str, pos: uint, needle: ~str) -> bool { let mut i = pos; for str::each(needle) |ch| { if s[i] != ch { @@ -151,7 +151,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { ret true; } - fn match_strs(s: str, pos: uint, strs: ~[(str, i32)]) + fn match_strs(s: ~str, pos: uint, strs: ~[(~str, i32)]) -> option<(i32, uint)> { let mut i = 0u; let len = vec::len(strs); @@ -167,7 +167,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { none } - fn match_digits(s: str, pos: uint, digits: uint, ws: bool) + fn match_digits(s: ~str, pos: uint, digits: uint, ws: bool) -> option<(i32, uint)> { let mut pos = pos; let mut value = 0_i32; @@ -190,7 +190,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { some((value, pos)) } - fn parse_char(s: str, pos: uint, c: char) -> result<uint, str> { + fn parse_char(s: ~str, pos: uint, c: char) -> result<uint, ~str> { let {ch, next} = str::char_range_at(s, pos); if c == ch { @@ -202,73 +202,73 @@ fn strptime(s: str, format: str) -> result<tm, str> { } } - fn parse_type(s: str, pos: uint, ch: char, tm: tm_mut) - -> result<uint, str> { + fn parse_type(s: ~str, pos: uint, ch: char, tm: tm_mut) + -> result<uint, ~str> { alt ch { 'A' { alt match_strs(s, pos, ~[ - ("Sunday", 0_i32), - ("Monday", 1_i32), - ("Tuesday", 2_i32), - ("Wednesday", 3_i32), - ("Thursday", 4_i32), - ("Friday", 5_i32), - ("Saturday", 6_i32) + (~"Sunday", 0_i32), + (~"Monday", 1_i32), + (~"Tuesday", 2_i32), + (~"Wednesday", 3_i32), + (~"Thursday", 4_i32), + (~"Friday", 5_i32), + (~"Saturday", 6_i32) ]) { some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err("Invalid day") } + none { err(~"Invalid day") } } } 'a' { alt match_strs(s, pos, ~[ - ("Sun", 0_i32), - ("Mon", 1_i32), - ("Tue", 2_i32), - ("Wed", 3_i32), - ("Thu", 4_i32), - ("Fri", 5_i32), - ("Sat", 6_i32) + (~"Sun", 0_i32), + (~"Mon", 1_i32), + (~"Tue", 2_i32), + (~"Wed", 3_i32), + (~"Thu", 4_i32), + (~"Fri", 5_i32), + (~"Sat", 6_i32) ]) { some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err("Invalid day") } + none { err(~"Invalid day") } } } 'B' { alt match_strs(s, pos, ~[ - ("January", 0_i32), - ("February", 1_i32), - ("March", 2_i32), - ("April", 3_i32), - ("May", 4_i32), - ("June", 5_i32), - ("July", 6_i32), - ("August", 7_i32), - ("September", 8_i32), - ("October", 9_i32), - ("November", 10_i32), - ("December", 11_i32) + (~"January", 0_i32), + (~"February", 1_i32), + (~"March", 2_i32), + (~"April", 3_i32), + (~"May", 4_i32), + (~"June", 5_i32), + (~"July", 6_i32), + (~"August", 7_i32), + (~"September", 8_i32), + (~"October", 9_i32), + (~"November", 10_i32), + (~"December", 11_i32) ]) { some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) } - none { err("Invalid month") } + none { err(~"Invalid month") } } } 'b' | 'h' { alt match_strs(s, pos, ~[ - ("Jan", 0_i32), - ("Feb", 1_i32), - ("Mar", 2_i32), - ("Apr", 3_i32), - ("May", 4_i32), - ("Jun", 5_i32), - ("Jul", 6_i32), - ("Aug", 7_i32), - ("Sep", 8_i32), - ("Oct", 9_i32), - ("Nov", 10_i32), - ("Dec", 11_i32) + (~"Jan", 0_i32), + (~"Feb", 1_i32), + (~"Mar", 2_i32), + (~"Apr", 3_i32), + (~"May", 4_i32), + (~"Jun", 5_i32), + (~"Jul", 6_i32), + (~"Aug", 7_i32), + (~"Sep", 8_i32), + (~"Oct", 9_i32), + (~"Nov", 10_i32), + (~"Dec", 11_i32) ]) { some(item) { let (v, pos) = item; tm.tm_mon = v; ok(pos) } - none { err("Invalid month") } + none { err(~"Invalid month") } } } 'C' { @@ -278,7 +278,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_year += (v * 100_i32) - 1900_i32; ok(pos) } - none { err("Invalid year") } + none { err(~"Invalid year") } } } 'c' { @@ -302,13 +302,13 @@ fn strptime(s: str, format: str) -> result<tm, str> { 'd' { alt match_digits(s, pos, 2u, false) { some(item) { let (v, pos) = item; tm.tm_mday = v; ok(pos) } - none { err("Invalid day of the month") } + none { err(~"Invalid day of the month") } } } 'e' { alt match_digits(s, pos, 2u, true) { some(item) { let (v, pos) = item; tm.tm_mday = v; ok(pos) } - none { err("Invalid day of the month") } + none { err(~"Invalid day of the month") } } } 'F' { @@ -322,7 +322,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) } - none { err("Invalid hour") } + none { err(~"Invalid hour") } } } 'I' { @@ -333,7 +333,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; ok(pos) } - none { err("Invalid hour") } + none { err(~"Invalid hour") } } } 'j' { @@ -344,14 +344,14 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_yday = v - 1_i32; ok(pos) } - none { err("Invalid year") } + none { err(~"Invalid year") } } } 'k' { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, true) { some(item) { let (v, pos) = item; tm.tm_hour = v; ok(pos) } - none { err("Invalid hour") } + none { err(~"Invalid hour") } } } 'l' { @@ -362,14 +362,14 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_hour = if v == 12_i32 { 0_i32 } else { v }; ok(pos) } - none { err("Invalid hour") } + none { err(~"Invalid hour") } } } 'M' { // FIXME (#2350): range check. alt match_digits(s, pos, 2u, false) { some(item) { let (v, pos) = item; tm.tm_min = v; ok(pos) } - none { err("Invalid minute") } + none { err(~"Invalid minute") } } } 'm' { @@ -380,20 +380,20 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_mon = v - 1_i32; ok(pos) } - none { err("Invalid month") } + none { err(~"Invalid month") } } } 'n' { parse_char(s, pos, '\n') } 'P' { - alt match_strs(s, pos, ~[("am", 0_i32), ("pm", 12_i32)]) { + alt match_strs(s, pos, ~[(~"am", 0_i32), (~"pm", 12_i32)]) { some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) } - none { err("Invalid hour") } + none { err(~"Invalid hour") } } } 'p' { - alt match_strs(s, pos, ~[("AM", 0_i32), ("PM", 12_i32)]) { + alt match_strs(s, pos, ~[(~"AM", 0_i32), (~"PM", 12_i32)]) { some(item) { let (v, pos) = item; tm.tm_hour += v; ok(pos) } - none { err("Invalid hour") } + none { err(~"Invalid hour") } } } 'R' { @@ -418,7 +418,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_sec = v; ok(pos) } - none { err("Invalid second") } + none { err(~"Invalid second") } } } //'s' {} @@ -438,7 +438,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_wday = v; ok(pos) } - none { err("Invalid weekday") } + none { err(~"Invalid weekday") } } } 'v' { @@ -453,7 +453,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { // FIXME (#2350): range check. alt match_digits(s, pos, 1u, false) { some(item) { let (v, pos) = item; tm.tm_wday = v; ok(pos) } - none { err("Invalid weekday") } + none { err(~"Invalid weekday") } } } //'X' {} @@ -466,7 +466,7 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_year = v - 1900_i32; ok(pos) } - none { err("Invalid weekday") } + none { err(~"Invalid weekday") } } } 'y' { @@ -477,13 +477,13 @@ fn strptime(s: str, format: str) -> result<tm, str> { tm.tm_year = v - 1900_i32; ok(pos) } - none { err("Invalid weekday") } + none { err(~"Invalid weekday") } } } 'Z' { - if match_str(s, pos, "UTC") || match_str(s, pos, "GMT") { + if match_str(s, pos, ~"UTC") || match_str(s, pos, ~"GMT") { tm.tm_gmtoff = 0_i32; - tm.tm_zone = "UTC"; + tm.tm_zone = ~"UTC"; ok(pos + 3u) } else { // It's odd, but to maintain compatibility with c's @@ -508,15 +508,15 @@ fn strptime(s: str, format: str) -> result<tm, str> { let (v, pos) = item; if v == 0_i32 { tm.tm_gmtoff = 0_i32; - tm.tm_zone = "UTC"; + tm.tm_zone = ~"UTC"; } ok(pos) } - none { err("Invalid zone offset") } + none { err(~"Invalid zone offset") } } } else { - err("Invalid zone offset") + err(~"Invalid zone offset") } } '%' { parse_char(s, pos, '%') } @@ -538,12 +538,12 @@ fn strptime(s: str, format: str) -> result<tm, str> { mut tm_yday: 0_i32, mut tm_isdst: 0_i32, mut tm_gmtoff: 0_i32, - mut tm_zone: "", + mut tm_zone: ~"", mut tm_nsec: 0_i32, }; let mut pos = 0u; let len = str::len(s); - let mut result = err("Invalid time"); + let mut result = err(~"Invalid time"); while !rdr.eof() && pos < len { let {ch, next} = str::char_range_at(s, pos); @@ -581,62 +581,62 @@ fn strptime(s: str, format: str) -> result<tm, str> { } } -fn strftime(format: str, tm: tm) -> str { - fn parse_type(ch: char, tm: tm) -> str { +fn strftime(format: ~str, tm: tm) -> ~str { + fn parse_type(ch: char, tm: tm) -> ~str { //FIXME (#2350): Implement missing types. alt check ch { 'A' { alt check tm.tm_wday as int { - 0 { "Sunday" } - 1 { "Monday" } - 2 { "Tuesday" } - 3 { "Wednesday" } - 4 { "Thursday" } - 5 { "Friday" } - 6 { "Saturday" } + 0 { ~"Sunday" } + 1 { ~"Monday" } + 2 { ~"Tuesday" } + 3 { ~"Wednesday" } + 4 { ~"Thursday" } + 5 { ~"Friday" } + 6 { ~"Saturday" } } } 'a' { alt check tm.tm_wday as int { - 0 { "Sun" } - 1 { "Mon" } - 2 { "Tue" } - 3 { "Wed" } - 4 { "Thu" } - 5 { "Fri" } - 6 { "Sat" } + 0 { ~"Sun" } + 1 { ~"Mon" } + 2 { ~"Tue" } + 3 { ~"Wed" } + 4 { ~"Thu" } + 5 { ~"Fri" } + 6 { ~"Sat" } } } 'B' { alt check tm.tm_mon as int { - 0 { "January" } - 1 { "February" } - 2 { "March" } - 3 { "April" } - 4 { "May" } - 5 { "June" } - 6 { "July" } - 7 { "August" } - 8 { "September" } - 9 { "October" } - 10 { "November" } - 11 { "December" } + 0 { ~"January" } + 1 { ~"February" } + 2 { ~"March" } + 3 { ~"April" } + 4 { ~"May" } + 5 { ~"June" } + 6 { ~"July" } + 7 { ~"August" } + 8 { ~"September" } + 9 { ~"October" } + 10 { ~"November" } + 11 { ~"December" } } } 'b' | 'h' { alt check tm.tm_mon as int { - 0 { "Jan" } - 1 { "Feb" } - 2 { "Mar" } - 3 { "Apr" } - 4 { "May" } - 5 { "Jun" } - 6 { "Jul" } - 7 { "Aug" } - 8 { "Sep" } - 9 { "Oct" } - 10 { "Nov" } - 11 { "Dec" } + 0 { ~"Jan" } + 1 { ~"Feb" } + 2 { ~"Mar" } + 3 { ~"Apr" } + 4 { ~"May" } + 5 { ~"Jun" } + 6 { ~"Jul" } + 7 { ~"Aug" } + 8 { ~"Sep" } + 9 { ~"Oct" } + 10 { ~"Nov" } + 11 { ~"Dec" } } } 'C' { #fmt("%02d", (tm.tm_year as int + 1900) / 100) } @@ -681,9 +681,9 @@ fn strftime(format: str, tm: tm) -> str { } 'M' { #fmt("%02d", tm.tm_min as int) } 'm' { #fmt("%02d", tm.tm_mon as int + 1) } - 'n' { "\n" } - 'P' { if tm.tm_hour as int < 12 { "am" } else { "pm" } } - 'p' { if tm.tm_hour as int < 12 { "AM" } else { "PM" } } + 'n' { ~"\n" } + 'P' { if tm.tm_hour as int < 12 { ~"am" } else { ~"pm" } } + 'p' { if tm.tm_hour as int < 12 { ~"AM" } else { ~"PM" } } 'R' { #fmt("%s:%s", parse_type('H', tm), @@ -704,7 +704,7 @@ fn strftime(format: str, tm: tm) -> str { parse_type('M', tm), parse_type('S', tm)) } - 't' { "\t" } + 't' { ~"\t" } //'U' {} 'u' { let i = tm.tm_wday as int; @@ -732,11 +732,11 @@ fn strftime(format: str, tm: tm) -> str { #fmt("%c%02d%02d", sign, h as int, m as int) } //'+' {} - '%' { "%" } + '%' { ~"%" } } } - let mut buf = ""; + let mut buf = ~""; do io::with_str_reader(format) |rdr| { while !rdr.eof() { @@ -776,10 +776,10 @@ impl tm for tm { * Return a string of the current time in the form * "Thu Jan 1 00:00:00 1970". */ - fn ctime() -> str { self.strftime("%c") } + fn ctime() -> ~str { self.strftime(~"%c") } /// Formats the time according to the format string. - fn strftime(format: str) -> str { strftime(format, self) } + fn strftime(format: ~str) -> ~str { strftime(format, self) } /** * Returns a time string formatted according to RFC 822. @@ -787,11 +787,11 @@ impl tm for tm { * local: "Thu, 22 Mar 2012 07:53:18 PST" * utc: "Thu, 22 Mar 2012 14:53:18 UTC" */ - fn rfc822() -> str { + fn rfc822() -> ~str { if self.tm_gmtoff == 0_i32 { - self.strftime("%a, %d %b %Y %T GMT") + self.strftime(~"%a, %d %b %Y %T GMT") } else { - self.strftime("%a, %d %b %Y %T %Z") + self.strftime(~"%a, %d %b %Y %T %Z") } } @@ -801,8 +801,8 @@ impl tm for tm { * local: "Thu, 22 Mar 2012 07:53:18 -0700" * utc: "Thu, 22 Mar 2012 14:53:18 -0000" */ - fn rfc822z() -> str { - self.strftime("%a, %d %b %Y %T %z") + fn rfc822z() -> ~str { + self.strftime(~"%a, %d %b %Y %T %z") } /** @@ -811,11 +811,11 @@ impl tm for tm { * local: "2012-02-22T07:53:18-07:00" * utc: "2012-02-22T14:53:18Z" */ - fn rfc3339() -> str { + fn rfc3339() -> ~str { if self.tm_gmtoff == 0_i32 { - self.strftime("%Y-%m-%dT%H:%M:%SZ") + self.strftime(~"%Y-%m-%dT%H:%M:%SZ") } else { - let s = self.strftime("%Y-%m-%dT%H:%M:%S"); + let s = self.strftime(~"%Y-%m-%dT%H:%M:%S"); let sign = if self.tm_gmtoff > 0_i32 { '+' } else { '-' }; let mut m = i32::abs(self.tm_gmtoff) / 60_i32; let h = m / 60_i32; @@ -835,15 +835,15 @@ mod tests { const some_future_date: i64 = 1577836800i64; // 2020-01-01T00:00:00Z let tv1 = get_time(); - log(debug, "tv1=" + uint::str(tv1.sec as uint) + " sec + " - + uint::str(tv1.nsec as uint) + " nsec"); + log(debug, ~"tv1=" + uint::str(tv1.sec as uint) + ~" sec + " + + uint::str(tv1.nsec as uint) + ~" nsec"); assert tv1.sec > some_recent_date; assert tv1.nsec < 1000000000i32; let tv2 = get_time(); - log(debug, "tv2=" + uint::str(tv2.sec as uint) + " sec + " - + uint::str(tv2.nsec as uint) + " nsec"); + log(debug, ~"tv2=" + uint::str(tv2.sec as uint) + ~" sec + " + + uint::str(tv2.nsec as uint) + ~" nsec"); assert tv2.sec >= tv1.sec; assert tv2.sec < some_future_date; @@ -858,22 +858,22 @@ mod tests { let s0 = precise_time_s(); let ns1 = precise_time_ns(); - log(debug, "s0=" + float::to_str(s0, 9u) + " sec"); + log(debug, ~"s0=" + float::to_str(s0, 9u) + ~" sec"); assert s0 > 0.; let ns0 = (s0 * 1000000000.) as u64; - log(debug, "ns0=" + u64::str(ns0) + " ns"); + log(debug, ~"ns0=" + u64::str(ns0) + ~" ns"); - log(debug, "ns1=" + u64::str(ns1) + " ns"); + log(debug, ~"ns1=" + u64::str(ns1) + ~" ns"); assert ns1 >= ns0; let ns2 = precise_time_ns(); - log(debug, "ns2=" + u64::str(ns2) + " ns"); + log(debug, ~"ns2=" + u64::str(ns2) + ~" ns"); assert ns2 >= ns1; } #[test] fn test_at_utc() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); let time = { sec: 1234567890_i64, nsec: 54321_i32 }; @@ -889,13 +889,13 @@ mod tests { assert utc.tm_yday == 43_i32; assert utc.tm_isdst == 0_i32; assert utc.tm_gmtoff == 0_i32; - assert utc.tm_zone == "UTC"; + assert utc.tm_zone == ~"UTC"; assert utc.tm_nsec == 54321_i32; } #[test] fn test_at() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); let time = { sec: 1234567890_i64, nsec: 54321_i32 }; @@ -917,14 +917,14 @@ mod tests { // FIXME (#2350): We should probably standardize on the timezone // abbreviation. let zone = local.tm_zone; - assert zone == "PST" || zone == "Pacific Standard Time"; + assert zone == ~"PST" || zone == ~"Pacific Standard Time"; assert local.tm_nsec == 54321_i32; } #[test] fn test_to_timespec() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); let time = { sec: 1234567890_i64, nsec: 54321_i32 }; @@ -936,7 +936,7 @@ mod tests { #[test] fn test_conversions() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); let time = { sec: 1234567890_i64, nsec: 54321_i32 }; @@ -953,10 +953,10 @@ mod tests { #[test] fn test_strptime() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); - alt strptime("", "") { + alt strptime(~"", ~"") { ok(tm) { assert tm.tm_sec == 0_i32; assert tm.tm_min == 0_i32; @@ -967,17 +967,18 @@ mod tests { assert tm.tm_wday == 0_i32; assert tm.tm_isdst== 0_i32; assert tm.tm_gmtoff == 0_i32; - assert tm.tm_zone == ""; + assert tm.tm_zone == ~""; assert tm.tm_nsec == 0_i32; } err(_) {} } - let format = "%a %b %e %T %Y"; - assert strptime("", format) == err("Invalid time"); - assert strptime("Fri Feb 13 15:31:30", format) == err("Invalid time"); + let format = ~"%a %b %e %T %Y"; + assert strptime(~"", format) == err(~"Invalid time"); + assert strptime(~"Fri Feb 13 15:31:30", format) + == err(~"Invalid time"); - alt strptime("Fri Feb 13 15:31:30 2009", format) { + alt strptime(~"Fri Feb 13 15:31:30 2009", format) { err(e) { fail e } ok(tm) { assert tm.tm_sec == 30_i32; @@ -990,12 +991,12 @@ mod tests { assert tm.tm_yday == 0_i32; assert tm.tm_isdst == 0_i32; assert tm.tm_gmtoff == 0_i32; - assert tm.tm_zone == ""; + assert tm.tm_zone == ~""; assert tm.tm_nsec == 0_i32; } } - fn test(s: str, format: str) -> bool { + fn test(s: ~str, format: ~str) -> bool { alt strptime(s, format) { ok(tm) { tm.strftime(format) == s } err(e) { fail e } @@ -1003,103 +1004,103 @@ mod tests { } [ - "Sunday", - "Monday", - "Tuesday", - "Wednesday", - "Thursday", - "Friday", - "Saturday" - ]/_.iter(|day| assert test(day, "%A")); + ~"Sunday", + ~"Monday", + ~"Tuesday", + ~"Wednesday", + ~"Thursday", + ~"Friday", + ~"Saturday" + ]/_.iter(|day| assert test(day, ~"%A")); [ - "Sun", - "Mon", - "Tue", - "Wed", - "Thu", - "Fri", - "Sat" - ]/_.iter(|day| assert test(day, "%a")); + ~"Sun", + ~"Mon", + ~"Tue", + ~"Wed", + ~"Thu", + ~"Fri", + ~"Sat" + ]/_.iter(|day| assert test(day, ~"%a")); [ - "January", - "February", - "March", - "April", - "May", - "June", - "July", - "August", - "September", - "October", - "November", - "December" - ]/_.iter(|day| assert test(day, "%B")); + ~"January", + ~"February", + ~"March", + ~"April", + ~"May", + ~"June", + ~"July", + ~"August", + ~"September", + ~"October", + ~"November", + ~"December" + ]/_.iter(|day| assert test(day, ~"%B")); [ - "Jan", - "Feb", - "Mar", - "Apr", - "May", - "Jun", - "Jul", - "Aug", - "Sep", - "Oct", - "Nov", - "Dec" - ]/_.iter(|day| assert test(day, "%b")); - - assert test("19", "%C"); - assert test("Fri Feb 13 23:31:30 2009", "%c"); - assert test("02/13/09", "%D"); - assert test("03", "%d"); - assert test("13", "%d"); - assert test(" 3", "%e"); - assert test("13", "%e"); - assert test("2009-02-13", "%F"); - assert test("03", "%H"); - assert test("13", "%H"); - assert test("03", "%I"); // FIXME (#2350): flesh out - assert test("11", "%I"); // FIXME (#2350): flesh out - assert test("044", "%j"); - assert test(" 3", "%k"); - assert test("13", "%k"); - assert test(" 1", "%l"); - assert test("11", "%l"); - assert test("03", "%M"); - assert test("13", "%M"); - assert test("\n", "%n"); - assert test("am", "%P"); - assert test("pm", "%P"); - assert test("AM", "%p"); - assert test("PM", "%p"); - assert test("23:31", "%R"); - assert test("11:31:30 AM", "%r"); - assert test("11:31:30 PM", "%r"); - assert test("03", "%S"); - assert test("13", "%S"); - assert test("15:31:30", "%T"); - assert test("\t", "%t"); - assert test("1", "%u"); - assert test("7", "%u"); - assert test("13-Feb-2009", "%v"); - assert test("0", "%w"); - assert test("6", "%w"); - assert test("2009", "%Y"); - assert test("09", "%y"); - assert strptime("UTC", "%Z").get().tm_zone == "UTC"; - assert strptime("PST", "%Z").get().tm_zone == ""; - assert strptime("-0000", "%z").get().tm_gmtoff == 0_i32; - assert strptime("-0800", "%z").get().tm_gmtoff == 0_i32; - assert test("%", "%%"); + ~"Jan", + ~"Feb", + ~"Mar", + ~"Apr", + ~"May", + ~"Jun", + ~"Jul", + ~"Aug", + ~"Sep", + ~"Oct", + ~"Nov", + ~"Dec" + ]/_.iter(|day| assert test(day, ~"%b")); + + assert test(~"19", ~"%C"); + assert test(~"Fri Feb 13 23:31:30 2009", ~"%c"); + assert test(~"02/13/09", ~"%D"); + assert test(~"03", ~"%d"); + assert test(~"13", ~"%d"); + assert test(~" 3", ~"%e"); + assert test(~"13", ~"%e"); + assert test(~"2009-02-13", ~"%F"); + assert test(~"03", ~"%H"); + assert test(~"13", ~"%H"); + assert test(~"03", ~"%I"); // FIXME (#2350): flesh out + assert test(~"11", ~"%I"); // FIXME (#2350): flesh out + assert test(~"044", ~"%j"); + assert test(~" 3", ~"%k"); + assert test(~"13", ~"%k"); + assert test(~" 1", ~"%l"); + assert test(~"11", ~"%l"); + assert test(~"03", ~"%M"); + assert test(~"13", ~"%M"); + assert test(~"\n", ~"%n"); + assert test(~"am", ~"%P"); + assert test(~"pm", ~"%P"); + assert test(~"AM", ~"%p"); + assert test(~"PM", ~"%p"); + assert test(~"23:31", ~"%R"); + assert test(~"11:31:30 AM", ~"%r"); + assert test(~"11:31:30 PM", ~"%r"); + assert test(~"03", ~"%S"); + assert test(~"13", ~"%S"); + assert test(~"15:31:30", ~"%T"); + assert test(~"\t", ~"%t"); + assert test(~"1", ~"%u"); + assert test(~"7", ~"%u"); + assert test(~"13-Feb-2009", ~"%v"); + assert test(~"0", ~"%w"); + assert test(~"6", ~"%w"); + assert test(~"2009", ~"%Y"); + assert test(~"09", ~"%y"); + assert strptime(~"UTC", ~"%Z").get().tm_zone == ~"UTC"; + assert strptime(~"PST", ~"%Z").get().tm_zone == ~""; + assert strptime(~"-0000", ~"%z").get().tm_gmtoff == 0_i32; + assert strptime(~"-0800", ~"%z").get().tm_gmtoff == 0_i32; + assert test(~"%", ~"%%"); } #[test] fn test_ctime() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); let time = { sec: 1234567890_i64, nsec: 54321_i32 }; @@ -1108,81 +1109,81 @@ mod tests { #error("test_ctime: %? %?", utc.ctime(), local.ctime()); - assert utc.ctime() == "Fri Feb 13 23:31:30 2009"; - assert local.ctime() == "Fri Feb 13 15:31:30 2009"; + assert utc.ctime() == ~"Fri Feb 13 23:31:30 2009"; + assert local.ctime() == ~"Fri Feb 13 15:31:30 2009"; } #[test] fn test_strftime() { - os::setenv("TZ", "America/Los_Angeles"); + os::setenv(~"TZ", ~"America/Los_Angeles"); tzset(); let time = { sec: 1234567890_i64, nsec: 54321_i32 }; let utc = at_utc(time); let local = at(time); - assert local.strftime("") == ""; - assert local.strftime("%A") == "Friday"; - assert local.strftime("%a") == "Fri"; - assert local.strftime("%B") == "February"; - assert local.strftime("%b") == "Feb"; - assert local.strftime("%C") == "20"; - assert local.strftime("%c") == "Fri Feb 13 15:31:30 2009"; - assert local.strftime("%D") == "02/13/09"; - assert local.strftime("%d") == "13"; - assert local.strftime("%e") == "13"; - assert local.strftime("%F") == "2009-02-13"; + assert local.strftime(~"") == ~""; + assert local.strftime(~"%A") == ~"Friday"; + assert local.strftime(~"%a") == ~"Fri"; + assert local.strftime(~"%B") == ~"February"; + assert local.strftime(~"%b") == ~"Feb"; + assert local.strftime(~"%C") == ~"20"; + assert local.strftime(~"%c") == ~"Fri Feb 13 15:31:30 2009"; + assert local.strftime(~"%D") == ~"02/13/09"; + assert local.strftime(~"%d") == ~"13"; + assert local.strftime(~"%e") == ~"13"; + assert local.strftime(~"%F") == ~"2009-02-13"; // assert local.strftime("%G") == "2009"; // assert local.strftime("%g") == "09"; - assert local.strftime("%H") == "15"; - assert local.strftime("%I") == "03"; - assert local.strftime("%j") == "044"; - assert local.strftime("%k") == "15"; - assert local.strftime("%l") == " 3"; - assert local.strftime("%M") == "31"; - assert local.strftime("%m") == "02"; - assert local.strftime("%n") == "\n"; - assert local.strftime("%P") == "pm"; - assert local.strftime("%p") == "PM"; - assert local.strftime("%R") == "15:31"; - assert local.strftime("%r") == "03:31:30 PM"; - assert local.strftime("%S") == "30"; - assert local.strftime("%s") == "1234567890"; - assert local.strftime("%T") == "15:31:30"; - assert local.strftime("%t") == "\t"; + assert local.strftime(~"%H") == ~"15"; + assert local.strftime(~"%I") == ~"03"; + assert local.strftime(~"%j") == ~"044"; + assert local.strftime(~"%k") == ~"15"; + assert local.strftime(~"%l") == ~" 3"; + assert local.strftime(~"%M") == ~"31"; + assert local.strftime(~"%m") == ~"02"; + assert local.strftime(~"%n") == ~"\n"; + assert local.strftime(~"%P") == ~"pm"; + assert local.strftime(~"%p") == ~"PM"; + assert local.strftime(~"%R") == ~"15:31"; + assert local.strftime(~"%r") == ~"03:31:30 PM"; + assert local.strftime(~"%S") == ~"30"; + assert local.strftime(~"%s") == ~"1234567890"; + assert local.strftime(~"%T") == ~"15:31:30"; + assert local.strftime(~"%t") == ~"\t"; // assert local.strftime("%U") == "06"; - assert local.strftime("%u") == "5"; + assert local.strftime(~"%u") == ~"5"; // assert local.strftime("%V") == "07"; - assert local.strftime("%v") == "13-Feb-2009"; + assert local.strftime(~"%v") == ~"13-Feb-2009"; // assert local.strftime("%W") == "06"; - assert local.strftime("%w") == "5"; + assert local.strftime(~"%w") == ~"5"; // handle "%X" // handle "%x" - assert local.strftime("%Y") == "2009"; - assert local.strftime("%y") == "09"; + assert local.strftime(~"%Y") == ~"2009"; + assert local.strftime(~"%y") == ~"09"; // FIXME (#2350): We should probably standardize on the timezone // abbreviation. - let zone = local.strftime("%Z"); - assert zone == "PST" || zone == "Pacific Standard Time"; + let zone = local.strftime(~"%Z"); + assert zone == ~"PST" || zone == ~"Pacific Standard Time"; - assert local.strftime("%z") == "-0800"; - assert local.strftime("%%") == "%"; + assert local.strftime(~"%z") == ~"-0800"; + assert local.strftime(~"%%") == ~"%"; // FIXME (#2350): We should probably standardize on the timezone // abbreviation. let rfc822 = local.rfc822(); - let prefix = "Fri, 13 Feb 2009 15:31:30 "; - assert rfc822 == prefix + "PST" || - rfc822 == prefix + "Pacific Standard Time"; - - assert local.ctime() == "Fri Feb 13 15:31:30 2009"; - assert local.rfc822z() == "Fri, 13 Feb 2009 15:31:30 -0800"; - assert local.rfc3339() == "2009-02-13T15:31:30-08:00"; - - assert utc.ctime() == "Fri Feb 13 23:31:30 2009"; - assert utc.rfc822() == "Fri, 13 Feb 2009 23:31:30 GMT"; - assert utc.rfc822z() == "Fri, 13 Feb 2009 23:31:30 -0000"; - assert utc.rfc3339() == "2009-02-13T23:31:30Z"; + let prefix = ~"Fri, 13 Feb 2009 15:31:30 "; + assert rfc822 == prefix + ~"PST" || + rfc822 == prefix + ~"Pacific Standard Time"; + + assert local.ctime() == ~"Fri Feb 13 15:31:30 2009"; + assert local.rfc822z() == ~"Fri, 13 Feb 2009 15:31:30 -0800"; + assert local.rfc3339() == ~"2009-02-13T15:31:30-08:00"; + + assert utc.ctime() == ~"Fri Feb 13 23:31:30 2009"; + assert utc.rfc822() == ~"Fri, 13 Feb 2009 23:31:30 GMT"; + assert utc.rfc822z() == ~"Fri, 13 Feb 2009 23:31:30 -0000"; + assert utc.rfc3339() == ~"2009-02-13T23:31:30Z"; } } diff --git a/src/libstd/timer.rs b/src/libstd/timer.rs index 87d7dd67577..b72e2c47539 100644 --- a/src/libstd/timer.rs +++ b/src/libstd/timer.rs @@ -41,12 +41,13 @@ fn delayed_send<T: copy send>(iotask: iotask, } else { let error_msg = uv::ll::get_last_err_info(loop_ptr); - fail "timer::delayed_send() start failed: "+error_msg; + fail ~"timer::delayed_send() start failed: " + + error_msg; } } else { let error_msg = uv::ll::get_last_err_info(loop_ptr); - fail "timer::delayed_send() init failed: "+error_msg; + fail ~"timer::delayed_send() init failed: "+error_msg; } }; // delayed_send_cb has been processed by libuv @@ -128,7 +129,7 @@ extern fn delayed_send_cb(handle: *uv::ll::uv_timer_t, else { let loop_ptr = uv::ll::get_loop_for_uv_handle(handle); let error_msg = uv::ll::get_last_err_info(loop_ptr); - fail "timer::sleep() init failed: "+error_msg; + fail ~"timer::sleep() init failed: "+error_msg; } } @@ -232,7 +233,7 @@ mod test { for iter::repeat(times as uint) { let expected = rand::rng().gen_str(16u); - let test_po = comm::port::<str>(); + let test_po = comm::port::<~str>(); let test_ch = comm::chan(test_po); do task::spawn() { diff --git a/src/libstd/treemap.rs b/src/libstd/treemap.rs index 1a3626e4660..3def5fbd0d1 100644 --- a/src/libstd/treemap.rs +++ b/src/libstd/treemap.rs @@ -132,13 +132,13 @@ mod tests { fn u8_map() { let m = treemap(); - let k1 = str::bytes("foo"); - let k2 = str::bytes("bar"); + let k1 = str::bytes(~"foo"); + let k2 = str::bytes(~"bar"); - insert(m, k1, "foo"); - insert(m, k2, "bar"); + insert(m, k1, ~"foo"); + insert(m, k2, ~"bar"); - assert (find(m, k2) == some("bar")); - assert (find(m, k1) == some("foo")); + assert (find(m, k2) == some(~"bar")); + assert (find(m, k1) == some(~"foo")); } } diff --git a/src/libstd/uv_global_loop.rs b/src/libstd/uv_global_loop.rs index 53769757f62..4a7962a977f 100644 --- a/src/libstd/uv_global_loop.rs +++ b/src/libstd/uv_global_loop.rs @@ -118,16 +118,16 @@ mod test { } extern fn simple_timer_cb(timer_ptr: *ll::uv_timer_t, _status: libc::c_int) unsafe { - log(debug, "in simple timer cb"); + log(debug, ~"in simple timer cb"); ll::timer_stop(timer_ptr); let hl_loop = get_gl(); do iotask::interact(hl_loop) |_loop_ptr| { - log(debug, "closing timer"); + log(debug, ~"closing timer"); ll::close(timer_ptr, simple_timer_close_cb); - log(debug, "about to deref exit_ch_ptr"); - log(debug, "after msg sent on deref'd exit_ch"); + log(debug, ~"about to deref exit_ch_ptr"); + log(debug, ~"after msg sent on deref'd exit_ch"); }; - log(debug, "exiting simple timer cb"); + log(debug, ~"exiting simple timer cb"); } fn impl_uv_hl_simple_timer(iotask: iotask) unsafe { @@ -139,7 +139,7 @@ mod test { let timer_handle = ll::timer_t(); let timer_ptr = ptr::addr_of(timer_handle); do iotask::interact(iotask) |loop_ptr| { - log(debug, "user code inside interact loop!!!"); + log(debug, ~"user code inside interact loop!!!"); let init_status = ll::timer_init(loop_ptr, timer_ptr); if(init_status == 0i32) { ll::set_data_for_uv_handle( @@ -150,15 +150,15 @@ mod test { if(start_status == 0i32) { } else { - fail "failure on ll::timer_start()"; + fail ~"failure on ll::timer_start()"; } } else { - fail "failure on ll::timer_init()"; + fail ~"failure on ll::timer_init()"; } }; comm::recv(exit_po); - log(debug, "global_loop timer test: msg recv on exit_po, done.."); + log(debug, ~"global_loop timer test: msg recv on exit_po, done.."); } #[test] @@ -192,7 +192,7 @@ mod test { for iter::repeat(cycles) { comm::recv(exit_po); }; - log(debug, "test_stress_gl_uv_global_loop_high_level_global_timer"+ - " exiting sucessfully!"); + log(debug, ~"test_stress_gl_uv_global_loop_high_level_global_timer"+ + ~" exiting sucessfully!"); } } diff --git a/src/libstd/uv_iotask.rs b/src/libstd/uv_iotask.rs index e38fae0fa72..d049c6f7c7b 100644 --- a/src/libstd/uv_iotask.rs +++ b/src/libstd/uv_iotask.rs @@ -114,10 +114,10 @@ fn run_loop(iotask_ch: chan<iotask>) unsafe { }); iotask_ch.send(iotask); - log(debug, "about to run uv loop"); + log(debug, ~"about to run uv loop"); // enter the loop... this blocks until the loop is done.. ll::run(loop_ptr); - log(debug, "uv loop ended"); + log(debug, ~"uv loop ended"); ll::loop_delete(loop_ptr); } @@ -157,7 +157,7 @@ extern fn wake_up_cb(async_handle: *ll::uv_async_t, } fn begin_teardown(data: *iotask_loop_data) unsafe { - log(debug, "iotask begin_teardown() called, close async_handle"); + log(debug, ~"iotask begin_teardown() called, close async_handle"); let async_handle = (*data).async_handle; ll::close(async_handle as *c_void, tear_down_close_cb); } @@ -250,9 +250,9 @@ mod test { for iter::repeat(7u) { comm::recv(work_exit_po); }; - log(debug, "sending teardown_loop msg.."); + log(debug, ~"sending teardown_loop msg.."); exit(iotask); comm::recv(exit_po); - log(debug, "after recv on exit_po.. exiting.."); + log(debug, ~"after recv on exit_po.. exiting.."); } } diff --git a/src/libstd/uv_ll.rs b/src/libstd/uv_ll.rs index 8407a18c549..56365514da9 100644 --- a/src/libstd/uv_ll.rs +++ b/src/libstd/uv_ll.rs @@ -793,7 +793,7 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t { // yuck :/ rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t); //let result = rustrt::rust_uv_buf_init_2(input, len as size_t); - log(debug, "after rust_uv_buf_init"); + log(debug, ~"after rust_uv_buf_init"); let res_base = get_base_from_buf(out_buf); let res_len = get_len_from_buf(out_buf); //let res_base = get_base_from_buf(result); @@ -803,21 +803,21 @@ unsafe fn buf_init(++input: *u8, len: uint) -> uv_buf_t { ret out_buf; //ret result; } -unsafe fn ip4_addr(ip: str, port: int) +unsafe fn ip4_addr(ip: ~str, port: int) -> sockaddr_in { do str::as_c_str(ip) |ip_buf| { rustrt::rust_uv_ip4_addr(ip_buf as *u8, port as libc::c_int) } } -unsafe fn ip6_addr(ip: str, port: int) +unsafe fn ip6_addr(ip: ~str, port: int) -> sockaddr_in6 { do str::as_c_str(ip) |ip_buf| { rustrt::rust_uv_ip6_addr(ip_buf as *u8, port as libc::c_int) } } -unsafe fn ip4_name(src: &sockaddr_in) -> str { +unsafe fn ip4_name(src: &sockaddr_in) -> ~str { // ipv4 addr max size: 15 + 1 trailing null byte let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8, 0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8]; @@ -834,7 +834,7 @@ unsafe fn ip4_name(src: &sockaddr_in) -> str { str::unsafe::from_buf(dst_buf) } } -unsafe fn ip6_name(src: &sockaddr_in6) -> str { +unsafe fn ip6_name(src: &sockaddr_in6) -> ~str { // ipv6 addr max size: 45 + 1 trailing null byte let dst: ~[u8] = ~[0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8, 0u8,0u8,0u8,0u8,0u8,0u8,0u8,0u8, @@ -854,7 +854,7 @@ unsafe fn ip6_name(src: &sockaddr_in6) -> str { str::unsafe::from_buf(dst_buf) } _ { - "" + ~"" } } } @@ -961,7 +961,7 @@ unsafe fn free_base_of_buf(buf: uv_buf_t) { rustrt::rust_uv_free_base_of_buf(buf); } -unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> str { +unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str { let err = last_error(uv_loop); let err_ptr = ptr::addr_of(err); let err_name = str::unsafe::from_c_str(err_name(err_ptr)); @@ -979,8 +979,8 @@ unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data { } type uv_err_data = { - err_name: str, - err_msg: str + err_name: ~str, + err_msg: ~str }; unsafe fn is_ipv4_addrinfo(input: *addrinfo) -> bool { @@ -1013,7 +1013,7 @@ mod test { type request_wrapper = { write_req: *uv_write_t, req_buf: *~[uv_buf_t], - read_chan: *comm::chan<str> + read_chan: *comm::chan<~str> }; extern fn after_close_cb(handle: *libc::c_void) { @@ -1024,7 +1024,7 @@ mod test { extern fn on_alloc_cb(handle: *libc::c_void, ++suggested_size: libc::size_t) -> uv_buf_t unsafe { - log(debug, "on_alloc_cb!"); + log(debug, ~"on_alloc_cb!"); let char_ptr = malloc_buf_base_of(suggested_size); log(debug, #fmt("on_alloc_cb h: %? char_ptr: %u sugsize: %u", handle, @@ -1056,15 +1056,15 @@ mod test { } else if (nread == -1) { // err .. possibly EOF - log(debug, "read: eof!"); + log(debug, ~"read: eof!"); } else { // nread == 0 .. do nothing, just free buf as below - log(debug, "read: do nothing!"); + log(debug, ~"read: do nothing!"); } // when we're done free_base_of_buf(buf); - log(debug, "CLIENT exiting on_read_cb"); + log(debug, ~"CLIENT exiting on_read_cb"); } extern fn on_write_complete_cb(write_req: *uv_write_t, @@ -1086,7 +1086,7 @@ mod test { let stream = get_stream_handle_from_connect_req(connect_req_ptr); if (status == 0i32) { - log(debug, "on_connect_cb: in status=0 if.."); + log(debug, ~"on_connect_cb: in status=0 if.."); let client_data = get_data_for_req( connect_req_ptr as *libc::c_void) as *request_wrapper; @@ -1107,11 +1107,11 @@ mod test { log(debug, err_msg); assert false; } - log(debug, "finishing on_connect_cb"); + log(debug, ~"finishing on_connect_cb"); } - fn impl_uv_tcp_request(ip: str, port: int, req_str: str, - client_chan: *comm::chan<str>) unsafe { + fn impl_uv_tcp_request(ip: ~str, port: int, req_str: ~str, + client_chan: *comm::chan<~str>) unsafe { let test_loop = loop_new(); let tcp_handle = tcp_t(); let tcp_handle_ptr = ptr::addr_of(tcp_handle); @@ -1143,9 +1143,9 @@ mod test { let tcp_init_result = tcp_init( test_loop as *libc::c_void, tcp_handle_ptr); if (tcp_init_result == 0i32) { - log(debug, "sucessful tcp_init_result"); + log(debug, ~"sucessful tcp_init_result"); - log(debug, "building addr..."); + log(debug, ~"building addr..."); let addr = ip4_addr(ip, port); // FIXME ref #2064 let addr_ptr = ptr::addr_of(addr); @@ -1167,17 +1167,17 @@ mod test { set_data_for_uv_handle( tcp_handle_ptr as *libc::c_void, ptr::addr_of(client_data) as *libc::c_void); - log(debug, "before run tcp req loop"); + log(debug, ~"before run tcp req loop"); run(test_loop); - log(debug, "after run tcp req loop"); + log(debug, ~"after run tcp req loop"); } else { - log(debug, "tcp_connect() failure"); + log(debug, ~"tcp_connect() failure"); assert false; } } else { - log(debug, "tcp_init() failure"); + log(debug, ~"tcp_init() failure"); assert false; } loop_delete(test_loop); @@ -1191,7 +1191,8 @@ mod test { extern fn client_stream_after_close_cb(handle: *libc::c_void) unsafe { - log(debug, "SERVER: closed client stream, now closing server stream"); + log(debug, + ~"SERVER: closed client stream, now closing server stream"); let client_data = get_data_for_uv_handle( handle) as *tcp_server_data; @@ -1202,7 +1203,7 @@ mod test { extern fn after_server_resp_write(req: *uv_write_t) unsafe { let client_stream_ptr = get_stream_handle_from_write_req(req); - log(debug, "SERVER: resp sent... closing client stream"); + log(debug, ~"SERVER: resp sent... closing client stream"); close(client_stream_ptr as *libc::c_void, client_stream_after_close_cb) } @@ -1231,8 +1232,8 @@ mod test { let server_kill_msg = (*client_data).server_kill_msg; let write_req = (*client_data).server_write_req; if (str::contains(request_str, server_kill_msg)) { - log(debug, "SERVER: client req contains kill_msg!"); - log(debug, "SERVER: sending response to client"); + log(debug, ~"SERVER: client req contains kill_msg!"); + log(debug, ~"SERVER: sending response to client"); read_stop(client_stream_ptr); let server_chan = *((*client_data).server_chan); comm::send(server_chan, request_str); @@ -1244,7 +1245,7 @@ mod test { log(debug, #fmt("SERVER: resp write result: %d", write_result as int)); if (write_result != 0i32) { - log(debug, "bad result for server resp write()"); + log(debug, ~"bad result for server resp write()"); log(debug, get_last_err_info( get_loop_for_uv_handle(client_stream_ptr as *libc::c_void))); @@ -1252,26 +1253,26 @@ mod test { } } else { - log(debug, "SERVER: client req !contain kill_msg!"); + log(debug, ~"SERVER: client req !contain kill_msg!"); } } else if (nread == -1) { // err .. possibly EOF - log(debug, "read: eof!"); + log(debug, ~"read: eof!"); } else { // nread == 0 .. do nothing, just free buf as below - log(debug, "read: do nothing!"); + log(debug, ~"read: do nothing!"); } // when we're done free_base_of_buf(buf); - log(debug, "SERVER exiting on_read_cb"); + log(debug, ~"SERVER exiting on_read_cb"); } extern fn server_connection_cb(server_stream_ptr: *uv_stream_t, status: libc::c_int) unsafe { - log(debug, "client connecting!"); + log(debug, ~"client connecting!"); let test_loop = get_loop_for_uv_handle( server_stream_ptr as *libc::c_void); if status != 0i32 { @@ -1289,7 +1290,7 @@ mod test { client_stream_ptr as *libc::c_void, server_data as *libc::c_void); if (client_init_result == 0i32) { - log(debug, "successfully initialized client stream"); + log(debug, ~"successfully initialized client stream"); let accept_result = accept(server_stream_ptr as *libc::c_void, client_stream_ptr as @@ -1301,7 +1302,7 @@ mod test { on_alloc_cb, on_server_read_cb); if (read_result == 0i32) { - log(debug, "successful server read start"); + log(debug, ~"successful server read start"); } else { log(debug, #fmt("server_connection_cb: bad read:%d", @@ -1325,9 +1326,9 @@ mod test { type tcp_server_data = { client: *uv_tcp_t, server: *uv_tcp_t, - server_kill_msg: str, + server_kill_msg: ~str, server_resp_buf: *~[uv_buf_t], - server_chan: *comm::chan<str>, + server_chan: *comm::chan<~str>, server_write_req: *uv_write_t }; @@ -1354,11 +1355,11 @@ mod test { close(async_handle as *libc::c_void, async_close_cb); } - fn impl_uv_tcp_server(server_ip: str, + fn impl_uv_tcp_server(server_ip: ~str, server_port: int, - kill_server_msg: str, - server_resp_msg: str, - server_chan: *comm::chan<str>, + kill_server_msg: ~str, + server_resp_msg: ~str, + server_chan: *comm::chan<~str>, continue_chan: *comm::chan<bool>) unsafe { let test_loop = loop_new(); let tcp_server = tcp_t(); @@ -1408,7 +1409,7 @@ mod test { let bind_result = tcp_bind(tcp_server_ptr, server_addr_ptr); if (bind_result == 0i32) { - log(debug, "successful uv_tcp_bind, listening"); + log(debug, ~"successful uv_tcp_bind, listening"); // uv_listen() let listen_result = listen(tcp_server_ptr as @@ -1428,7 +1429,7 @@ mod test { async_send(continue_async_handle_ptr); // uv_run() run(test_loop); - log(debug, "server uv::run() has returned"); + log(debug, ~"server uv::run() has returned"); } else { log(debug, #fmt("uv_async_init failure: %d", @@ -1459,15 +1460,15 @@ mod test { // this is the impl for a test that is (maybe) ran on a // per-platform/arch basis below fn impl_uv_tcp_server_and_request() unsafe { - let bind_ip = "0.0.0.0"; - let request_ip = "127.0.0.1"; + let bind_ip = ~"0.0.0.0"; + let request_ip = ~"127.0.0.1"; let port = 8887; - let kill_server_msg = "does a dog have buddha nature?"; - let server_resp_msg = "mu!"; - let client_port = comm::port::<str>(); - let client_chan = comm::chan::<str>(client_port); - let server_port = comm::port::<str>(); - let server_chan = comm::chan::<str>(server_port); + let kill_server_msg = ~"does a dog have buddha nature?"; + let server_resp_msg = ~"mu!"; + let client_port = comm::port::<~str>(); + let client_chan = comm::chan::<~str>(client_port); + let server_port = comm::port::<~str>(); + let server_chan = comm::chan::<~str>(server_port); let continue_port = comm::port::<bool>(); let continue_chan = comm::chan::<bool>(continue_port); @@ -1482,9 +1483,9 @@ mod test { }; // block until the server up is.. possibly a race? - log(debug, "before receiving on server continue_port"); + log(debug, ~"before receiving on server continue_port"); comm::recv(continue_port); - log(debug, "received on continue port, set up tcp client"); + log(debug, ~"received on continue port, set up tcp client"); do task::spawn_sched(task::manual_threads(1u)) { impl_uv_tcp_request(request_ip, port, |
