]> git.lizzy.rs Git - rust.git/commitdiff
[std::str] Rename from_utf8_owned_opt() to from_utf8_owned(), drop the old from_utf8_...
authorSimon Sapin <simon.sapin@exyr.org>
Mon, 23 Dec 2013 16:45:01 +0000 (17:45 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Tue, 21 Jan 2014 23:48:48 +0000 (15:48 -0800)
33 files changed:
src/compiletest/procsrv.rs
src/compiletest/runtest.rs
src/libextra/base64.rs
src/libextra/hex.rs
src/libextra/json.rs
src/libextra/stats.rs
src/libextra/terminfo/parser/compiled.rs
src/libextra/time.rs
src/libextra/uuid.rs
src/libextra/workcache.rs
src/librustc/back/link.rs
src/librustc/lib.rs
src/librustc/metadata/encoder.rs
src/librustc/middle/liveness.rs
src/librustdoc/html/render.rs
src/librustdoc/lib.rs
src/librustpkg/source_control.rs
src/librustpkg/tests.rs
src/libstd/fmt/mod.rs
src/libstd/io/fs.rs
src/libstd/io/mod.rs
src/libstd/num/strconv.rs
src/libstd/repr.rs
src/libstd/run.rs
src/libstd/str.rs
src/libsyntax/ext/source_util.rs
src/libsyntax/parse/comments.rs
src/libsyntax/parse/mod.rs
src/libsyntax/print/pprust.rs
src/test/bench/shootout-k-nucleotide.rs
src/test/bench/shootout-meteor.rs
src/test/run-pass/core-run-destroy.rs
src/test/run-pass/ifmt.rs

index f919274f2ed18a396811a23a4713a1dc9b7e1c14..83fb267b0e720528a99a1ecce148f3b0a9de9746 100644 (file)
@@ -66,8 +66,8 @@ pub fn run(lib_path: &str,
 
             Some(Result {
                 status: status,
-                out: str::from_utf8_owned(output),
-                err: str::from_utf8_owned(error)
+                out: str::from_utf8_owned(output).unwrap(),
+                err: str::from_utf8_owned(error).unwrap()
             })
         },
         None => None
index 7fede7f855d12c319249bf75f33e374bfe04e7f7..1d8e5a707edebbc7e6f57dc575565551bf291a88 100644 (file)
@@ -154,7 +154,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
         match props.pp_exact { Some(_) => 1, None => 2 };
 
     let src = File::open(testfile).read_to_end();
-    let src = str::from_utf8_owned(src);
+    let src = str::from_utf8_owned(src).unwrap();
     let mut srcs = ~[src];
 
     let mut round = 0;
@@ -176,7 +176,7 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
         Some(ref file) => {
             let filepath = testfile.dir_path().join(file);
             let s = File::open(&filepath).read_to_end();
-            str::from_utf8_owned(s)
+            str::from_utf8_owned(s).unwrap()
           }
           None => { srcs[srcs.len() - 2u].clone() }
         };
