Skip to content

Commit 948e363

Browse files
committed
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' ```
1 parent 34d6800 commit 948e363

File tree

9 files changed

+58
-59
lines changed

9 files changed

+58
-59
lines changed

src/doc/reference.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,10 +248,9 @@ cases mentioned in [Number literals](#number-literals) below.
248248
| `\\` | Backslash |
249249

250250
##### Unicode escapes
251-
| | Name |
252-
|---|------|
253-
| `\u7FFF` | 16-bit character code (exactly 4 digits) |
254-
| `\U7EEEFFFF` | 32-bit character code (exactly 8 digits) |
251+
| | Name |
252+
|---|------------|
253+
| `\u{7FF}` | Unicode code point value (1 to 6 digits) |
255254

256255
##### Numbers
257256

src/libcoretest/char.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ fn test_is_uppercase() {
3333
#[test]
3434
fn test_is_whitespace() {
3535
assert!(' '.is_whitespace());
36-
assert!('\u2007'.is_whitespace());
36+
assert!('\u{2007}'.is_whitespace());
3737
assert!('\t'.is_whitespace());
3838
assert!('\n'.is_whitespace());
3939
assert!(!'a'.is_whitespace());
4040
assert!(!'_'.is_whitespace());
41-
assert!(!'\u0000'.is_whitespace());
41+
assert!(!'\u{0}'.is_whitespace());
4242
}
4343

4444
#[test]
@@ -92,15 +92,15 @@ fn test_to_uppercase() {
9292

9393
#[test]
9494
fn test_is_control() {
95-
assert!('\u0000'.is_control());
96-
assert!('\u0003'.is_control());
97-
assert!('\u0006'.is_control());
98-
assert!('\u0009'.is_control());
99-
assert!('\u007f'.is_control());
100-
assert!('\u0092'.is_control());
101-
assert!(!'\u0020'.is_control());
102-
assert!(!'\u0055'.is_control());
103-
assert!(!'\u0068'.is_control());
95+
assert!('\u{0}'.is_control());
96+
assert!('\u{3}'.is_control());
97+
assert!('\u{6}'.is_control());
98+
assert!('\u{9}'.is_control());
99+
assert!('\u{7f}'.is_control());
100+
assert!('\u{92}'.is_control());
101+
assert!(!'\u{20}'.is_control());
102+
assert!(!'\u{55}'.is_control());
103+
assert!(!'\u{68}'.is_control());
104104
}
105105

106106
#[test]
@@ -175,9 +175,9 @@ fn test_encode_utf8() {
175175
}
176176

177177
check('x', &[0x78]);
178-
check('\u00e9', &[0xc3, 0xa9]);
179-
check('\ua66e', &[0xea, 0x99, 0xae]);
180-
check('\U0001f4a9', &[0xf0, 0x9f, 0x92, 0xa9]);
178+
check('\u{e9}', &[0xc3, 0xa9]);
179+
check('\u{a66e}', &[0xea, 0x99, 0xae]);
180+
check('\u{1f4a9}', &[0xf0, 0x9f, 0x92, 0xa9]);
181181
}
182182

183183
#[test]
@@ -189,17 +189,17 @@ fn test_encode_utf16() {
189189
}
190190

191191
check('x', &[0x0078]);
192-
check('\u00e9', &[0x00e9]);
193-
check('\ua66e', &[0xa66e]);
194-
check('\U0001f4a9', &[0xd83d, 0xdca9]);
192+
check('\u{e9}', &[0x00e9]);
193+
check('\u{a66e}', &[0xa66e]);
194+
check('\u{1f4a9}', &[0xd83d, 0xdca9]);
195195
}
196196

197197
#[test]
198198
fn test_len_utf16() {
199199
assert!('x'.len_utf16() == 1);
200-
assert!('\u00e9'.len_utf16() == 1);
201-
assert!('\ua66e'.len_utf16() == 1);
202-
assert!('\U0001f4a9'.len_utf16() == 2);
200+
assert!('\u{e9}'.len_utf16() == 1);
201+
assert!('\u{a66e}'.len_utf16() == 1);
202+
assert!('\u{1f4a9}'.len_utf16() == 2);
203203
}
204204

205205
#[test]
@@ -216,15 +216,15 @@ fn test_width() {
216216
assert_eq!('h'.width(false),Some(2));
217217
assert_eq!('h'.width(true),Some(2));
218218

219-
assert_eq!('\u00AD'.width(false),Some(1));
220-
assert_eq!('\u00AD'.width(true),Some(1));
219+
assert_eq!('\u{AD}'.width(false),Some(1));
220+
assert_eq!('\u{AD}'.width(true),Some(1));
221221

222-
assert_eq!('\u1160'.width(false),Some(0));
223-
assert_eq!('\u1160'.width(true),Some(0));
222+
assert_eq!('\u{1160}'.width(false),Some(0));
223+
assert_eq!('\u{1160}'.width(true),Some(0));
224224

225-
assert_eq!('\u00a1'.width(false),Some(1));
226-
assert_eq!('\u00a1'.width(true),Some(2));
225+
assert_eq!('\u{a1}'.width(false),Some(1));
226+
assert_eq!('\u{a1}'.width(true),Some(2));
227227

228-
assert_eq!('\u0300'.width(false),Some(0));
229-
assert_eq!('\u0300'.width(true),Some(0));
228+
assert_eq!('\u{300}'.width(false),Some(0));
229+
assert_eq!('\u{300}'.width(true),Some(0));
230230
}

src/libserialize/json.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,8 +2855,8 @@ mod tests {
28552855
assert_eq!(from_str("\"\\r\""), Ok(String("\r".into_string())));
28562856
assert_eq!(from_str("\"\\t\""), Ok(String("\t".into_string())));
28572857
assert_eq!(from_str(" \"foo\" "), Ok(String("foo".into_string())));
2858-
assert_eq!(from_str("\"\\u12ab\""), Ok(String("\u{12ab}".into_string())));
2859-
assert_eq!(from_str("\"\\uAB12\""), Ok(String("\u{AB12}".into_string())));
2858+
assert_eq!(from_str("\"\\u{12ab}\""), Ok(String("\u{12ab}".into_string())));
2859+
assert_eq!(from_str("\"\\u{AB12}\""), Ok(String("\u{AB12}".into_string())));
28602860
}
28612861

28622862
#[test]
@@ -2868,8 +2868,8 @@ mod tests {
28682868
("\"\\n\"", "\n"),
28692869
("\"\\r\"", "\r"),
28702870
("\"\\t\"", "\t"),
2871-
("\"\\u12ab\"", "\u{12ab}"),
2872-
("\"\\uAB12\"", "\u{AB12}")];
2871+
("\"\\u{12ab}\"", "\u{12ab}"),
2872+
("\"\\u{AB12}\"", "\u{AB12}")];
28732873

