summaryrefslogtreecommitdiffstats
path: root/library/core/src/char
diff options
context:
space:
mode:
Diffstat (limited to 'library/core/src/char')
-rw-r--r--library/core/src/char/convert.rs28
-rw-r--r--library/core/src/char/decode.rs6
-rw-r--r--library/core/src/char/methods.rs24
-rw-r--r--library/core/src/char/mod.rs2
4 files changed, 20 insertions, 40 deletions
diff --git a/library/core/src/char/convert.rs b/library/core/src/char/convert.rs
index f1a51a550..136bbcb8b 100644
--- a/library/core/src/char/convert.rs
+++ b/library/core/src/char/convert.rs
@@ -2,6 +2,7 @@
use crate::char::TryFromCharError;
use crate::convert::TryFrom;
+use crate::error::Error;
use crate::fmt;
use crate::mem::transmute;
use crate::str::FromStr;
@@ -150,14 +151,16 @@ pub struct ParseCharError {
kind: CharErrorKind,
}
-impl ParseCharError {
- #[unstable(
- feature = "char_error_internals",
- reason = "this method should not be available publicly",
- issue = "none"
- )]
- #[doc(hidden)]
- pub fn __description(&self) -> &str {
+#[derive(Copy, Clone, Debug, PartialEq, Eq)]
+enum CharErrorKind {
+ EmptyString,
+ TooManyChars,
+}
+
+#[stable(feature = "char_from_str", since = "1.20.0")]
+impl Error for ParseCharError {
+ #[allow(deprecated)]
+ fn description(&self) -> &str {
match self.kind {
CharErrorKind::EmptyString => "cannot parse char from empty string",
CharErrorKind::TooManyChars => "too many characters in string",
@@ -165,16 +168,11 @@ impl ParseCharError {
}
}
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-enum CharErrorKind {
- EmptyString,
- TooManyChars,
-}
-
#[stable(feature = "char_from_str", since = "1.20.0")]
impl fmt::Display for ParseCharError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
- self.__description().fmt(f)
+ #[allow(deprecated)]
+ self.description().fmt(f)
}
}
diff --git a/library/core/src/char/decode.rs b/library/core/src/char/decode.rs
index eeb088030..dbfe251f2 100644
--- a/library/core/src/char/decode.rs
+++ b/library/core/src/char/decode.rs
@@ -3,8 +3,6 @@
use crate::error::Error;
use crate::fmt;
-use super::from_u32_unchecked;
-
/// An iterator that decodes UTF-16 encoded code points from an iterator of `u16`s.
///
/// This `struct` is created by the [`decode_utf16`] method on [`char`]. See its
@@ -49,7 +47,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
if !u.is_utf16_surrogate() {
// SAFETY: not a surrogate
- Some(Ok(unsafe { from_u32_unchecked(u as u32) }))
+ Some(Ok(unsafe { char::from_u32_unchecked(u as u32) }))
} else if u >= 0xDC00 {
// a trailing surrogate
Some(Err(DecodeUtf16Error { code: u }))
@@ -69,7 +67,7 @@ impl<I: Iterator<Item = u16>> Iterator for DecodeUtf16<I> {
// all ok, so lets decode it.
let c = (((u & 0x3ff) as u32) << 10 | (u2 & 0x3ff) as u32) + 0x1_0000;
// SAFETY: we checked that it's a legal unicode value
- Some(Ok(unsafe { from_u32_unchecked(c) }))
+ Some(Ok(unsafe { char::from_u32_unchecked(c) }))
}
}
diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs
index 3e7383b4c..9bc97ea0b 100644
--- a/library/core/src/char/methods.rs
+++ b/library/core/src/char/methods.rs
@@ -53,15 +53,13 @@ impl char {
/// Basic usage:
///
/// ```
- /// use std::char::decode_utf16;
- ///
/// // 𝄞mus<invalid>ic<invalid>
/// let v = [
/// 0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0xDD1E, 0x0069, 0x0063, 0xD834,
/// ];
///
/// assert_eq!(
- /// decode_utf16(v)
+ /// char::decode_utf16(v)
/// .map(|r| r.map_err(|e| e.unpaired_surrogate()))
/// .collect::<Vec<_>>(),
/// vec![
@@ -77,16 +75,14 @@ impl char {
/// A lossy decoder can be obtained by replacing `Err` results with the replacement character:
///
/// ```
- /// use std::char::{decode_utf16, REPLACEMENT_CHARACTER};
- ///
/// // 𝄞mus<invalid>ic<invalid>
/// let v = [
/// 0xD834, 0xDD1E, 0x006d, 0x0075, 0x0073, 0xDD1E, 0x0069, 0x0063, 0xD834,
/// ];
///
/// assert_eq!(
- /// decode_utf16(v)
- /// .map(|r| r.unwrap_or(REPLACEMENT_CHARACTER))
+ /// char::decode_utf16(v)
+ /// .map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))
/// .collect::<String>(),
/// "𝄞mus�ic�"
/// );
@@ -123,8 +119,6 @@ impl char {
/// Basic usage:
///
/// ```
- /// use std::char;
- ///
/// let c = char::from_u32(0x2764);
///
/// assert_eq!(Some('❤'), c);
@@ -133,8 +127,6 @@ impl char {
/// Returning `None` when the input is not a valid `char`:
///
/// ```
- /// use std::char;
- ///
/// let c = char::from_u32(0x110000);
///
/// assert_eq!(None, c);
@@ -176,8 +168,6 @@ impl char {
/// Basic usage:
///
/// ```
- /// use std::char;
- ///
/// let c = unsafe { char::from_u32_unchecked(0x2764) };
///
/// assert_eq!('❤', c);
@@ -210,8 +200,6 @@ impl char {
/// Basic usage:
///
/// ```
- /// use std::char;
- ///
/// let c = char::from_digit(4, 10);
///
/// assert_eq!(Some('4'), c);
@@ -225,8 +213,6 @@ impl char {
/// Returning `None` when the input is not a digit:
///
/// ```
- /// use std::char;
- ///
/// let c = char::from_digit(20, 10);
///
/// assert_eq!(None, c);
@@ -235,8 +221,6 @@ impl char {
/// Passing a large radix, causing a panic:
///
/// ```should_panic
- /// use std::char;
- ///
/// // this panics
/// let _c = char::from_digit(1, 37);
/// ```
@@ -1786,7 +1770,7 @@ pub fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] {
} else {
panic!(
"encode_utf16: need {} units to encode U+{:X}, but the buffer has {}",
- from_u32_unchecked(code).len_utf16(),
+ char::from_u32_unchecked(code).len_utf16(),
code,
dst.len(),
)
diff --git a/library/core/src/char/mod.rs b/library/core/src/char/mod.rs
index af98059cf..8ec78e887 100644
--- a/library/core/src/char/mod.rs
+++ b/library/core/src/char/mod.rs
@@ -189,7 +189,7 @@ impl Iterator for EscapeUnicode {
}
EscapeUnicodeState::Value => {
let hex_digit = ((self.c as u32) >> (self.hex_digit_idx * 4)) & 0xf;
- let c = from_digit(hex_digit, 16).unwrap();
+ let c = char::from_digit(hex_digit, 16).unwrap();
if self.hex_digit_idx == 0 {
self.state = EscapeUnicodeState::RightBrace;
} else {