Looks up a Unicode class given a query. If one doesn't exist, then `None` is returned.
(query: ClassQuery<'a>)
| 209 | /// Looks up a Unicode class given a query. If one doesn't exist, then |
| 210 | /// `None` is returned. |
| 211 | pub fn class<'a>(query: ClassQuery<'a>) -> Result<hir::ClassUnicode> { |
| 212 | use self::CanonicalClassQuery::*; |
| 213 | |
| 214 | match query.canonicalize()? { |
| 215 | Binary(name) => { |
| 216 | property_set(property_bool::BY_NAME, name) |
| 217 | .map(hir_class) |
| 218 | .ok_or(Error::PropertyNotFound) |
| 219 | } |
| 220 | GeneralCategory("Any") => { |
| 221 | Ok(hir_class(&[('\0', '\u{10FFFF}')])) |
| 222 | } |
| 223 | GeneralCategory("Assigned") => { |
| 224 | let mut cls = |
| 225 | property_set(general_category::BY_NAME, "Unassigned") |
| 226 | .map(hir_class) |
| 227 | .ok_or(Error::PropertyNotFound)?; |
| 228 | cls.negate(); |
| 229 | Ok(cls) |
| 230 | } |
| 231 | GeneralCategory("ASCII") => { |
| 232 | Ok(hir_class(&[('\0', '\x7F')])) |
| 233 | } |
| 234 | GeneralCategory(name) => { |
| 235 | property_set(general_category::BY_NAME, name) |
| 236 | .map(hir_class) |
| 237 | .ok_or(Error::PropertyValueNotFound) |
| 238 | } |
| 239 | Script(name) => { |
| 240 | property_set(script::BY_NAME, name) |
| 241 | .map(hir_class) |
| 242 | .ok_or(Error::PropertyValueNotFound) |
| 243 | } |
| 244 | ByValue { property_name: "Age", property_value } => { |
| 245 | let mut class = hir::ClassUnicode::empty(); |
| 246 | for set in ages(property_value)? { |
| 247 | class.union(&hir_class(set)); |
| 248 | } |
| 249 | Ok(class) |
| 250 | } |
| 251 | ByValue { property_name: "Script_Extensions", property_value } => { |
| 252 | property_set(script_extension::BY_NAME, property_value) |
| 253 | .map(hir_class) |
| 254 | .ok_or(Error::PropertyValueNotFound) |
| 255 | } |
| 256 | ByValue { property_name: "Grapheme_Cluster_Break", property_value } => { |
| 257 | property_set(grapheme_cluster_break::BY_NAME, property_value) |
| 258 | .map(hir_class) |
| 259 | .ok_or(Error::PropertyValueNotFound) |
| 260 | } |
| 261 | ByValue { property_name: "Sentence_Break", property_value } => { |
| 262 | property_set(sentence_break::BY_NAME, property_value) |
| 263 | .map(hir_class) |
| 264 | .ok_or(Error::PropertyValueNotFound) |
| 265 | } |
| 266 | ByValue { property_name: "Word_Break", property_value } => { |
| 267 | property_set(word_break::BY_NAME, property_value) |
| 268 | .map(hir_class) |
no test coverage detected