Skip to content

Remove all utf-8 deprecated warning. #19988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
56 changes: 28 additions & 28 deletions src/libcoretest/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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));
}
8 changes: 4 additions & 4 deletions src/libserialize/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ fn with_env_lock<T, F>(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
Expand Down Expand Up @@ -166,7 +166,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
/// 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
Expand Down Expand Up @@ -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
///
Expand Down
8 changes: 4 additions & 4 deletions src/test/pretty/block-comment-wchar.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/test/pretty/block-comment-wchar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions src/test/run-pass/nul-characters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-pass/process-spawn-with-unicode-params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions src/test/run-pass/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand Down