Skip to content

Commit d162865

Browse files
committed
Move IdentifierStatus into its own module
1 parent b56f3a1 commit d162865

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/general_security_profile.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//! Utilities for working with the [General Security Profile](https://www.unicode.org/reports/tr39/#General_Security_Profile)
2+
//! for identifiers
3+
4+
use crate::tables::identifier_status as is;
5+
6+
/// Methods for determining characters not restricted from use for identifiers.
7+
pub trait GeneralSecurityProfile {
8+
/// Returns whether the character is not restricted from use for identifiers.
9+
fn identifier_allowed(self) -> bool;
10+
}
11+
12+
impl GeneralSecurityProfile for char {
13+
#[inline]
14+
fn identifier_allowed(self) -> bool { is::identifier_status_allowed(self) }
15+
}
16+
17+
impl GeneralSecurityProfile for &'_ str {
18+
#[inline]
19+
fn identifier_allowed(self) -> bool { self.chars().all(is::identifier_status_allowed) }
20+
}

src/lib.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
//! ```rust
1616
//! extern crate unicode_security;
1717
//!
18-
//! use unicode_security::IdentifierStatusChar;
18+
//! use unicode_security::GeneralSecurityProfile;
1919
//!
2020
//! fn main() {
2121
//! let ch = 'µ'; // U+00B5 MICRO SIGN
@@ -55,23 +55,16 @@ extern crate std;
5555
#[cfg(feature = "bench")]
5656
extern crate test;
5757

58-
use tables::identifier_status as is;
5958
pub use tables::UNICODE_VERSION;
6059

6160
pub mod mixed_script;
61+
pub mod general_security_profile;
6262

63-
mod tables;
63+
pub use mixed_script::MixedScript;
64+
pub use general_security_profile::GeneralSecurityProfile;
65+
66+
#[rustfmt::skip]
67+
pub(crate) mod tables;
6468

6569
#[cfg(test)]
6670
mod tests;
67-
68-
/// Methods for determining characters not restricted from use for identifiers.
69-
pub trait UnicodeIdentifierStatus {
70-
/// Returns whether the character is not restricted from use for identifiers.
71-
fn identifier_allowed(self) -> bool;
72-
}
73-
74-
impl UnicodeIdentifierStatus for char {
75-
#[inline]
76-
fn identifier_allowed(self) -> bool { is::identifier_status_allowed(self) }
77-
}

src/tests.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010

1111
#[test]
1212
fn test_char() {
13-
use super::IdentifierStatusChar;
14-
assert_eq!(IdentifierStatusChar::identifier_allowed('A'), true);
13+
use crate::GeneralSecurityProfile;
14+
assert_eq!(GeneralSecurityProfile::identifier_allowed('A'), true);
1515
assert_eq!('A'.identifier_allowed(), true);
16-
assert_eq!(IdentifierStatusChar::identifier_allowed('0'), true);
16+
assert_eq!(GeneralSecurityProfile::identifier_allowed('0'), true);
1717
assert_eq!('0'.identifier_allowed(), true);
18-
assert_eq!(IdentifierStatusChar::identifier_allowed('_'), true);
18+
assert_eq!(GeneralSecurityProfile::identifier_allowed('_'), true);
1919
assert_eq!('_'.identifier_allowed(), true);
20-
assert_eq!(IdentifierStatusChar::identifier_allowed('\x00'), false);
20+
assert_eq!(GeneralSecurityProfile::identifier_allowed('\x00'), false);
2121
assert_eq!('\x00'.identifier_allowed(), false);
2222
// U+00B5 MICRO SIGN
23-
assert_eq!(IdentifierStatusChar::identifier_allowed('µ'), false);
23+
assert_eq!(GeneralSecurityProfile::identifier_allowed('µ'), false);
2424
assert_eq!('µ'.identifier_allowed(), false);
2525
// U+2160 ROMAN NUMERAL ONE
26-
assert_eq!(IdentifierStatusChar::identifier_allowed('Ⅰ'), false);
26+
assert_eq!(GeneralSecurityProfile::identifier_allowed('Ⅰ'), false);
2727
assert_eq!('Ⅰ'.identifier_allowed(), false);
2828
}

0 commit comments

Comments
 (0)