Skip to content

Commit a725f3d

Browse files
committed
syntax: add 'try_case_fold_simple' to 'Class'
Previously this was only defined on 'ClassUnicode', but since 'Class' might contain a 'ClassUnicode', it should be defined here too. We don't need to update any call sites since this crate doesn't actually use 'Class::case_fold_simple' directly, and instead manipulates the underlying 'ClassUnicode' or 'ClassBytes'.
1 parent 25866ae commit a725f3d

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

regex-syntax/src/hir/mod.rs

+32
Original file line numberDiff line numberDiff line change
@@ -795,13 +795,45 @@ impl Class {
795795
///
796796
/// If this is a byte oriented character class, then this will be limited
797797
/// to the ASCII ranges `A-Z` and `a-z`.
798+
///
799+
/// # Panics
800+
///
801+
/// This routine panics when the case mapping data necessary for this
802+
/// routine to complete is unavailable. This occurs when the `unicode-case`
803+
/// feature is not enabled and the underlying class is Unicode oriented.
804+
///
805+
/// Callers should prefer using `try_case_fold_simple` instead, which will
806+
/// return an error instead of panicking.
798807
pub fn case_fold_simple(&mut self) {
799808
match *self {
800809
Class::Unicode(ref mut x) => x.case_fold_simple(),
801810
Class::Bytes(ref mut x) => x.case_fold_simple(),
802811
}
803812
}
804813

814+
/// Apply Unicode simple case folding to this character class, in place.
815+
/// The character class will be expanded to include all simple case folded
816+
/// character variants.
817+
///
818+
/// If this is a byte oriented character class, then this will be limited
819+
/// to the ASCII ranges `A-Z` and `a-z`.
820+
///
821+
/// # Error
822+
///
823+
/// This routine returns an error when the case mapping data necessary
824+
/// for this routine to complete is unavailable. This occurs when the
825+
/// `unicode-case` feature is not enabled and the underlying class is
826+
/// Unicode oriented.
827+
pub fn try_case_fold_simple(
828+
&mut self,
829+
) -> result::Result<(), CaseFoldError> {
830+
match *self {
831+
Class::Unicode(ref mut x) => x.try_case_fold_simple()?,
832+
Class::Bytes(ref mut x) => x.case_fold_simple(),
833+
}
834+
Ok(())
835+
}
836+
805837
/// Negate this character class in place.
806838
///
807839
/// After completion, this character class will contain precisely the

0 commit comments

Comments
 (0)