@@ -970,6 +970,50 @@ impl char {
970970 }
971971 }
972972
973+ /// Returns `true` if this `char` has one of the general categories for numbers.
974+ ///
975+ /// The general categories for numbers (`Nd` for decimal digits, `Nl` for letter-like numeric
976+ /// characters, and `No` for other numeric characters) are [specified] in the Unicode Character
977+ /// Database [`UnicodeData.txt`].
978+ ///
979+ /// This method doesn't cover everything that could be considered a number, e.g. ideographic numbers like '三'.
980+ /// If you want everything including characters with overlapping purposes, then you might want to use
981+ /// a Unicode or language-processing library that exposes the appropriate character properties
982+ /// (e.g. [`Numeric_Type`]) instead of looking at the Unicode categories.
983+ ///
984+ /// If you want to parse ASCII decimal digits (0-9) or ASCII base-N, use
985+ /// `is_ascii_digit` or `is_digit` instead.
986+ ///
987+ /// [specified]: https://www.unicode.org/reports/tr44/#GC_Values_Table
988+ /// [`UnicodeData.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
989+ /// [`Numeric_Type`]: https://www.unicode.org/reports/tr44/#Numeric_Type
990+ ///
991+ /// # Examples
992+ ///
993+ /// Basic usage:
994+ ///
995+ /// ```
996+ /// assert!('٣'.is_numeric());
997+ /// assert!('7'.is_numeric());
998+ /// assert!('৬'.is_numeric());
999+ /// assert!('¾'.is_numeric());
1000+ /// assert!('①'.is_numeric());
1001+ /// assert!(!'K'.is_numeric());
1002+ /// assert!(!'و'.is_numeric());
1003+ /// assert!(!'藏'.is_numeric());
1004+ /// assert!(!'三'.is_numeric());
1005+ /// ```
1006+ #[ must_use]
1007+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1008+ #[ inline]
1009+ pub fn is_numeric ( self ) -> bool {
1010+ match self {
1011+ '0' ..='9' => true ,
1012+ '\0' ..='\u{B1}' => false ,
1013+ _ => unicode:: N ( self ) ,
1014+ }
1015+ }
1016+
9731017 /// Returns `true` if this `char` satisfies either [`is_alphabetic()`] or [`is_numeric()`].
9741018 ///
9751019 /// [`is_alphabetic()`]: Self::is_alphabetic
@@ -1102,50 +1146,6 @@ impl char {
11021146 }
11031147 }
11041148
1105- /// Returns `true` if this `char` has one of the general categories for numbers.
1106- ///
1107- /// The general categories for numbers (`Nd` for decimal digits, `Nl` for letter-like numeric
1108- /// characters, and `No` for other numeric characters) are [specified] in the Unicode Character
1109- /// Database [`UnicodeData.txt`].
1110- ///
1111- /// This method doesn't cover everything that could be considered a number, e.g. ideographic numbers like '三'.
1112- /// If you want everything including characters with overlapping purposes, then you might want to use
1113- /// a Unicode or language-processing library that exposes the appropriate character properties
1114- /// (e.g. [`Numeric_Type`]) instead of looking at the Unicode categories.
1115- ///
1116- /// If you want to parse ASCII decimal digits (0-9) or ASCII base-N, use
1117- /// `is_ascii_digit` or `is_digit` instead.
1118- ///
1119- /// [specified]: https://www.unicode.org/reports/tr44/#GC_Values_Table
1120- /// [`UnicodeData.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/UnicodeData.txt
1121- /// [`Numeric_Type`]: https://www.unicode.org/reports/tr44/#Numeric_Type
1122- ///
1123- /// # Examples
1124- ///
1125- /// Basic usage:
1126- ///
1127- /// ```
1128- /// assert!('٣'.is_numeric());
1129- /// assert!('7'.is_numeric());
1130- /// assert!('৬'.is_numeric());
1131- /// assert!('¾'.is_numeric());
1132- /// assert!('①'.is_numeric());
1133- /// assert!(!'K'.is_numeric());
1134- /// assert!(!'و'.is_numeric());
1135- /// assert!(!'藏'.is_numeric());
1136- /// assert!(!'三'.is_numeric());
1137- /// ```
1138- #[ must_use]
1139- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
1140- #[ inline]
1141- pub fn is_numeric ( self ) -> bool {
1142- match self {
1143- '0' ..='9' => true ,
1144- '\0' ..='\u{B1}' => false ,
1145- _ => unicode:: N ( self ) ,
1146- }
1147- }
1148-
11491149 /// Returns an iterator that yields the lowercase mapping of this `char` as one or more
11501150 /// `char`s.
11511151 ///
0 commit comments