Skip to content

Commit c6871d0

Browse files
committed
---
yaml --- r: 79791 b: refs/heads/try c: f6b36c6 h: refs/heads/master i: 79789: 964baf1 79787: 7c8ce97 79783: ac35704 79775: e3989da v: v3
1 parent cd63cdf commit c6871d0

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: ba9fa89bfb4aae53db93e9ecac31807af96356fc
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 54ae2800ffb30513f89ce13d27ac3c8d095d98ac
5-
refs/heads/try: 7f8ada9acf128507106e67834c8d0d780f38636c
5+
refs/heads/try: f6b36c676e6b31313a8fd2b31e804bd3d6a4af73
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libstd/repr.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl<'self> ReprVisitor<'self> {
178178
pub fn write_escaped_slice(&mut self, slice: &str) {
179179
self.writer.write(['"' as u8]);
180180
for ch in slice.iter() {
181-
self.write_escaped_char(ch);
181+
self.write_escaped_char(ch, true);
182182
}
183183
self.writer.write(['"' as u8]);
184184
}
@@ -230,14 +230,26 @@ impl<'self> ReprVisitor<'self> {
230230
v.fill, inner)
231231
}
232232

233-
fn write_escaped_char(&mut self, ch: char) {
233+
fn write_escaped_char(&mut self, ch: char, is_str: bool) {
234234
match ch {
235235
'\t' => self.writer.write("\\t".as_bytes()),
236236
'\r' => self.writer.write("\\r".as_bytes()),
237237
'\n' => self.writer.write("\\n".as_bytes()),
238238
'\\' => self.writer.write("\\\\".as_bytes()),
239-
'\'' => self.writer.write("\\'".as_bytes()),
240-
'"' => self.writer.write("\\\"".as_bytes()),
239+
'\'' => {
240+
if is_str {
241+
self.writer.write("'".as_bytes())
242+
} else {
243+
self.writer.write("\\'".as_bytes())
244+
}
245+
}
246+
'"' => {
247+
if is_str {
248+
self.writer.write("\\\"".as_bytes())
249+
} else {
250+
self.writer.write("\"".as_bytes())
251+
}
252+
}
241253
'\x20'..'\x7e' => self.writer.write([ch as u8]),
242254
_ => {
243255
do char::escape_unicode(ch) |c| {
@@ -274,7 +286,7 @@ impl<'self> TyVisitor for ReprVisitor<'self> {
274286
fn visit_char(&mut self) -> bool {
275287
do self.get::<char> |this, &ch| {
276288
this.writer.write(['\'' as u8]);
277-
this.write_escaped_char(ch);
289+
this.write_escaped_char(ch, false);
278290
this.writer.write(['\'' as u8]);
279291
}
280292
}
@@ -684,6 +696,11 @@ fn test_repr() {
684696
exact_test(&(10u64, ~"hello"),
685697
"(10u64, ~\"hello\")");
686698

699+
exact_test(&'\'', "'\\''");
700+
exact_test(&'"', "'\"'");
701+
exact_test(&("'"), "\"'\"");
702+
exact_test(&("\""), "\"\\\"\"");
703+
687704
exact_test(&println, "fn(&str)");
688705
exact_test(&swap::<int>, "fn(&mut int, &mut int)");
689706
exact_test(&is_alphabetic, "fn(char) -> bool");

0 commit comments

Comments
 (0)