From 948e363d1939ca8f0d4961b1380d89fbf6f0b1a1 Mon Sep 17 00:00:00 2001 From: Axel Viala Date: Thu, 18 Dec 2014 20:24:00 +0100 Subject: [PATCH] Remove all utf-8 deprecated warning. Script used for that made by @simonsapin. here: https://www.reddit.com/r/rust/comments/2p3b3s/convert_to_uabcd12_style_unicode_escapes/ Copy of the script here ```bash git grep -l '\\u' | xargs sed -i \ -e 's/\\u000\([0-9a-fA-F]\)/\\u{\1}/g' \ -e 's/\\u00\([0-9a-fA-F]\{2\}\)/\\u{\1}/g' \ -e 's/\\u0\([0-9a-fA-F]\{3\}\)/\\u{\1}/g' \ -e 's/\\u\([0-9a-fA-F]\{4\}\)/\\u{\1}/g' \ -e 's/\\U0000000\([0-9a-fA-F]\)/\\u{\1}/g' \ -e 's/\\U000000\([0-9a-fA-F]\{2\}\)/\\u{\1}/g' \ -e 's/\\U00000\([0-9a-fA-F]\{3\}\)/\\u{\1}/g' \ -e 's/\\U0000\([0-9a-fA-F]\{4\}\)/\\u{\1}/g' \ -e 's/\\U000\([0-9a-fA-F]\{5\}\)/\\u{\1}/g' \ -e 's/\\U00\([0-9a-fA-F]\{6\}\)/\\u{\1}/g' \ -e 's/\\U0\([0-9a-fA-F]\{7\}\)/\\u{\1}/g' \ -e 's/\\U\([0-9a-fA-F]\{8\}\)/\\u{\1}/g' ``` --- src/doc/reference.md | 7 +-- src/libcoretest/char.rs | 56 +++++++++---------- src/libserialize/json.rs | 8 +-- src/libstd/os.rs | 6 +- src/test/pretty/block-comment-wchar.pp | 8 +-- src/test/pretty/block-comment-wchar.rs | 8 +-- src/test/run-pass/nul-characters.rs | 12 ++-- .../process-spawn-with-unicode-params.rs | 2 +- src/test/run-pass/utf8.rs | 10 ++-- 9 files changed, 58 insertions(+), 59 deletions(-) diff --git a/src/doc/reference.md b/src/doc/reference.md index 722230d37557c..9884743bc5bad 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -248,10 +248,9 @@ cases mentioned in [Number literals](#number-literals) below. | `\\` | Backslash | ##### Unicode escapes -| | Name | -|---|------| -| `\u7FFF` | 16-bit character code (exactly 4 digits) | -| `\U7EEEFFFF` | 32-bit character code (exactly 8 digits) | +| | Name | +|---|------------| +| `\u{7FF}` | Unicode code point value (1 to 6 digits) | ##### Numbers diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index bed38f8c29666..f6a45407ce5db 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -33,12 +33,12 @@ fn test_is_uppercase() { #[test] fn test_is_whitespace() { assert!(' '.is_whitespace()); - assert!('\u2007'.is_whitespace()); + assert!('\u{2007}'.is_whitespace()); assert!('\t'.is_whitespace()); assert!('\n'.is_whitespace()); assert!(!'a'.is_whitespace()); assert!(!'_'.is_whitespace()); - assert!(!'\u0000'.is_whitespace()); + assert!(!'\u{0}'.is_whitespace()); } #[test] @@ -92,15 +92,15 @@ fn test_to_uppercase() { #[test] fn test_is_control() { - assert!('\u0000'.is_control()); - assert!('\u0003'.is_control()); - assert!('\u0006'.is_control()); - assert!('\u0009'.is_control()); - assert!('\u007f'.is_control()); - assert!('\u0092'.is_control()); - assert!(!'\u0020'.is_control()); - assert!(!'\u0055'.is_control()); - assert!(!'\u0068'.is_control()); + assert!('\u{0}'.is_control()); + assert!('\u{3}'.is_control()); + assert!('\u{6}'.is_control()); + assert!('\u{9}'.is_control()); + assert!('\u{7f}'.is_control()); + assert!('\u{92}'.is_control()); + assert!(!'\u{20}'.is_control()); + assert!(!'\u{55}'.is_control()); + assert!(!'\u{68}'.is_control()); } #[test] @@ -175,9 +175,9 @@ fn test_encode_utf8() { } check('x', &[0x78]); - check('\u00e9', &[0xc3, 0xa9]); - check('\ua66e', &[0xea, 0x99, 0xae]); - check('\U0001f4a9', &[0xf0, 0x9f, 0x92, 0xa9]); + check('\u{e9}', &[0xc3, 0xa9]); + check('\u{a66e}', &[0xea, 0x99, 0xae]); + check('\u{1f4a9}', &[0xf0, 0x9f, 0x92, 0xa9]); } #[test] @@ -189,17 +189,17 @@ fn test_encode_utf16() { } check('x', &[0x0078]); - check('\u00e9', &[0x00e9]); - check('\ua66e', &[0xa66e]); - check('\U0001f4a9', &[0xd83d, 0xdca9]); + check('\u{e9}', &[0x00e9]); + check('\u{a66e}', &[0xa66e]); + check('\u{1f4a9}', &[0xd83d, 0xdca9]); } #[test] fn test_len_utf16() { assert!('x'.len_utf16() == 1); - assert!('\u00e9'.len_utf16() == 1); - assert!('\ua66e'.len_utf16() == 1); - assert!('\U0001f4a9'.len_utf16() == 2); + assert!('\u{e9}'.len_utf16() == 1); + assert!('\u{a66e}'.len_utf16() == 1); + assert!('\u{1f4a9}'.len_utf16() == 2); } #[test] @@ -216,15 +216,15 @@ fn test_width() { assert_eq!('h'.width(false),Some(2)); assert_eq!('h'.width(true),Some(2)); - assert_eq!('\u00AD'.width(false),Some(1)); - assert_eq!('\u00AD'.width(true),Some(1)); + assert_eq!('\u{AD}'.width(false),Some(1)); + assert_eq!('\u{AD}'.width(true),Some(1)); - assert_eq!('\u1160'.width(false),Some(0)); - assert_eq!('\u1160'.width(true),Some(0)); + assert_eq!('\u{1160}'.width(false),Some(0)); + assert_eq!('\u{1160}'.width(true),Some(0)); - assert_eq!('\u00a1'.width(false),Some(1)); - assert_eq!('\u00a1'.width(true),Some(2)); + assert_eq!('\u{a1}'.width(false),Some(1)); + assert_eq!('\u{a1}'.width(true),Some(2)); - assert_eq!('\u0300'.width(false),Some(0)); - assert_eq!('\u0300'.width(true),Some(0)); + assert_eq!('\u{300}'.width(false),Some(0)); + assert_eq!('\u{300}'.width(true),Some(0)); } diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 3181e28a1211b..c2c25f0aa3796 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -2855,8 +2855,8 @@ mod tests { assert_eq!(from_str("\"\\r\""), Ok(String("\r".into_string()))); assert_eq!(from_str("\"\\t\""), Ok(String("\t".into_string()))); assert_eq!(from_str(" \"foo\" "), Ok(String("foo".into_string()))); - assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u{12ab}".into_string()))); - assert_eq!(from_str("\"\\uAB12\""), Ok(String("\u{AB12}".into_string()))); + assert_eq!(from_str("\"\\u{12ab}\""), Ok(String("\u{12ab}".into_string()))); + assert_eq!(from_str("\"\\u{AB12}\""), Ok(String("\u{AB12}".into_string()))); } #[test] @@ -2868,8 +2868,8 @@ mod tests { ("\"\\n\"", "\n"), ("\"\\r\"", "\r"), ("\"\\t\"", "\t"), - ("\"\\u12ab\"", "\u{12ab}"), - ("\"\\uAB12\"", "\u{AB12}")]; + ("\"\\u{12ab}\"", "\u{12ab}"), + ("\"\\u{AB12}\"", "\u{AB12}")]; for &(i, o) in s.iter() { let v: string::String = super::decode(i).unwrap(); diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 258e8964a9fdf..351cfe620c14c 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -119,7 +119,7 @@ fn with_env_lock(f: F) -> T where /// Returns a vector of (variable, value) pairs, for all the environment /// variables of the current process. /// -/// Invalid UTF-8 bytes are replaced with \uFFFD. See `String::from_utf8_lossy()` +/// Invalid UTF-8 bytes are replaced with \u{FFFD}. See `String::from_utf8_lossy()` /// for details. /// /// # Example @@ -166,7 +166,7 @@ pub fn env_as_bytes() -> Vec<(Vec,Vec)> { /// Fetches the environment variable `n` from the current process, returning /// None if the variable isn't set. /// -/// Any invalid UTF-8 bytes in the value are replaced by \uFFFD. See +/// Any invalid UTF-8 bytes in the value are replaced by \u{FFFD}. See /// `String::from_utf8_lossy()` for details. /// /// # Panics @@ -768,7 +768,7 @@ extern "system" { /// set to arbitrary text, and it may not even exist, so this property should not /// be relied upon for security purposes. /// -/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD. +/// The arguments are interpreted as utf-8, with invalid bytes replaced with \u{FFFD}. /// See `String::from_utf8_lossy` for details. /// # Example /// diff --git a/src/test/pretty/block-comment-wchar.pp b/src/test/pretty/block-comment-wchar.pp index fbdd15b6060b6..e0937c92a4ad3 100644 --- a/src/test/pretty/block-comment-wchar.pp +++ b/src/test/pretty/block-comment-wchar.pp @@ -105,10 +105,10 @@ fn main() { // Taken from http://www.unicode.org/Public/UNIDATA/PropList.txt let chars = - ['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u0085', '\u00A0', '\u1680', - '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', - '\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F', - '\u205F', '\u3000']; + ['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}', '\u{1680}', + '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}', '\u{2004}', '\u{2005}', '\u{2006}', + '\u{2007}', '\u{2008}', '\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}', + '\u{205F}', '\u{3000}']; for c in chars.iter() { let ws = c.is_whitespace(); println!("{} {}" , c , ws); diff --git a/src/test/pretty/block-comment-wchar.rs b/src/test/pretty/block-comment-wchar.rs index cc5640ce82a37..6c04896cac2d2 100644 --- a/src/test/pretty/block-comment-wchar.rs +++ b/src/test/pretty/block-comment-wchar.rs @@ -99,10 +99,10 @@ fn f() { fn main() { // Taken from http://www.unicode.org/Public/UNIDATA/PropList.txt let chars = - ['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u0085', '\u00A0', '\u1680', - '\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006', - '\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F', - '\u205F', '\u3000']; + ['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}', '\u{1680}', + '\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}', '\u{2004}', '\u{2005}', '\u{2006}', + '\u{2007}', '\u{2008}', '\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}', + '\u{205F}', '\u{3000}']; for c in chars.iter() { let ws = c.is_whitespace(); println!("{} {}", c , ws); diff --git a/src/test/run-pass/nul-characters.rs b/src/test/run-pass/nul-characters.rs index 22786c0abc89b..4a14969209f02 100644 --- a/src/test/run-pass/nul-characters.rs +++ b/src/test/run-pass/nul-characters.rs @@ -10,10 +10,10 @@ pub fn main() { - let all_nuls1 = "\0\x00\u0000\U00000000"; - let all_nuls2 = "\U00000000\u0000\x00\0"; - let all_nuls3 = "\u0000\U00000000\x00\0"; - let all_nuls4 = "\x00\u0000\0\U00000000"; + let all_nuls1 = "\0\x00\u{0}\u{0}"; + let all_nuls2 = "\u{0}\u{0}\x00\0"; + let all_nuls3 = "\u{0}\u{0}\x00\0"; + let all_nuls4 = "\x00\u{0}\0\u{0}"; // sizes for two should suffice assert_eq!(all_nuls1.len(), 4); @@ -35,8 +35,8 @@ pub fn main() // testing equality between explicit character literals assert_eq!('\0', '\x00'); - assert_eq!('\u0000', '\x00'); - assert_eq!('\u0000', '\U00000000'); + assert_eq!('\u{0}', '\x00'); + assert_eq!('\u{0}', '\u{0}'); // NUL characters should make a difference assert!("Hello World" != "Hello \0World"); diff --git a/src/test/run-pass/process-spawn-with-unicode-params.rs b/src/test/run-pass/process-spawn-with-unicode-params.rs index cceb0bf4d96e8..0b06782975651 100644 --- a/src/test/run-pass/process-spawn-with-unicode-params.rs +++ b/src/test/run-pass/process-spawn-with-unicode-params.rs @@ -31,7 +31,7 @@ fn main() { let my_ext = my_path.extension_str().unwrap_or(""); // some non-ASCII characters - let blah = "\u03c0\u042f\u97f3\u00e6\u221e"; + let blah = "\u{3c0}\u{42f}\u{97f3}\u{e6}\u{221e}"; let child_name = "child"; let child_dir = format!("process-spawn-with-unicode-params-{}", blah); diff --git a/src/test/run-pass/utf8.rs b/src/test/run-pass/utf8.rs index a52828387bf92..2d0d5f18d215f 100644 --- a/src/test/run-pass/utf8.rs +++ b/src/test/run-pass/utf8.rs @@ -24,7 +24,7 @@ pub fn main() { assert_eq!(y_diaeresis as int, 0xff); assert_eq!(pi as int, 0x3a0); - assert_eq!(pi as int, '\u03a0' as int); + assert_eq!(pi as int, '\u{3a0}' as int); assert_eq!('\x0a' as int, '\n' as int); let bhutan: String = "འབྲུག་ཡུལ།".to_string(); @@ -33,11 +33,11 @@ pub fn main() { let austria: String = "Österreich".to_string(); let bhutan_e: String = - "\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d".to_string(); - let japan_e: String = "\u65e5\u672c".to_string(); + "\u{f60}\u{f56}\u{fb2}\u{f74}\u{f42}\u{f0b}\u{f61}\u{f74}\u{f63}\u{f0d}".to_string(); + let japan_e: String = "\u{65e5}\u{672c}".to_string(); let uzbekistan_e: String = - "\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d".to_string(); - let austria_e: String = "\u00d6sterreich".to_string(); + "\u{40e}\u{437}\u{431}\u{435}\u{43a}\u{438}\u{441}\u{442}\u{43e}\u{43d}".to_string(); + let austria_e: String = "\u{d6}sterreich".to_string(); let oo: char = 'Ö'; assert_eq!(oo as int, 0xd6);