File tree 1 file changed +26
-0
lines changed 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,12 @@ impl Script {
35
35
}
36
36
}
37
37
38
+ impl Default for Script {
39
+ fn default ( ) -> Self {
40
+ Script :: Common
41
+ }
42
+ }
43
+
38
44
impl From < char > for Script {
39
45
fn from ( o : char ) -> Self {
40
46
o. script ( )
@@ -76,6 +82,20 @@ impl ScriptExtension {
76
82
pub fn is_empty ( self ) -> bool {
77
83
self == ScriptExtension :: Single ( Script :: Unknown )
78
84
}
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
+ }
79
99
}
80
100
81
101
impl From < char > for ScriptExtension {
@@ -84,6 +104,12 @@ impl From<char> for ScriptExtension {
84
104
}
85
105
}
86
106
107
+ impl From < & ' _ str > for ScriptExtension {
108
+ fn from ( o : & ' _ str ) -> Self {
109
+ Self :: for_str ( o)
110
+ }
111
+ }
112
+
87
113
/// Extension trait on `char` for calculating script properties
88
114
pub trait UnicodeScript {
89
115
/// Get the script for a given character
You can’t perform that action at this time.
0 commit comments