@@ -1100,7 +1100,7 @@ fn disassemble_extract(config: &config, _props: &TestProps,
 
 fn count_extracted_lines(p: &Path) -> uint {
     let x = File::open(&p.with_extension("ll")).read_to_end();
-    let x = str::from_utf8_owned(x);
+    let x = str::from_utf8_owned(x).unwrap();
     x.lines().len()
 }
 
index 1043f700aa7e99bee1ae9e5679529ee637e046b5..1fcce6d01eea1d1eb78d356e190d32927ffc8edf 100644 (file)
@@ -198,7 +198,7 @@ impl<'a> FromBase64 for &'a str {
      *     println!("base64 output: {}", hello_str);
      *     let res = hello_str.from_base64();
      *     if res.is_ok() {
-     *       let optBytes = str::from_utf8_owned_opt(res.unwrap());
+     *       let optBytes = str::from_utf8_owned(res.unwrap());
      *       if optBytes.is_some() {
      *         println!("decoded from base64: {}", optBytes.unwrap());
      *       }
index e5fcd39667de0a37d4487a993970d3e1847e9e1b..343d6aac437a048952e10c71946bea193b4530c8 100644 (file)
@@ -96,7 +96,7 @@ impl<'a> FromHex for &'a str {
      *     println!("{}", hello_str);
      *     let bytes = hello_str.from_hex().unwrap();
      *     println!("{:?}", bytes);
-     *     let result_str = str::from_utf8_owned(bytes);
+     *     let result_str = str::from_utf8_owned(bytes).unwrap();
      *     println!("{}", result_str);
      * }
      * ```
index 9fcafee8c51bb3900d7caa87fdf88dd860b8e0d8..a35c474337d61ec2106c067d5df4d0db54f4135a 100644 (file)
@@ -312,7 +312,7 @@ pub fn buffer_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~[u8]  {
     /// Encode the specified struct into a json str
     pub fn str_encode<T:Encodable<Encoder<'a>>>(to_encode_object: &T) -> ~str  {
         let buff:~[u8] = Encoder::buffer_encode(to_encode_object);
-        str::from_utf8_owned(buff)
+        str::from_utf8_owned(buff).unwrap()
     }
 }
 
@@ -684,7 +684,7 @@ pub fn to_pretty_writer(&self, wr: &mut io::Writer) {
     pub fn to_pretty_str(&self) -> ~str {
         let mut s = MemWriter::new();
         self.to_pretty_writer(&mut s as &mut io::Writer);
-        str::from_utf8_owned(s.unwrap())
+        str::from_utf8_owned(s.unwrap()).unwrap()
     }
 }
 
@@ -1067,7 +1067,7 @@ fn parse_object(&mut self) -> Result<Json, Error> {
 
 /// Decodes a json value from an `&mut io::Reader`
 pub fn from_reader(rdr: &mut io::Reader) -> Result<Json, Error> {
-    let s = str::from_utf8_owned(rdr.read_to_end());
+    let s = str::from_utf8_owned(rdr.read_to_end()).unwrap();
     let mut parser = Parser::new(s.chars());
     parser.parse()
 }
@@ -1541,7 +1541,7 @@ impl to_str::ToStr for Json {
     fn to_str(&self) -> ~str {
         let mut s = MemWriter::new();
         self.to_writer(&mut s as &mut io::Writer);
-        str::from_utf8_owned(s.unwrap())
+        str::from_utf8_owned(s.unwrap()).unwrap()
     }
 }
 
@@ -1732,7 +1732,7 @@ fn with_str_writer(f: |&mut io::Writer|) -> ~str {
 
         let mut m = MemWriter::new();
         f(&mut m as &mut io::Writer);
-        str::from_utf8_owned(m.unwrap())
+        str::from_utf8_owned(m.unwrap()).unwrap()
     }
 
     #[test]
index 2e95357541080735afa36d30590a3d78944947d7..096e588277468d78473d285efdef21340f1594d0 100644 (file)
@@ -1001,7 +1001,7 @@ fn t(s: &Summary, expected: ~str) {
             use std::io::MemWriter;
             let mut m = MemWriter::new();
             write_boxplot(&mut m as &mut io::Writer, s, 30);
-            let out = str::from_utf8_owned(m.unwrap());
+            let out = str::from_utf8_owned(m.unwrap()).unwrap();
             assert_eq!(out, expected);
         }
 
index 8d63021d51b8832e6f6eacde513c002ad90924b7..23478728330ebc69557e217a8dc9d7f7942d9ed2 100644 (file)
@@ -216,7 +216,7 @@ pub fn parse(file: &mut io::Reader,
     }
 
     // don't read NUL
-    let names_str = str::from_utf8_owned(file.read_bytes(names_bytes as uint - 1));
+    let names_str = str::from_utf8_owned(file.read_bytes(names_bytes as uint - 1)).unwrap();
 
     let term_names: ~[~str] = names_str.split('|').map(|s| s.to_owned()).collect();
 
index 9d7c71d6e6cf24d230408853addceb20993a063d..3e5b9b797d31b6a3e3b38f1a2cb6d19bb4ba08a9 100644 (file)
@@ -1030,7 +1030,7 @@ fn parse_type(ch: char, tm: &Tm) -> ~str {
         }
     }
 
-    str::from_utf8_owned(buf)
+    str::from_utf8_owned(buf).unwrap()
 }
 
 #[cfg(test)]
index 3465deb5a59185093e317d121b7daf543dd90fdb..9163a892039139199dd390f717c5eab4a7edff34 100644 (file)
@@ -313,7 +313,7 @@ pub fn to_simple_str(&self) -> ~str {
             s[i*2+0] = digit[0];
             s[i*2+1] = digit[1];
         }
-        str::from_utf8_owned(s)
+        str::from_utf8_owned(s).unwrap()
     }
 
     /// Returns a string of hexadecimal digits, separated into groups with a hyphen.
index 2bec1a2f96221f4ffb6de0d4ab455eb34dc79dc4..cccca1309f4c3918581f6fc755b2dd32fad05385 100644 (file)
@@ -243,7 +243,7 @@ fn json_encode<'a, T:Encodable<json::Encoder<'a>>>(t: &T) -> ~str {
     let mut writer = MemWriter::new();
     let mut encoder = json::Encoder::new(&mut writer as &mut io::Writer);
     t.encode(&mut encoder);
-    str::from_utf8_owned(writer.unwrap())
+    str::from_utf8_owned(writer.unwrap()).unwrap()
 }
 
 // FIXME(#5121)
@@ -491,7 +491,7 @@ fn make_path(filename: ~str) -> Path {
         let subcx = cx.clone();
         let pth = pth.clone();
 
-        let file_content = from_utf8_owned(File::open(&pth).read_to_end());
+        let file_content = from_utf8_owned(File::open(&pth).read_to_end()).unwrap();
 
         // FIXME (#9639): This needs to handle non-utf8 paths
         prep.declare_input("file", pth.as_str().unwrap(), file_content);
index 06c13c7de15ac5b037f4c9b911e73039149a4189..63c4d9f4a2976ee270e7cdcdd50934fb41bb9d3e 100644 (file)
@@ -298,7 +298,7 @@ pub fn run_assembler(sess: Session, assembly: &Path, object: &Path) {
                 if !prog.status.success() {
                     sess.err(format!("linking with `{}` failed: {}", cc, prog.status));
                     sess.note(format!("{} arguments: '{}'", cc, args.connect("' '")));
-                    sess.note(str::from_utf8_owned(prog.error + prog.output));
+                    sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
                     sess.abort_if_errors();
                 }
             },
@@ -1007,7 +1007,7 @@ fn link_natively(sess: Session, dylib: bool, obj_filename: &Path,
             if !prog.status.success() {
                 sess.err(format!("linking with `{}` failed: {}", cc_prog, prog.status));
                 sess.note(format!("{} arguments: '{}'", cc_prog, cc_args.connect("' '")));
-                sess.note(str::from_utf8_owned(prog.error + prog.output));
+                sess.note(str::from_utf8_owned(prog.error + prog.output).unwrap());
                 sess.abort_if_errors();
             }
         },
index 7ecf2b1e18c4202dcb62d22b080d5c90ee5f05cd..f7ee736f144de60bc042287af91252e6421ae6c1 100644 (file)
@@ -234,7 +234,7 @@ pub fn run_compiler(args: &[~str], demitter: @diagnostic::Emitter) {
       1u => {
         let ifile = matches.free[0].as_slice();
         if "-" == ifile {
-            let src = str::from_utf8_owned(io::stdin().read_to_end());
+            let src = str::from_utf8_owned(io::stdin().read_to_end()).unwrap();
             d::StrInput(src.to_managed())
         } else {
             d::FileInput(Path::new(ifile))
index 9bf3e2ca43e806cf54f605910fab9a25b7875558..a7c82ba4317782bf7fc833617f51d927a4469935 100644 (file)
@@ -1989,5 +1989,5 @@ pub fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> ~str {
         abbrevs: tyencode::ac_no_abbrevs};
     let mut wr = MemWriter::new();
     tyencode::enc_ty(&mut wr, cx, t);
-    str::from_utf8_owned(wr.get_ref().to_owned())
+    str::from_utf8_owned(wr.get_ref().to_owned()).unwrap()
 }
index 03d7c56aeb6f4bdc251811464e384ffe1f825faf..d8bf115eb42b298f0c7b0166ba702fae29e86201 100644 (file)
@@ -825,7 +825,7 @@ pub fn ln_str(&self, ln: LiveNode) -> ~str {
                 }
             }
         }
-        str::from_utf8_owned(wr.unwrap())
+        str::from_utf8_owned(wr.unwrap()).unwrap()
     }
 
     pub fn init_empty(&self, ln: LiveNode, succ_ln: LiveNode) {
index 9a9b588fa4782afd66d2f6eb0c5a2d73ec0ce1fd..b0a56cb402b5ffe57a100c22333148f6c9217fae 100644 (file)
@@ -427,7 +427,7 @@ fn emit_source(&mut self, filename: &str) -> bool {
                 }
             }
         }
-        let contents = str::from_utf8_owned(contents);
+        let contents = str::from_utf8_owned(contents).unwrap();
 
         // Create the intermediate directories
         let mut cur = self.dst.clone();
index a6bdb2250a6aaccad4c10888e8cc6830ba8a2b7b..393be290506e127582f5ca899f6c33019f9dd1f2 100644 (file)
@@ -330,7 +330,7 @@ fn json_output(crate: clean::Crate, res: ~[plugins::PluginJson], dst: Path) {
             let mut encoder = json::Encoder::new(&mut w as &mut io::Writer);
             crate.encode(&mut encoder);
         }
-        str::from_utf8_owned(w.unwrap())
+        str::from_utf8_owned(w.unwrap()).unwrap()
     };
     let crate_json = match json::from_str(crate_json_str) {
         Ok(j) => j,
index 7da99c5d5621be2d2b701891a6c706e82031dc13..4b7aaf7e340d94af8593dac8dfc07102d3c5b70a 100644 (file)
@@ -38,8 +38,8 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
                                                        target.as_str().unwrap().to_owned()]);
             let outp = opt_outp.expect("Failed to exec `git`");
             if !outp.status.success() {
-                println!("{}", str::from_utf8_owned(outp.output.clone()));
-                println!("{}", str::from_utf8_owned(outp.error));
+                println!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
+                println!("{}", str::from_utf8_owned(outp.error).unwrap());
                 return DirToUse(target.clone());
             }
             else {
@@ -54,8 +54,8 @@ pub fn safe_git_clone(source: &Path, v: &Version, target: &Path) -> CloneResult
                              format!("--git-dir={}", git_dir.as_str().unwrap().to_owned()),
                              ~"checkout", format!("{}", *s)]).expect("Failed to exec `git`");
                         if !outp.status.success() {
-                            println!("{}", str::from_utf8_owned(outp.output.clone()));
-                            println!("{}", str::from_utf8_owned(outp.error));
+                            println!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
+                            println!("{}", str::from_utf8_owned(outp.error).unwrap());
                             return DirToUse(target.clone());
                         }
                     }
@@ -114,8 +114,8 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
                                                target.as_str().unwrap().to_owned()]);
     let outp = opt_outp.expect("Failed to exec `git`");
     if !outp.status.success() {
-         debug!("{}", str::from_utf8_owned(outp.output.clone()));
-         debug!("{}", str::from_utf8_owned(outp.error));
+         debug!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
+         debug!("{}", str::from_utf8_owned(outp.error).unwrap());
          cond.raise((source.to_owned(), target.clone()))
     }
     else {
@@ -125,8 +125,8 @@ pub fn git_clone_url(source: &str, target: &Path, v: &Version) {
                                                          target);
                     let outp = opt_outp.expect("Failed to exec `git`");
                     if !outp.status.success() {
-                        debug!("{}", str::from_utf8_owned(outp.output.clone()));
-                        debug!("{}", str::from_utf8_owned(outp.error));
+                        debug!("{}", str::from_utf8_owned(outp.output.clone()).unwrap());
+                        debug!("{}", str::from_utf8_owned(outp.error).unwrap());
                         cond.raise((source.to_owned(), target.clone()))
                     }
             }
index b2cc568ee5e60d89097b38c9bdce94abc00e2917..c0b4a246d35d76216c10780a4249373af24d1809 100644 (file)
@@ -1191,7 +1191,7 @@ fn test_info() {
     let expected_info = ~"package foo"; // fill in
     let workspace = create_local_package(&CrateId::new("foo"));
     let output = command_line_test([~"info", ~"foo"], workspace.path());
-    assert_eq!(str::from_utf8_owned(output.output), expected_info);
+    assert_eq!(str::from_utf8_owned(output.output).unwrap(), expected_info);
 }
 
 #[test]
index 4bee1f42b86cdebd9bd2eebffc8cecccde053546..411f9f254593fc50484f05c4972e223f1d09fa3d 100644 (file)
@@ -691,7 +691,7 @@ pub fn format(args: &Arguments) -> ~str {
 pub unsafe fn format_unsafe(fmt: &[rt::Piece], args: &[Argument]) -> ~str {
     let mut output = MemWriter::new();
     write_unsafe(&mut output as &mut io::Writer, fmt, args);
-    return str::from_utf8_owned(output.unwrap());
+    return str::from_utf8_owned(output.unwrap()).unwrap();
 }
 
 impl<'a> Formatter<'a> {
index 0564311ad2270df38c7644041ca137ecb09b91fa..cb98ff21105bba7eb386c7413bf255f482cd3044 100644 (file)
@@ -754,7 +754,7 @@ pub fn tmpdir() -> TempDir {
             let mut read_buf = [0, .. 1028];
             let read_str = match read_stream.read(read_buf).unwrap() {
                 -1|0 => fail!("shouldn't happen"),
-                n => str::from_utf8_owned(read_buf.slice_to(n).to_owned())
+                n => str::from_utf8_owned(read_buf.slice_to(n).to_owned()).unwrap()
             };
             assert_eq!(read_str, message.to_owned());
         }
index b12adbf230fd0597c3c2f0b5369579acb0cc3581..30827983360692f3029be5f6ddcbc55c8f5b26bd 100644 (file)
@@ -607,7 +607,7 @@ fn read_to_end(&mut self) -> ~[u8] {
     /// This function will raise all the same conditions as the `read` method,
     /// along with raising a condition if the input is not valid UTF-8.
     fn read_to_str(&mut self) -> ~str {
-        match str::from_utf8_owned_opt(self.read_to_end()) {
+        match str::from_utf8_owned(self.read_to_end()) {
             Some(s) => s,
             None => {
                 io_error::cond.raise(standard_error(InvalidInput));
@@ -1117,7 +1117,7 @@ pub trait Buffer: Reader {
     /// The task will also fail if sequence of bytes leading up to
     /// the newline character are not valid UTF-8.
     fn read_line(&mut self) -> Option<~str> {
-        self.read_until('\n' as u8).map(str::from_utf8_owned)
+        self.read_until('\n' as u8).map(|line| str::from_utf8_owned(line).unwrap())
     }
 
     /// Create an iterator that reads a line on each iteration until EOF.
index 5c35c500e6c243ca6a07e9aceb52f577b172f38f..bf9e6b739f2a4a4c9ceb6c195a2ca628f62dcdc7 100644 (file)
@@ -427,7 +427,7 @@ pub fn float_to_str_common<T:NumCast+Zero+One+Eq+Ord+NumStrConv+Float+Round+
         sign: SignFormat, digits: SignificantDigits) -> (~str, bool) {
     let (bytes, special) = float_to_str_bytes_common(num, radix,
                                negative_zero, sign, digits);
-    (str::from_utf8_owned(bytes), special)
+    (str::from_utf8_owned(bytes).unwrap(), special)
 }
 
 // Some constants for from_str_bytes_common's input validation,
index 8f7d01f263dd14dfaf931a4a2ccf416344e19a9f..8919f9f890311cc04d6610d3c2722d6d7c2c967a 100644 (file)
@@ -608,7 +608,7 @@ pub fn repr_to_str<T>(t: &T) -> ~str {
 
     let mut result = io::MemWriter::new();
     write_repr(&mut result as &mut io::Writer, t);
-    str::from_utf8_owned(result.unwrap())
+    str::from_utf8_owned(result.unwrap()).unwrap()
 }
 
 #[cfg(test)]
@@ -626,7 +626,7 @@ fn test_repr() {
     fn exact_test<T>(t: &T, e:&str) {
         let mut m = io::MemWriter::new();
         write_repr(&mut m as &mut io::Writer, t);
-        let s = str::from_utf8_owned(m.unwrap());
+        let s = str::from_utf8_owned(m.unwrap()).unwrap();
         assert_eq!(s.as_slice(), e);
     }
 
index 3595a7d45aca2e8f858088be8473ef8a5ce1ec73..f460d3f494408d5ef9b4dbef0682f263e44143ee 100644 (file)
@@ -372,7 +372,7 @@ fn test_process_output_output() {
 
         let run::ProcessOutput {status, output, error}
              = run::process_output("echo", [~"hello"]).expect("failed to exec `echo`");
-        let output_str = str::from_utf8_owned(output);
+        let output_str = str::from_utf8_owned(output).unwrap();
 
         assert!(status.success());
         assert_eq!(output_str.trim().to_owned(), ~"hello");
@@ -439,7 +439,7 @@ fn readclose(fd: c_int) -> ~str {
                 None => break
             }
         }
-        str::from_utf8_owned(res)
+        str::from_utf8_owned(res).unwrap()
     }
 
     #[test]
@@ -467,7 +467,7 @@ fn test_finish_with_output_once() {
             .expect("failed to exec `echo`");
         let run::ProcessOutput {status, output, error}
             = prog.finish_with_output();
-        let output_str = str::from_utf8_owned(output);
+        let output_str = str::from_utf8_owned(output).unwrap();
 
         assert!(status.success());
         assert_eq!(output_str.trim().to_owned(), ~"hello");
@@ -486,7 +486,7 @@ fn test_finish_with_output_twice() {
         let run::ProcessOutput {status, output, error}
             = prog.finish_with_output();
 
-        let output_str = str::from_utf8_owned(output);
+        let output_str = str::from_utf8_owned(output).unwrap();
 
         assert!(status.success());
         assert_eq!(output_str.trim().to_owned(), ~"hello");
@@ -533,7 +533,7 @@ fn run_pwd(dir: Option<&Path>) -> run::Process {
     fn test_keep_current_working_dir() {
         let mut prog = run_pwd(None);
 
-        let output = str::from_utf8_owned(prog.finish_with_output().output);
+        let output = str::from_utf8_owned(prog.finish_with_output().output).unwrap();
         let parent_dir = os::getcwd();
         let child_dir = Path::new(output.trim());
 
@@ -551,7 +551,7 @@ fn test_change_working_directory() {
         let parent_dir = os::getcwd().dir_path();
         let mut prog = run_pwd(Some(&parent_dir));
 
-        let output = str::from_utf8_owned(prog.finish_with_output().output);
+        let output = str::from_utf8_owned(prog.finish_with_output().output).unwrap();
         let child_dir = Path::new(output.trim());
 
         let parent_stat = parent_dir.stat();
@@ -590,7 +590,7 @@ fn test_inherit_env() {
         if running_on_valgrind() { return; }
 
         let mut prog = run_env(None);
-        let output = str::from_utf8_owned(prog.finish_with_output().output);
+        let output = str::from_utf8_owned(prog.finish_with_output().output).unwrap();
 
         let r = os::env();
         for &(ref k, ref v) in r.iter() {
@@ -604,7 +604,7 @@ fn test_inherit_env() {
         if running_on_valgrind() { return; }
 
         let mut prog = run_env(None);
-        let output = str::from_utf8_owned(prog.finish_with_output().output);
+        let output = str::from_utf8_owned(prog.finish_with_output().output).unwrap();
 
         let r = os::env();
         for &(ref k, ref v) in r.iter() {
@@ -623,7 +623,7 @@ fn test_add_to_env() {
         new_env.push((~"RUN_TEST_NEW_ENV", ~"123"));
 
         let mut prog = run_env(Some(new_env));
-        let output = str::from_utf8_owned(prog.finish_with_output().output);
+        let output = str::from_utf8_owned(prog.finish_with_output().output).unwrap();
 
         assert!(output.contains("RUN_TEST_NEW_ENV=123"));
     }
index c266ddfea4b924df3174ad464033f8c19edf036a..6d52e94064c094b945d9b5d249f4fd455ecc04c5 100644 (file)
@@ -129,26 +129,9 @@ fn main() {
 Section: Creating a string
 */
 
-/// Consumes a vector of bytes to create a new utf-8 string
-///
-/// # Failure
-///
-/// Raises the `not_utf8` condition if invalid UTF-8
-pub fn from_utf8_owned(vv: ~[u8]) -> ~str {
-    use str::not_utf8::cond;
-
-    if !is_utf8(vv) {
-        let first_bad_byte = *vv.iter().find(|&b| !is_utf8([*b])).unwrap();
-        cond.raise(format!("from_utf8: input is not UTF-8; first bad byte is {}",
-                           first_bad_byte))
-    } else {
-        unsafe { raw::from_utf8_owned(vv) }
-    }
-}
-
 /// Consumes a vector of bytes to create a new utf-8 string.
 /// Returns None if the vector contains invalid UTF-8.
-pub fn from_utf8_owned_opt(vv: ~[u8]) -> Option<~str> {
+pub fn from_utf8_owned(vv: ~[u8]) -> Option<~str> {
     if is_utf8(vv) {
         Some(unsafe { raw::from_utf8_owned(vv) })
     } else {
@@ -3964,22 +3947,13 @@ fn test_str_from_utf8() {
     #[test]
     fn test_str_from_utf8_owned() {
         let xs = bytes!("hello").to_owned();
-        assert_eq!(from_utf8_owned(xs), ~"hello");
-
-        let xs = bytes!("ศไทย中华Việt Nam").to_owned();
-        assert_eq!(from_utf8_owned(xs), ~"ศไทย中华Việt Nam");
-    }
-
-    #[test]
-    fn test_str_from_utf8_owned_opt() {
-        let xs = bytes!("hello").to_owned();
-        assert_eq!(from_utf8_owned_opt(xs), Some(~"hello"));
+        assert_eq!(from_utf8_owned(xs), Some(~"hello"));
 
         let xs = bytes!("ศไทย中华Việt Nam").to_owned();
-        assert_eq!(from_utf8_owned_opt(xs), Some(~"ศไทย中华Việt Nam"));
+        assert_eq!(from_utf8_owned(xs), Some(~"ศไทย中华Việt Nam"));
 
         let xs = bytes!("hello", 0xff).to_owned();
-        assert_eq!(from_utf8_owned_opt(xs), None);
+        assert_eq!(from_utf8_owned(xs), None);
     }
 
     #[test]
index 711f8ff11ee63548838b01ae0bf2ab704235106f..a9f94da7a98cbea0a1680b7edd0746b59600c21a 100644 (file)
@@ -109,7 +109,7 @@ pub fn expand_include_str(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
         }
         Ok(bytes) => bytes,
     };
-    match str::from_utf8_owned_opt(bytes) {
+    match str::from_utf8_owned(bytes) {
         Some(src) => {
             // Add this input file to the code map to make it available as
             // dependency information
index 86ab2e099d0c29b6f6cd3dd1a48c83124e08d3a1..22ece367b8028962c23072669696b330952b3c00 100644 (file)
@@ -351,7 +351,7 @@ pub fn gather_comments_and_literals(span_diagnostic:
                                     path: @str,
                                     srdr: &mut io::Reader)
                                  -> (~[Comment], ~[Literal]) {
-    let src = str::from_utf8_owned(srdr.read_to_end()).to_managed();
+    let src = str::from_utf8_owned(srdr.read_to_end()).unwrap().to_managed();
     let cm = CodeMap::new();
     let filemap = cm.new_filemap(path, src);
     let rdr = lexer::new_low_level_string_reader(span_diagnostic, filemap);
index b1a80878cf1b5b5d1f6a573d3211bf715ec7119b..9713f331147c01b931a438abbad04545a6c48461 100644 (file)
@@ -246,7 +246,7 @@ pub fn file_to_filemap(sess: @ParseSess, path: &Path, spanopt: Option<Span>)
             unreachable!()
         }
     };
-    match str::from_utf8_owned_opt(bytes) {
+    match str::from_utf8_owned(bytes) {
         Some(s) => {
             return string_to_filemap(sess, s.to_managed(),
                                      path.as_str().unwrap().to_managed());
@@ -315,7 +315,7 @@ fn to_json_str<'a, E: Encodable<extra::json::Encoder<'a>>>(val: &E) -> ~str {
         let mut writer = MemWriter::new();
         let mut encoder = extra::json::Encoder::new(&mut writer as &mut io::Writer);
         val.encode(&mut encoder);
-        str::from_utf8_owned(writer.unwrap())
+        str::from_utf8_owned(writer.unwrap()).unwrap()
     }
 
     // produce a codemap::span
index cdfeebd3e1bc88e3df3022ff73ef6c6515c88fa7..54e9a8bd62937f378677e4f6d9f72b551d95ff2d 100644 (file)
@@ -2316,7 +2316,7 @@ pub fn print_string(s: &mut State, st: &str, style: ast::StrStyle) {
 // downcasts.
 unsafe fn get_mem_writer(writer: &mut ~io::Writer) -> ~str {
     let (_, wr): (uint, ~MemWriter) = cast::transmute_copy(writer);
-    let result = str::from_utf8_owned(wr.get_ref().to_owned());
+    let result = str::from_utf8_owned(wr.get_ref().to_owned()).unwrap();
     cast::forget(wr);
     result
 }
index 067ef873fd3d2e4d019c4d5457262f7521f6a45b..61e76b992830086668bac89431142a9aa19b1d88 100644 (file)
@@ -59,7 +59,7 @@ fn unpack(&self, frame: i32) -> ~str {
         }
 
         reverse(result);
-        str::from_utf8_owned(result)
+        str::from_utf8_owned(result).unwrap()
     }
 }
 
index 4b6430cbd27bcb124c23ff16ec23cb4120b07ac9..c5b01e68fc4e8f1824093eb7dc7c9487dffb72ff 100644 (file)
@@ -187,7 +187,7 @@ fn to_utf8(raw_sol: &List<u64>) -> ~str {
             if m & 1 << i != 0 {sol[i] = '0' as u8 + id;}
         }
     }
-    std::str::from_utf8_owned(sol)
+    std::str::from_utf8_owned(sol).unwrap()
 }
 
 // Prints a solution in ~str form.
index 4b7ab09e152b0388cdef9670074856949725e13b..3442e971f4fe5d9b6b34554956274f5a8df5354c 100644 (file)
@@ -62,14 +62,14 @@ fn test_destroy_actually_kills(force: bool) {
     fn process_exists(pid: libc::pid_t) -> bool {
         let run::ProcessOutput {output, ..} = run::process_output("ps", [~"-p", pid.to_str()])
             .expect("failed to exec `ps`");
-        str::from_utf8_owned(output).contains(pid.to_str())
+        str::from_utf8_owned(output).unwrap().contains(pid.to_str())
     }
 
     #[cfg(unix,target_os="android")]
     fn process_exists(pid: libc::pid_t) -> bool {
         let run::ProcessOutput {output, ..} = run::process_output("/system/bin/ps", [pid.to_str()])
             .expect("failed to exec `/system/bin/ps`");
-        str::from_utf8_owned(output).contains(~"root")
+        str::from_utf8_owned(output).unwrap().contains(~"root")
     }
 
     #[cfg(windows)]
index 54aaa86351e9811d6ec0ef3ff0fe506b5dbbf8d0..76759d04ab4ae34959adb3fd322d14af526a80b7 100644 (file)
@@ -260,7 +260,7 @@ fn test_write() {
         writeln!(w, "{foo}", foo="bar");
     }
 
-    let s = str::from_utf8_owned(buf.unwrap());
+    let s = str::from_utf8_owned(buf.unwrap()).unwrap();
     t!(s, "34helloline\nbar\n");
 }
 
@@ -284,7 +284,7 @@ fn test_format_args() {
         format_args!(|args| { fmt::write(w, args) }, "test");
         format_args!(|args| { fmt::write(w, args) }, "{test}", test=3);
     }
-    let s = str::from_utf8_owned(buf.unwrap());
+    let s = str::from_utf8_owned(buf.unwrap()).unwrap();
     t!(s, "1test3");
 
     let s = format_args!(fmt::format, "hello {}", "world");