10000 Add public API · unicode-rs/unicode-script@6f36a50 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f36a50

Browse files
committed
Add public API
1 parent 8f21f95 commit 6f36a50

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

src/lib.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,55 @@
1+
#![cfg_attr(not(feature = "with_std"), no_std)]
2+
13
#[rustfmt::skip]
24
mod tables;
5+
6+
pub use tables::{Script, ScriptExtension, UNICODE_VERSION};
7+
8+
use tables::{get_script, get_script_extension};
9+
10+
impl Script {
11+
/// Get the full name of a script
12+
pub fn full_name(self) -> &'static str {
13+
self.inner_full_name()
14+
}
15+
}
16+
17+
impl ScriptExtension {
18+
/// Obtain the list of scripts contained inside this ScriptExtension
19+
#[cfg(feature = "with_std")]
20+
pub fn scripts(self) -> Vec<Script> {
21+
self.inner_scripts()
22+
}
23+
24+
/// Check if this ScriptExtension contains the given script
25+
pub fn contains_script(self, script: Script) -> bool {
26+
self.inner_contains_script(script)
27+
}
28+
29+
/// Check if this ScriptExtension has any intersection with another
30+
/// ScriptExtension
31+
///
32+
/// "Common" (`Zyyy`) and "Inherited" (Zinh`) are considered as intersecting
33+
/// everything.
34+
pub fn intersects(self, other: Self) -> bool {
35+
self.inner_intersects(other)
36+
}
37+
}
38+
39+
/// Extension trait on `char` for calculating script properties
40+
pub trait UnicodeScript {
41+
/// Get the script for a given character
42+
fn script(&self) -> Option<Script>;
43+
/// Get the Script_Extension for a given character
44+
fn script_extension(&self) -> Option<ScriptExtension>;
45+
}
46+
47+
impl UnicodeScript for char {
48+
fn script(&self) -> Option<Script> {
49+
get_script(*self)
50+
}
51+
52+
fn script_extension(&self) -> Option<ScriptExtension> {
53+
get_script_extension(*self).or_else(|| self.script().map(ScriptExtension::Single))
54+
}
55+
}

0 commit comments

Comments
 (0)
0