Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions library/alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,8 @@ impl str {
}

fn case_ignorable_then_cased<I: Iterator<Item = char>>(iter: I) -> bool {
use core::unicode::{Case_Ignorable, Cased};
match iter.skip_while(|&c| Case_Ignorable(c)).next() {
Some(c) => Cased(c),
match iter.skip_while(|&c| c.is_case_ignorable()).next() {
Some(c) => c.is_cased(),
None => false,
}
}
Expand Down
38 changes: 37 additions & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,43 @@ impl char {
#[must_use]
#[inline]
pub(crate) fn is_grapheme_extended(self) -> bool {
unicode::Grapheme_Extend(self)
!self.is_ascii() && unicode::Grapheme_Extend(self)
}

/// Returns `true` if this `char` has the `Cased` property.
///
/// `Cased` is described in Chapter 4 (Character Properties) of the [Unicode Standard] and
/// specified in the [Unicode Character Database][ucd] [`DerivedCoreProperties.txt`].
///
/// [Unicode Standard]: https://www.unicode.org/versions/latest/
/// [ucd]: https://www.unicode.org/reports/tr44/
/// [`DerivedCoreProperties.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt
#[must_use]
#[inline]
#[doc(hidden)]
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
pub fn is_cased(self) -> bool {
if self.is_ascii() { self.is_ascii_alphabetic() } else { unicode::Cased(self) }
}

/// Returns `true` if this `char` has the `Case_Ignorable` property.
///
/// `Case_Ignorable` is described in Chapter 4 (Character Properties) of the [Unicode Standard] and
/// specified in the [Unicode Character Database][ucd] [`DerivedCoreProperties.txt`].
///
/// [Unicode Standard]: https://www.unicode.org/versions/latest/
/// [ucd]: https://www.unicode.org/reports/tr44/
/// [`DerivedCoreProperties.txt`]: https://www.unicode.org/Public/UCD/latest/ucd/DerivedCoreProperties.txt
#[must_use]
#[inline]
#[doc(hidden)]
#[unstable(feature = "char_internals", reason = "exposed only for libstd", issue = "none")]
pub fn is_case_ignorable(self) -> bool {
if self.is_ascii() {
matches!(self, '\'' | '.' | ':' | '^' | '`')
} else {
unicode::Case_Ignorable(self)
}
}

/// Returns `true` if this `char` has one of the general categories for numbers.
Expand Down
519 changes: 276 additions & 243 deletions library/core/src/unicode/unicode_data.rs

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/tools/unicode-table-generator/src/cascading_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ impl RawEmitter {

writeln!(&mut self.file, "#[inline]").unwrap();
writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap();
writeln!(&mut self.file, " debug_assert!(!c.is_ascii());").unwrap();
writeln!(&mut self.file, " match c as u32 >> 8 {{").unwrap();
for arm in arms {
writeln!(&mut self.file, " {arm},").unwrap();
Expand Down
1 change: 1 addition & 0 deletions src/tools/unicode-table-generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ fn load_data() -> UnicodeData {
.into_iter()
.flatten()
.flat_map(|cp| cp.scalar())
.filter(|c| !c.is_ascii())
.map(u32::from)
.collect::<Vec<_>>();
(prop, ranges_from_set(&codepoints))
Expand Down
1 change: 1 addition & 0 deletions src/tools/unicode-table-generator/src/raw_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl RawEmitter {
self.blank_line();

writeln!(&mut self.file, "pub const fn lookup(c: char) -> bool {{").unwrap();
writeln!(&mut self.file, " debug_assert!(!c.is_ascii());").unwrap();
if first_code_point > 0x7f {
writeln!(&mut self.file, " (c as u32) >= {first_code_point:#04x} &&").unwrap();
}
Expand Down
2 changes: 2 additions & 0 deletions src/tools/unicode-table-generator/src/skiplist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ impl RawEmitter {
if first_code_point > 0x7f {
writeln!(&mut self.file, "#[inline]").unwrap();
writeln!(&mut self.file, "pub fn lookup(c: char) -> bool {{").unwrap();
writeln!(&mut self.file, " debug_assert!(!c.is_ascii());").unwrap();
writeln!(&mut self.file, " (c as u32) >= {first_code_point:#04x} && lookup_slow(c)")
.unwrap();
writeln!(&mut self.file, "}}").unwrap();
Expand All @@ -107,6 +108,7 @@ impl RawEmitter {
writeln!(&mut self.file, "fn lookup_slow(c: char) -> bool {{").unwrap();
} else {
writeln!(&mut self.file, "pub fn lookup(c: char) -> bool {{").unwrap();
writeln!(&mut self.file, " debug_assert!(!c.is_ascii());").unwrap();
}
writeln!(&mut self.file, " const {{").unwrap();
writeln!(
Expand Down
Loading