about summary refs log tree commit diff
path: root/src/libcollections/string.rs
diff options
context:
space:
mode:
authorAdolfo Ochagavía <aochagavia92@gmail.com>2014-07-04 22:38:13 +0200
committerAdolfo Ochagavía <aochagavia92@gmail.com>2014-07-15 20:34:16 +0200
commit584fbde5d1f9e0048592b44195263dfea0ee8231 (patch)
treea8ed3d1b187108d1793581b5b2b5ffceb514c744 /src/libcollections/string.rs
parentc6b82c7566a2e1da7d0f1697335b47c8c999720e (diff)
downloadrust-584fbde5d1f9e0048592b44195263dfea0ee8231.tar.gz
rust-584fbde5d1f9e0048592b44195263dfea0ee8231.zip
Fix errors
Diffstat (limited to 'src/libcollections/string.rs')
-rw-r--r--src/libcollections/string.rs49
1 files changed, 27 insertions, 22 deletions
diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs
index d5a666d4b4c..5450f2d7c31 100644
--- a/src/libcollections/string.rs
+++ b/src/libcollections/string.rs
@@ -99,7 +99,7 @@ impl String {
     ///
     /// ```rust
     /// let input = b"Hello \xF0\x90\x80World";
-    /// let output = std::str::from_utf8_lossy(input);
+    /// let output = String::from_utf8_lossy(input);
     /// assert_eq!(output.as_slice(), "Hello \uFFFDWorld");
     /// ```
     pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
@@ -218,18 +218,18 @@ impl String {
         Owned(res.into_string())
     }
 
-    /// Decode a UTF-16 encoded vector `v` into a string, returning `None`
+    /// Decode a UTF-16 encoded vector `v` into a `String`, returning `None`
     /// if `v` contains any invalid data.
     ///
     /// # Example
     ///
     /// ```rust
-    /// // 𝄞music
+    /// // 𝄞music
     /// let mut v = [0xD834, 0xDD1E, 0x006d, 0x0075,
     ///              0x0073, 0x0069, 0x0063];
-    /// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
+    /// assert_eq!(String::from_utf16(v), Some("𝄞music".to_string()));
     ///
-    /// // 𝄞mu<invalid>ic
+    /// // 𝄞mu<invalid>ic
     /// v[4] = 0xD800;
     /// assert_eq!(String::from_utf16(v), None);
     /// ```
@@ -249,13 +249,13 @@ impl String {
     ///
     /// # Example
     /// ```rust
-    /// // 𝄞mus<invalid>ic<invalid>
+    /// // 𝄞mus<invalid>ic<invalid>
     /// let v = [0xD834, 0xDD1E, 0x006d, 0x0075,
     ///          0x0073, 0xDD1E, 0x0069, 0x0063,
     ///          0xD834];
     ///
     /// assert_eq!(String::from_utf16_lossy(v),
-    ///            "𝄞mus\uFFFDic\uFFFD".to_string());
+    ///            "𝄞mus\uFFFDic\uFFFD".to_string());
     /// ```
     pub fn from_utf16_lossy(v: &[u16]) -> String {
         str::utf16_items(v).map(|c| c.to_char_lossy()).collect()
@@ -575,8 +575,9 @@ mod tests {
 
     use Mutable;
     use str;
-    use str::{Str, StrSlice, MaybeOwned, Owned, Slice};
+    use str::{Str, StrSlice, Owned, Slice};
     use super::String;
+    use vec::Vec;
 
     #[test]
     fn test_from_str() {
@@ -587,10 +588,10 @@ mod tests {
     #[test]
     fn test_from_utf8() {
         let xs = Vec::from_slice(b"hello");
-        assert_eq!(String::from_utf8(xs), Ok("hello".to_string()));
+        assert_eq!(String::from_utf8(xs), Ok(String::from_str("hello")));
 
-        let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes());
-        assert_eq!(String::from_utf8(xs), Ok("ศไทย中华Việt Nam".to_string()));
+        let xs = Vec::from_slice("ศไทย中华Việt Nam".as_bytes());
+        assert_eq!(String::from_utf8(xs), Ok(String::from_str("ศไทย中华Việt Nam")));
 
         let xs = Vec::from_slice(b"hello\xFF");
         assert_eq!(String::from_utf8(xs),
@@ -602,21 +603,24 @@ mod tests {
         let xs = b"hello";
         assert_eq!(String::from_utf8_lossy(xs), Slice("hello"));
 
-        let xs = "ศไทย中华Việt Nam".as_bytes();
-        assert_eq!(String::from_utf8_lossy(xs), Slice("ศไทย中华Việt Nam"));
+        let xs = "ศไทย中华Việt Nam".as_bytes();
+        assert_eq!(String::from_utf8_lossy(xs), Slice("ศไทย中华Việt Nam"));
 
         let xs = b"Hello\xC2 There\xFF Goodbye";
-        assert_eq!(String::from_utf8_lossy(xs), Owned(String::from_str("Hello\uFFFD There\uFFFD Goodbye")));
+        assert_eq!(String::from_utf8_lossy(xs),
+                   Owned(String::from_str("Hello\uFFFD There\uFFFD Goodbye")));
 
         let xs = b"Hello\xC0\x80 There\xE6\x83 Goodbye";
         assert_eq!(String::from_utf8_lossy(xs),
                    Owned(String::from_str("Hello\uFFFD\uFFFD There\uFFFD Goodbye")));
 
         let xs = b"\xF5foo\xF5\x80bar";
-        assert_eq!(String::from_utf8_lossy(xs), Owned(String::from_str("\uFFFDfoo\uFFFD\uFFFDbar")));
+        assert_eq!(String::from_utf8_lossy(xs),
+                   Owned(String::from_str("\uFFFDfoo\uFFFD\uFFFDbar")));
 
         let xs = b"\xF1foo\xF1\x80bar\xF1\x80\x80baz";
-        assert_eq!(String::from_utf8_lossy(xs), Owned(String::from_str("\uFFFDfoo\uFFFDbar\uFFFDbaz")));
+        assert_eq!(String::from_utf8_lossy(xs),
+                   Owned(String::from_str("\uFFFDfoo\uFFFDbar\uFFFDbaz")));
 
         let xs = b"\xF4foo\xF4\x80bar\xF4\xBFbaz";
         assert_eq!(String::from_utf8_lossy(xs),
@@ -635,13 +639,13 @@ mod tests {
     #[test]
     fn test_from_utf16() {
         let pairs =
-            [(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
+            [(String::from_str("𐍅𐌿𐌻𐍆𐌹𐌻𐌰\n"),
               vec![0xd800_u16, 0xdf45_u16, 0xd800_u16, 0xdf3f_u16,
                 0xd800_u16, 0xdf3b_u16, 0xd800_u16, 0xdf46_u16,
                 0xd800_u16, 0xdf39_u16, 0xd800_u16, 0xdf3b_u16,
                 0xd800_u16, 0xdf30_u16, 0x000a_u16]),
 
-             (String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
+             (String::from_str("𐐒𐑉𐐮𐑀𐐲𐑋 𐐏𐐲𐑍\n"),
               vec![0xd801_u16, 0xdc12_u16, 0xd801_u16,
                 0xdc49_u16, 0xd801_u16, 0xdc2e_u16, 0xd801_u16,
                 0xdc40_u16, 0xd801_u16, 0xdc32_u16, 0xd801_u16,
@@ -649,7 +653,7 @@ mod tests {
                 0xd801_u16, 0xdc32_u16, 0xd801_u16, 0xdc4d_u16,
                 0x000a_u16]),
 
-             (String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
+             (String::from_str("𐌀𐌖𐌋𐌄𐌑𐌉·𐌌𐌄𐌕𐌄𐌋𐌉𐌑\n"),
               vec![0xd800_u16, 0xdf00_u16, 0xd800_u16, 0xdf16_u16,
                 0xd800_u16, 0xdf0b_u16, 0xd800_u16, 0xdf04_u16,
                 0xd800_u16, 0xdf11_u16, 0xd800_u16, 0xdf09_u16,
@@ -658,7 +662,7 @@ mod tests {
                 0xdf04_u16, 0xd800_u16, 0xdf0b_u16, 0xd800_u16,
                 0xdf09_u16, 0xd800_u16, 0xdf11_u16, 0x000a_u16 ]),
 
-             (String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
+             (String::from_str("𐒋𐒘𐒈𐒑𐒛𐒒 𐒕𐒓 𐒈𐒚𐒍 𐒏𐒜𐒒𐒖𐒆 𐒕𐒆\n"),
               vec![0xd801_u16, 0xdc8b_u16, 0xd801_u16, 0xdc98_u16,
                 0xd801_u16, 0xdc88_u16, 0xd801_u16, 0xdc91_u16,
                 0xd801_u16, 0xdc9b_u16, 0xd801_u16, 0xdc92_u16,
@@ -718,7 +722,7 @@ mod tests {
 
         // general
         assert_eq!(String::from_utf16_lossy([0xD800, 0xd801, 0xdc8b, 0xD800]),
-                   String::from_str("\uFFFD𐒋\uFFFD"));
+                   String::from_str("\uFFFD𐒋\uFFFD"));
     }
 
     #[test]
@@ -852,7 +856,8 @@ mod tests {
 
     #[bench]
     fn from_utf8_lossy_100_multibyte(b: &mut Bencher) {
-        let s = "𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰".as_bytes();
+        let s = "𐌀𐌖𐌋𐌄𐌑𐌉ปรدولة\
+            الكويتทศไทย中华𐍅𐌿𐌻𐍆𐌹𐌻𐌰".as_bytes();
         assert_eq!(100, s.len());
         b.iter(|| {
             let _ = String::from_utf8_lossy(s);