Skip to content

Upgrade to unicode-script 0.5.0 #18

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ according to Unicode Technical Standard #39 rules.
exclude = [ "target/*", "Cargo.lock" ]

[dependencies]
unicode-script = { version = "0.4.0", default-features = false }
unicode-script = { version = "0.5.0", default-features = false }
unicode-normalization = { version = "0.1.12", default-features = false }
std = { version = "1.0", package = "rustc-std-workspace-std", optional = true }
core = { version = "1.0", package = "rustc-std-workspace-core", optional = true }
Expand Down
10 changes: 3 additions & 7 deletions src/mixed_script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ impl From<ScriptExtension> for AugmentedScriptSet {
let mut jpan = false;
let mut kore = false;

if ext == ScriptExtension::Single(Script::Common)
|| ext == ScriptExtension::Single(Script::Inherited)
|| ext.contains_script(Script::Han)
{
if ext.is_common() || ext.is_inherited() || ext.contains_script(Script::Han) {
hanb = true;
jpan = true;
kore = true;
Expand Down Expand Up @@ -67,7 +64,7 @@ impl From<&'_ str> for AugmentedScriptSet {
impl Default for AugmentedScriptSet {
fn default() -> Self {
AugmentedScriptSet {
base: ScriptExtension::Single(Script::Common),
base: ScriptExtension::from(Script::Common),
hanb: true,
jpan: true,
kore: true,
Expand All @@ -91,8 +88,7 @@ impl AugmentedScriptSet {

/// Check if the set is "All" (Common or Inherited)
pub fn is_all(&self) -> bool {
self.base == ScriptExtension::Single(Script::Common)
|| self.base == ScriptExtension::Single(Script::Inherited)
self.base.is_common() || self.base.is_inherited()
}

/// Construct an AugmentedScriptSet for a given character
Expand Down
12 changes: 10 additions & 2 deletions src/restriction_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use crate::mixed_script::AugmentedScriptSet;
use crate::GeneralSecurityProfile;
use unicode_script::{Script, ScriptExtension};
use unicode_script::Script;

#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
/// The [Restriction level](https://www.unicode.org/reports/tr39/#Restriction_Level_Detection)
Expand Down Expand Up @@ -58,13 +58,21 @@ impl RestrictionLevelDetection for &'_ str {
}
}

fn single_item<I: Iterator>(mut iter: I) -> Option<I::Item> {
let first_item = iter.next()?;
if iter.next().is_some() {
return None;
}
Some(first_item)
}

if ascii_only {
return RestrictionLevel::ASCIIOnly;
} else if !set.is_empty() {
return RestrictionLevel::SingleScript;
} else if exclude_latin_set.kore || exclude_latin_set.hanb || exclude_latin_set.jpan {
return RestrictionLevel::HighlyRestrictive;
} else if let ScriptExtension::Single(script) = exclude_latin_set.base {
} else if let Some(script) = single_item(exclude_latin_set.base.iter()) {
if script.is_recommended() && script != Script::Cyrillic && script != Script::Greek {
return RestrictionLevel::ModeratelyRestrictive;
}
Expand Down