Rename char::escape
to char::escape_debug
and add tracking issue
This commit is contained in:
parent
68efea08fa
commit
3d09b4a0d5
@ -33,7 +33,7 @@
|
||||
#![feature(allow_internal_unstable)]
|
||||
#![feature(box_patterns)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(char_escape)]
|
||||
#![cfg_attr(not(test), feature(char_escape_debug))]
|
||||
#![feature(core_intrinsics)]
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(fmt_internals)]
|
||||
|
@ -1697,12 +1697,12 @@ impl str {
|
||||
return s;
|
||||
}
|
||||
|
||||
/// Escapes each char in `s` with `char::escape`.
|
||||
/// Escapes each char in `s` with `char::escape_debug`.
|
||||
#[unstable(feature = "str_escape",
|
||||
reason = "return type may change to be an iterator",
|
||||
issue = "27791")]
|
||||
pub fn escape(&self) -> String {
|
||||
self.chars().flat_map(|c| c.escape()).collect()
|
||||
pub fn escape_debug(&self) -> String {
|
||||
self.chars().flat_map(|c| c.escape_debug()).collect()
|
||||
}
|
||||
|
||||
/// Escapes each char in `s` with `char::escape_default`.
|
||||
|
@ -704,17 +704,17 @@ fn test_escape_unicode() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape() {
|
||||
assert_eq!("abc".escape_default(), "abc");
|
||||
assert_eq!("a c".escape_default(), "a c");
|
||||
assert_eq!("éèê".escape_default(), "éèê");
|
||||
assert_eq!("\r\n\t".escape_default(), "\\r\\n\\t");
|
||||
assert_eq!("'\"\\".escape_default(), "\\'\\\"\\\\");
|
||||
assert_eq!("\u{7f}\u{ff}".escape_default(), "\\u{7f}\u{ff}");
|
||||
assert_eq!("\u{100}\u{ffff}".escape_default(), "\u{100}\\u{ffff}");
|
||||
assert_eq!("\u{10000}\u{10ffff}".escape_default(), "\u{10000}\\u{10ffff}");
|
||||
assert_eq!("ab\u{200b}".escape_default(), "ab\\u{200b}");
|
||||
assert_eq!("\u{10d4ea}\r".escape_default(), "\\u{10d4ea}\\r");
|
||||
fn test_escape_debug() {
|
||||
assert_eq!("abc".escape_debug(), "abc");
|
||||
assert_eq!("a c".escape_debug(), "a c");
|
||||
assert_eq!("éèê".escape_debug(), "éèê");
|
||||
assert_eq!("\r\n\t".escape_debug(), "\\r\\n\\t");
|
||||
assert_eq!("'\"\\".escape_debug(), "\\'\\\"\\\\");
|
||||
assert_eq!("\u{7f}\u{ff}".escape_debug(), "\\u{7f}\u{ff}");
|
||||
assert_eq!("\u{100}\u{ffff}".escape_debug(), "\u{100}\\u{ffff}");
|
||||
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");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -264,8 +264,8 @@ pub trait CharExt {
|
||||
fn escape_unicode(self) -> EscapeUnicode;
|
||||
#[stable(feature = "core", since = "1.6.0")]
|
||||
fn escape_default(self) -> EscapeDefault;
|
||||
#[unstable(feature = "char_escape", issue = "0")]
|
||||
fn escape(self) -> Escape;
|
||||
#[unstable(feature = "char_escape_debug", issue = "35068")]
|
||||
fn escape_debug(self) -> EscapeDebug;
|
||||
#[stable(feature = "core", since = "1.6.0")]
|
||||
fn len_utf8(self) -> usize;
|
||||
#[stable(feature = "core", since = "1.6.0")]
|
||||
@ -330,7 +330,7 @@ impl CharExt for char {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn escape(self) -> Escape {
|
||||
fn escape_debug(self) -> EscapeDebug {
|
||||
let init_state = match self {
|
||||
'\t' => EscapeDefaultState::Backslash('t'),
|
||||
'\r' => EscapeDefaultState::Backslash('r'),
|
||||
@ -339,7 +339,7 @@ impl CharExt for char {
|
||||
c if is_printable(c) => EscapeDefaultState::Char(c),
|
||||
c => EscapeDefaultState::Unicode(c.escape_unicode()),
|
||||
};
|
||||
Escape(EscapeDefault { state: init_state })
|
||||
EscapeDebug(EscapeDefault { state: init_state })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -618,24 +618,24 @@ impl ExactSizeIterator for EscapeDefault {
|
||||
|
||||
/// An iterator that yields the literal escape code of a `char`.
|
||||
///
|
||||
/// This `struct` is created by the [`escape()`] method on [`char`]. See its
|
||||
/// This `struct` is created by the [`escape_debug()`] method on [`char`]. See its
|
||||
/// documentation for more.
|
||||
///
|
||||
/// [`escape()`]: ../../std/primitive.char.html#method.escape
|
||||
/// [`escape_debug()`]: ../../std/primitive.char.html#method.escape_debug
|
||||
/// [`char`]: ../../std/primitive.char.html
|
||||
#[unstable(feature = "char_escape", issue = "0")]
|
||||
#[unstable(feature = "char_escape_debug", issue = "35068")]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Escape(EscapeDefault);
|
||||
pub struct EscapeDebug(EscapeDefault);
|
||||
|
||||
#[unstable(feature = "char_escape", issue = "0")]
|
||||
impl Iterator for Escape {
|
||||
#[unstable(feature = "char_escape_debug", issue = "35068")]
|
||||
impl Iterator for EscapeDebug {
|
||||
type Item = char;
|
||||
fn next(&mut self) -> Option<char> { self.0.next() }
|
||||
fn size_hint(&self) -> (usize, Option<usize>) { self.0.size_hint() }
|
||||
}
|
||||
|
||||
#[unstable(feature = "char_escape", issue = "0")]
|
||||
impl ExactSizeIterator for Escape { }
|
||||
#[unstable(feature = "char_escape_debug", issue = "35068")]
|
||||
impl ExactSizeIterator for EscapeDebug { }
|
||||
|
||||
/// An iterator over `u8` entries represending the UTF-8 encoding of a `char`
|
||||
/// value.
|
||||
|
@ -1383,7 +1383,7 @@ impl Debug for str {
|
||||
f.write_char('"')?;
|
||||
let mut from = 0;
|
||||
for (i, c) in self.char_indices() {
|
||||
let esc = c.escape();
|
||||
let esc = c.escape_debug();
|
||||
// If char needs escaping, flush backlog so far and write, else skip
|
||||
if esc.len() != 1 {
|
||||
f.write_str(&self[from..i])?;
|
||||
@ -1409,7 +1409,7 @@ impl Display for str {
|
||||
impl Debug for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
f.write_char('\'')?;
|
||||
for c in self.escape() {
|
||||
for c in self.escape_debug() {
|
||||
f.write_char(c)?
|
||||
}
|
||||
f.write_char('\'')
|
||||
|
@ -124,9 +124,9 @@ fn test_is_digit() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_escape() {
|
||||
fn test_escape_debug() {
|
||||
fn string(c: char) -> String {
|
||||
c.escape().collect()
|
||||
c.escape_debug().collect()
|
||||
}
|
||||
let s = string('\n');
|
||||
assert_eq!(s, "\\n");
|
||||
|
@ -14,6 +14,7 @@
|
||||
#![feature(borrow_state)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(cell_extras)]
|
||||
#![feature(char_escape_debug)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(core_private_bignum)]
|
||||
#![feature(core_private_diy_float)]
|
||||
@ -29,10 +30,10 @@
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(step_by)]
|
||||
#![feature(test)]
|
||||
#![feature(try_from)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unicode)]
|
||||
#![feature(unique)]
|
||||
#![feature(try_from)]
|
||||
|
||||
extern crate core;
|
||||
extern crate test;
|
||||
|
@ -36,7 +36,7 @@ use tables::{conversions, derived_property, general_category, property};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use core::char::{MAX, from_digit, from_u32, from_u32_unchecked};
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
pub use core::char::{EncodeUtf16, EncodeUtf8, Escape, EscapeDefault, EscapeUnicode};
|
||||
pub use core::char::{EncodeUtf16, EncodeUtf8, EscapeDebug, EscapeDefault, EscapeUnicode};
|
||||
|
||||
// unstable reexports
|
||||
#[unstable(feature = "decode_utf8", issue = "33906")]
|
||||
@ -296,10 +296,10 @@ impl char {
|
||||
///
|
||||
/// assert_eq!(quote, "\\n");
|
||||
/// ```
|
||||
#[unstable(feature = "char_escape", issue = "0")]
|
||||
#[unstable(feature = "char_escape_debug", issue = "35068")]
|
||||
#[inline]
|
||||
pub fn escape(self) -> Escape {
|
||||
C::escape(self)
|
||||
pub fn escape_debug(self) -> EscapeDebug {
|
||||
C::escape_debug(self)
|
||||
}
|
||||
|
||||
/// Returns an iterator that yields the literal escape code of a `char`.
|
||||
|
@ -32,7 +32,7 @@
|
||||
#![cfg_attr(not(stage0), deny(warnings))]
|
||||
#![no_std]
|
||||
|
||||
#![feature(char_escape)]
|
||||
#![feature(char_escape_debug)]
|
||||
#![feature(core_char_ext)]
|
||||
#![feature(decode_utf8)]
|
||||
#![feature(lang_items)]
|
||||
|
@ -218,8 +218,9 @@
|
||||
#![feature(associated_consts)]
|
||||
#![feature(borrow_state)]
|
||||
#![feature(box_syntax)]
|
||||
#![feature(cfg_target_vendor)]
|
||||
#![feature(cfg_target_thread_local)]
|
||||
#![feature(cfg_target_vendor)]
|
||||
#![feature(char_escape_debug)]
|
||||
#![feature(char_internals)]
|
||||
#![feature(collections)]
|
||||
#![feature(collections_bound)]
|
||||
@ -229,10 +230,10 @@
|
||||
#![feature(dropck_parametricity)]
|
||||
#![feature(float_extras)]
|
||||
#![feature(float_from_str_radix)]
|
||||
#![feature(fnbox)]
|
||||
#![feature(fn_traits)]
|
||||
#![feature(heap_api)]
|
||||
#![feature(fnbox)]
|
||||
#![feature(hashmap_hasher)]
|
||||
#![feature(heap_api)]
|
||||
#![feature(inclusive_range)]
|
||||
#![feature(int_error_internals)]
|
||||
#![feature(into_cow)]
|
||||
@ -242,6 +243,7 @@
|
||||
#![feature(linkage)]
|
||||
#![feature(macro_reexport)]
|
||||
#![cfg_attr(test, feature(map_values_mut))]
|
||||
#![feature(needs_panic_runtime)]
|
||||
#![feature(num_bits_bytes)]
|
||||
#![feature(old_wrapping)]
|
||||
#![feature(on_unimplemented)]
|
||||
@ -249,10 +251,11 @@
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(panic_unwind)]
|
||||
#![feature(placement_in_syntax)]
|
||||
#![feature(question_mark)]
|
||||
#![feature(rand)]
|
||||
#![feature(raw)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(reflect_marker)]
|
||||
#![feature(repr_simd)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(shared)]
|
||||
#![feature(sip_hash_13)]
|
||||
@ -266,6 +269,7 @@
|
||||
#![feature(str_utf16)]
|
||||
#![feature(test, rustc_private)]
|
||||
#![feature(thread_local)]
|
||||
#![feature(try_from)]
|
||||
#![feature(unboxed_closures)]
|
||||
#![feature(unicode)]
|
||||
#![feature(unique)]
|
||||
@ -273,9 +277,6 @@
|
||||
#![feature(unwind_attributes)]
|
||||
#![feature(vec_push_all)]
|
||||
#![feature(zero_one)]
|
||||
#![feature(question_mark)]
|
||||
#![feature(try_from)]
|
||||
#![feature(needs_panic_runtime)]
|
||||
|
||||
// Issue# 30592: Systematically use alloc_system during stage0 since jemalloc
|
||||
// might be unavailable or disabled
|
||||
|
@ -390,7 +390,7 @@ impl fmt::Debug for Wtf8 {
|
||||
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
|
||||
fn write_str_escaped(f: &mut fmt::Formatter, s: &str) -> fmt::Result {
|
||||
use fmt::Write;
|
||||
for c in s.chars().flat_map(|c| c.escape_default()) {
|
||||
for c in s.chars().flat_map(|c| c.escape_debug()) {
|
||||
f.write_char(c)?
|
||||
}
|
||||
Ok(())
|
||||
@ -1064,9 +1064,9 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn wtf8buf_show() {
|
||||
let mut string = Wtf8Buf::from_str("a\té 💩\r");
|
||||
let mut string = Wtf8Buf::from_str("a\té \u{7f}💩\r");
|
||||
string.push(CodePoint::from_u32(0xD800).unwrap());
|
||||
assert_eq!(format!("{:?}", string), r#""a\t\u{e9} \u{1f4a9}\r\u{D800}""#);
|
||||
assert_eq!(format!("{:?}", string), "\"a\\té \\u{7f}\u{1f4a9}\\r\\u{D800}\"");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -67,7 +67,7 @@ macro_rules! is_sync_send {
|
||||
|
||||
fn main() {
|
||||
// for char.rs
|
||||
all_sync_send!("Я", escape_default, escape_unicode);
|
||||
all_sync_send!("Я", escape_debug, escape_default, escape_unicode);
|
||||
|
||||
// for iter.rs
|
||||
all_sync_send_mutable_ref!([1], iter);
|
||||
|
Loading…
x
Reference in New Issue
Block a user