Skip to content

Commit cbfd7bd

Browse files
committed
Add methods for obtaining the scriptext of a string
1 parent bef685b commit cbfd7bd

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/lib.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ impl Script {
3535
}
3636
}
3737

38+
impl Default for Script {
39+
fn default() -> Self {
40+
Script::Common
41+
}
42+
}
43+
3844
impl From<char> for Script {
3945
fn from(o: char) -> Self {
4046
o.script()
@@ -76,6 +82,20 @@ impl ScriptExtension {
7682
pub fn is_empty(self) -> bool {
7783
self == ScriptExtension::Single(Script::Unknown)
7884
}
85+
86+
pub fn for_str(x: &str) -> Self {
87+
let mut ext = ScriptExtension::default();
88+
for ch in x.chars() {
89+
ext.intersect_with(ch.into());
90+
}
91+
ext
92+
}
93+
}
94+
95+
impl Default for ScriptExtension {
96+
fn default() -> Self {
97+
ScriptExtension::Single(Script::Common)
98+
}
7999
}
80100

81101
impl From<char> for ScriptExtension {
@@ -84,6 +104,12 @@ impl From<char> for ScriptExtension {
84104
}
85105
}
86106

107+
impl From<&'_ str> for ScriptExtension {
108+
fn from(o: &'_ str) -> Self {
109+
Self::for_str(o)
110+
}
111+
}
112+
87113
/// Extension trait on `char` for calculating script properties
88114
pub trait UnicodeScript {
89115
/// Get the script for a given character

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