diff options
| author | varkor <github@varkor.com> | 2018-05-17 10:45:34 +0100 |
|---|---|---|
| committer | varkor <github@varkor.com> | 2018-05-21 18:57:54 +0100 |
| commit | c51f00280205d476651ff9f9a46cff6645b411a2 (patch) | |
| tree | 07b1bf6c4e79740cb0d84137eeae7935e27cbed3 /src/liballoc | |
| parent | 8c89e7f3d58ff110aa4de64aef8ef29f78ebf456 (diff) | |
| download | rust-c51f00280205d476651ff9f9a46cff6645b411a2.tar.gz rust-c51f00280205d476651ff9f9a46cff6645b411a2.zip | |
Only escape extended grapheme characters in the first position
Diffstat (limited to 'src/liballoc')
| -rw-r--r-- | src/liballoc/str.rs | 5 | ||||
| -rw-r--r-- | src/liballoc/tests/str.rs | 2 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/liballoc/str.rs b/src/liballoc/str.rs index c10c0a69433..8af14d3c698 100644 --- a/src/liballoc/str.rs +++ b/src/liballoc/str.rs @@ -372,12 +372,15 @@ impl str { /// Escapes each char in `s` with [`char::escape_debug`]. /// + /// Note: only extended grapheme codepoints that begin the string will be + /// escaped. + /// /// [`char::escape_debug`]: primitive.char.html#method.escape_debug #[unstable(feature = "str_escape", reason = "return type may change to be an iterator", issue = "27791")] pub fn escape_debug(&self) -> String { - self.chars().flat_map(|c| c.escape_debug()).collect() + self.chars().enumerate().flat_map(|(i, c)| c.escape_debug_ext(i == 0)).collect() } /// Escapes each char in `s` with [`char::escape_default`]. diff --git a/src/liballoc/tests/str.rs b/src/liballoc/tests/str.rs index 2f38c8b3ae2..84c97abcbc2 100644 --- a/src/liballoc/tests/str.rs +++ b/src/liballoc/tests/str.rs @@ -999,7 +999,7 @@ fn test_escape_debug() { assert_eq!("\u{10000}\u{10ffff}".escape_debug(), "\u{10000}\\u{10ffff}"); assert_eq!("ab\u{200b}".escape_debug(), "ab\\u{200b}"); assert_eq!("\u{10d4ea}\r".escape_debug(), "\\u{10d4ea}\\r"); - assert_eq!("\u{301}a\u{301}bé\u{e000}".escape_debug(), "\\u{301}a\\u{301}bé\\u{e000}"); + assert_eq!("\u{301}a\u{301}bé\u{e000}".escape_debug(), "\\u{301}a\u{301}bé\\u{e000}"); } #[test] |