28742874
for &(i, o) in s.iter() {
28752875
let v: string::String = super::decode(i).unwrap();

src/libstd/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn with_env_lock<T, F>(f: F) -> T where
119119
/// Returns a vector of (variable, value) pairs, for all the environment
120120
/// variables of the current process.
121121
///
122-
/// Invalid UTF-8 bytes are replaced with \uFFFD. See `String::from_utf8_lossy()`
122+
/// Invalid UTF-8 bytes are replaced with \u{FFFD}. See `String::from_utf8_lossy()`
123123
/// for details.
124124
///
125125
/// # Example
@@ -166,7 +166,7 @@ pub fn env_as_bytes() -> Vec<(Vec<u8>,Vec<u8>)> {
166166
/// Fetches the environment variable `n` from the current process, returning
167167
/// None if the variable isn't set.
168168
///
169-
/// Any invalid UTF-8 bytes in the value are replaced by \uFFFD. See
169+
/// Any invalid UTF-8 bytes in the value are replaced by \u{FFFD}. See
170170
/// `String::from_utf8_lossy()` for details.
171171
///
172172
/// # Panics
@@ -768,7 +768,7 @@ extern "system" {
768768
/// set to arbitrary text, and it may not even exist, so this property should not
769769
/// be relied upon for security purposes.
770770
///
771-
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
771+
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \u{FFFD}.
772772
/// See `String::from_utf8_lossy` for details.
773773
/// # Example
774774
///

src/test/pretty/block-comment-wchar.pp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@
105105
fn main() {
106106
// Taken from http://www.unicode.org/Public/UNIDATA/PropList.txt
107107
let chars =
108-
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u0085', '\u00A0', '\u1680',
109-
'\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006',
110-
'\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F',
111-
'\u205F', '\u3000'];
108+
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}', '\u{1680}',
109+
'\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}', '\u{2004}', '\u{2005}', '\u{2006}',
110+
'\u{2007}', '\u{2008}', '\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}',
111+
'\u{205F}', '\u{3000}'];
112112
for c in chars.iter() {
113113
let ws = c.is_whitespace();
114114
println!("{} {}" , c , ws);

src/test/pretty/block-comment-wchar.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ fn f() {
9999
fn main() {
100100
// Taken from http://www.unicode.org/Public/UNIDATA/PropList.txt
101101
let chars =
102-
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u0085', '\u00A0', '\u1680',
103-
'\u2000', '\u2001', '\u2002', '\u2003', '\u2004', '\u2005', '\u2006',
104-
'\u2007', '\u2008', '\u2009', '\u200A', '\u2028', '\u2029', '\u202F',
105-
'\u205F', '\u3000'];
102+
['\x0A', '\x0B', '\x0C', '\x0D', '\x20', '\u{85}', '\u{A0}', '\u{1680}',
103+
'\u{2000}', '\u{2001}', '\u{2002}', '\u{2003}', '\u{2004}', '\u{2005}', '\u{2006}',
104+
'\u{2007}', '\u{2008}', '\u{2009}', '\u{200A}', '\u{2028}', '\u{2029}', '\u{202F}',
105+
'\u{205F}', '\u{3000}'];
106106
for c in chars.iter() {
107107
let ws = c.is_whitespace();
108108
println!("{} {}", c , ws);

src/test/run-pass/nul-characters.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111
pub fn main()
1212
{
13-
let all_nuls1 = "\0\x00\u0000\U00000000";
14-
let all_nuls2 = "\U00000000\u0000\x00\0";
15-
let all_nuls3 = "\u0000\U00000000\x00\0";
16-
let all_nuls4 = "\x00\u0000\0\U00000000";
13+
let all_nuls1 = "\0\x00\u{0}\u{0}";
14+
let all_nuls2 = "\u{0}\u{0}\x00\0";
15+
let all_nuls3 = "\u{0}\u{0}\x00\0";
16+
let all_nuls4 = "\x00\u{0}\0\u{0}";
1717

1818
// sizes for two should suffice
1919
assert_eq!(all_nuls1.len(), 4);
@@ -35,8 +35,8 @@ pub fn main()
3535

3636
// testing equality between explicit character literals
3737
assert_eq!('\0', '\x00');
38-
assert_eq!('\u0000', '\x00');
39-
assert_eq!('\u0000', '\U00000000');
38+
assert_eq!('\u{0}', '\x00');
39+
assert_eq!('\u{0}', '\u{0}');
4040

4141
// NUL characters should make a difference
4242
assert!("Hello World" != "Hello \0World");

src/test/run-pass/process-spawn-with-unicode-params.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn main() {
3131
let my_ext = my_path.extension_str().unwrap_or("");
3232

3333
// some non-ASCII characters
34-
let blah = "\u03c0\u042f\u97f3\u00e6\u221e";
34+
let blah = "\u{3c0}\u{42f}\u{97f3}\u{e6}\u{221e}";
3535

3636
let child_name = "child";
3737
let child_dir = format!("process-spawn-with-unicode-params-{}", blah);

src/test/run-pass/utf8.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub fn main() {
2424
assert_eq!(y_diaeresis as int, 0xff);
2525
assert_eq!(pi as int, 0x3a0);
2626

27-
assert_eq!(pi as int, '\u03a0' as int);
27+
assert_eq!(pi as int, '\u{3a0}' as int);
2828
assert_eq!('\x0a' as int, '\n' as int);
2929

3030
let bhutan: String = "འབྲུག་ཡུལ།".to_string();
@@ -33,11 +33,11 @@ pub fn main() {
3333
let austria: String = "Österreich".to_string();
3434

3535
let bhutan_e: String =
36-
"\u0f60\u0f56\u0fb2\u0f74\u0f42\u0f0b\u0f61\u0f74\u0f63\u0f0d".to_string();
37-
let japan_e: String = "\u65e5\u672c".to_string();
36+
"\u{f60}\u{f56}\u{fb2}\u{f74}\u{f42}\u{f0b}\u{f61}\u{f74}\u{f63}\u{f0d}".to_string();
37+
let japan_e: String = "\u{65e5}\u{672c}".to_string();
3838
let uzbekistan_e: String =
39-
"\u040e\u0437\u0431\u0435\u043a\u0438\u0441\u0442\u043e\u043d".to_string();
40-
let austria_e: String = "\u00d6sterreich".to_string();
39+
"\u{40e}\u{437}\u{431}\u{435}\u{43a}\u{438}\u{441}\u{442}\u{43e}\u{43d}".to_string();
40+
let austria_e: String = "\u{d6}sterreich".to_string();
4141

4242
let oo: char = 'Ö';
4343
assert_eq!(oo as int, 0xd6);

0 commit comments

Comments
 (0)