Skip to content

Commit 2ac1251

Browse files
committed
Add Unknown script
1 parent 7fb4c49 commit 2ac1251

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

scripts/unicode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,8 @@ def emit_enums(f, script_list, extension_list, longforms):
194194
#[allow(non_camel_case_types)]
195195
/// A value of the Script property
196196
pub enum Script {
197+
/// Unknown script
198+
Unknown,
197199
""")
198200
for script in script_list:
199201
f.write(" /// %s\n %s,\n" % (script, longforms[script]))
@@ -233,6 +235,7 @@ def emit_enums(f, script_list, extension_list, longforms):
233235
impl Script {
234236
pub(crate) fn inner_full_name(self) -> &'static str {
235237
match self {
238+
Script::Unknown => "Unknown",
236239
""")
237240
for script in script_list:
238241
f.write(" Script::%s => \"%s\",\n" % (longforms[script], longforms[script]))
@@ -241,6 +244,7 @@ def emit_enums(f, script_list, extension_list, longforms):
241244
242245
pub(crate) fn inner_short_name(self) -> &'static str {
243246
match self {
247+
Script::Unknown => "",
244248
""")
245249
for script in script_list:
246250
f.write(" Script::%s => \"%s\",\n" % (longforms[script], script))
@@ -276,6 +280,8 @@ def emit_enums(f, script_list, extension_list, longforms):
276280
#[inline]
277281
pub(crate) fn inner_intersects(self, other: Self) -> bool {
278282
match (self, other) {
283+
(ScriptExtension::Single(Script::Unknown), _) |
284+
(_, ScriptExtension::Single(Script::Unknown)) => false,
279285
(a, b) if a == b => true,
280286
(ScriptExtension::Single(Script::Common), _) |
281287
(ScriptExtension::Single(Script::Inherited), _) |

src/lib.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,10 @@ impl ScriptExtension {
3737
/// Check if this ScriptExtension has any intersection with another
3838
/// ScriptExtension
3939
///
40-
/// "Common" (`Zyyy`) and "Inherited" (Zinh`) are considered as intersecting
40+
/// "Common" (`Zyyy`) and "Inherited" (`Zinh`) are considered as intersecting
4141
/// everything.
42+
///
43+
/// "Unknown" intersects nothing
4244
pub fn intersects(self, other: Self) -> bool {
4345
self.inner_intersects(other)
4446
}
@@ -47,17 +49,17 @@ impl ScriptExtension {
4749
/// Extension trait on `char` for calculating script properties
4850
pub trait UnicodeScript {
4951
/// Get the script for a given character
50-
fn script(&self) -> Option<Script>;
52+
fn script(&self) -> Script;
5153
/// Get the Script_Extension for a given character
52-
fn script_extension(&self) -> Option<ScriptExtension>;
54+
fn script_extension(&self) -> ScriptExtension;
5355
}
5456

5557
impl UnicodeScript for char {
56-
fn script(&self) -> Option<Script> {
57-
get_script(*self)
58+
fn script(&self) -> Script {
59+
get_script(*self).unwrap_or(Script::Unknown)
5860
}
5961

60-
fn script_extension(&self) -> Option<ScriptExtension> {
61-
get_script_extension(*self).or_else(|| self.script().map(ScriptExtension::Single))
62+
fn script_extension(&self) -> ScriptExtension {
63+
get_script_extension(*self).unwrap_or_else(|| ScriptExtension::Single(self.script()))
6264
}
6365
}

src/tables.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ use core::convert::TryFrom;
2222
#[allow(non_camel_case_types)]
2323
/// A value of the Script property
2424
pub enum Script {
25+
/// Unknown script
26+
Unknown,
2527
/// Tang
2628
Tangut,
2729
/// Thaa
@@ -454,6 +456,7 @@ impl TryFrom<ScriptExtension> for Script {
454456
impl Script {
455457
pub(crate) fn inner_full_name(self) -> &'static str {
456458
match self {
459+
Script::Unknown => "Unknown",
457460
Script::Tangut => "Tangut",
458461
Script::Thaana => "Thaana",
459462
Script::Adlam => "Adlam",
@@ -611,6 +614,7 @@ impl Script {
611614

612615
pub(crate) fn inner_short_name(self) -> &'static str {
613616
match self {
617+
Script::Unknown => "",
614618
Script::Tangut => "Tang",
615619
Script::Thaana => "Thaa",
616620
Script::Adlam => "Adlm",
@@ -883,6 +887,8 @@ impl ScriptExtension {
883887
#[inline]
884888
pub(crate) fn inner_intersects(self, other: Self) -> bool {
885889
match (self, other) {
890+
(ScriptExtension::Single(Script::Unknown), _) |
891+
(_, ScriptExtension::Single(Script::Unknown)) => false,
886892
(a, b) if a == b => true,
887893
(ScriptExtension::Single(Script::Common), _) |
888894
(ScriptExtension::Single(Script::Inherited), _) |

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy