├── .gitignore ├── .travis.yml ├── Cargo.toml ├── LICENSE ├── LICENSE-UCD ├── README.md ├── data ├── LICENSE ├── blocks.py ├── gen_bidi.py ├── gen_bool.py ├── gen_decomp.py ├── gen_func.py ├── gen_general.py ├── gen_misc.py ├── gen_rem.py ├── gen_scripts.py ├── gen_tests.py ├── generate.py ├── generate.sh ├── misc.py ├── process.py └── ucd.xml.xz ├── prepare.sh ├── src ├── lib.rs └── tables │ ├── LICENSE-UCD │ ├── bidi.rs │ ├── bool.rs │ ├── decomp.rs │ ├── function.rs │ ├── general.rs │ ├── misc.rs │ ├── mod.rs │ ├── rem.rs │ └── scripts.rs └── tests ├── data.tar.xz └── lib.rs /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | Cargo.lock 3 | *.swp 4 | __pycache__ 5 | .DS_Store 6 | tests/data/* 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | script: 3 | - ./prepare.sh 4 | - cargo build --release --verbose 5 | - cargo test --release --verbose 6 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "ucd" 3 | version = "0.1.1" 4 | authors = ["sourtin "] 5 | 6 | homepage = "https://github.com/sourtin/libucd" 7 | repository = "https://github.com/sourtin/libucd" 8 | license = "MIT" 9 | keywords = ["text", "unicode", "ucd", "character"] 10 | readme = "README.md" 11 | description = """ 12 | Extends the char type to provide access to most fields of the UCD, Unicode 13 | Character Database, as of version 9.0.0. It aims to be compact, fast, and use 14 | minimal dependencies (only rust's core crate). Not all properties are included, 15 | most notably character names. 16 | """ 17 | 18 | exclude = ["tests/*", "data/*"] 19 | 20 | [dependencies] 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 William Earley 2 | 3 | Permission is hereby granted, free of charge, to any 4 | person obtaining a copy of this software and associated 5 | documentation files (the "Software"), to deal in the 6 | Software without restriction, including without 7 | limitation the rights to use, copy, modify, merge, 8 | publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software 10 | is furnished to do so, subject to the following 11 | conditions: 12 | 13 | The above copyright notice and this permission notice 14 | shall be included in all copies or substantial portions 15 | of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 18 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 19 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 20 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 21 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 22 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 23 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 24 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /LICENSE-UCD: -------------------------------------------------------------------------------- 1 | COPYRIGHT AND PERMISSION NOTICE 2 | 3 | Copyright © 1991-2016 Unicode, Inc. All rights reserved. 4 | Distributed under the Terms of Use in 5 | http://www.unicode.org/copyright.html. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining 8 | a copy of the Unicode data files and any associated documentation 9 | (the "Data Files") or Unicode software and any associated documentation 10 | (the "Software") to deal in the Data Files or Software 11 | without restriction, including without limitation the rights to use, 12 | copy, modify, merge, publish, distribute, and/or sell copies of 13 | the Data Files or Software, and to permit persons to whom the Data Files 14 | or Software are furnished to do so, provided that 15 | (a) this copyright and permission notice appear with all copies 16 | of the Data Files or Software, 17 | (b) this copyright and permission notice appear in associated 18 | documentation, and 19 | (c) there is clear notice in each modified Data File or in the Software 20 | as well as in the documentation associated with the Data File(s) or 21 | Software that the data or software has been modified. 22 | 23 | THE DATA FILES AND SOFTWARE ARE PROVIDED "AS IS", WITHOUT WARRANTY OF 24 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 25 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 | NONINFRINGEMENT OF THIRD PARTY RIGHTS. 27 | IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS 28 | NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL 29 | DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 30 | DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 31 | TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 32 | PERFORMANCE OF THE DATA FILES OR SOFTWARE. 33 | 34 | Except as contained in this notice, the name of a copyright holder 35 | shall not be used in advertising or otherwise to promote the sale, 36 | use or other dealings in these Data Files or Software without prior 37 | written authorization of the copyright holder. 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # `libucd` 2 | 3 | [![Build Status](https://travis-ci.org/sourtin/libucd.svg?branch=master)](https://travis-ci.org/sourtin/libucd) 4 | [![crates.io](http://meritbadge.herokuapp.com/ucd)](https://crates.io/crates/ucd) 5 | 6 | This library extends the inbuilt `char` type with the `Codepoint` trait, which implements 100 properties of the UCD (Unicode Character Database). It aims to be fast and compact, and to have minimal dependencies (it does not require the rust standard library so only needs rust's `core` crate). 7 | 8 | ```rust 9 | extern crate ucd; 10 | use ucd::Codepoint; 11 | 12 | fn main() { 13 | let salawat: char = 'ﷺ'; 14 | let decomp: String = salawat.decomposition_map().collect(); 15 | println!("{} -> {}", salawat, decomp); 16 | // ﷺ -> صلى الله عليه وسلم 17 | } 18 | ``` 19 | 20 | Though the library is fairly extensive, it is not complete. The properties it lacks are: 21 | 22 | * Character [names](https://github.com/huonw/unicode_names) and aliases 23 | * Unihan properties 24 | * Tangut source data 25 | * Named sequences 26 | * Standardised variants 27 | * CJK Radicals 28 | * Emoji source data 29 | 30 | Data was compressed as arrays of ranges of codepoints having each value for each property, excluding the most common value. Lookup is then implemented by a binary search which should provide O(1) access. A very unscientific test suggests each lookup takes around 100ns on a core i5 processor. 31 | 32 | ## Disclaimer 33 | 34 | Please note that this data has been derived from the flat XML version of the UCD. Though this is published by Unicode, it is not the official version of the database. As such, it cannot be guaranteed that this library is entirely consistent with the official database. The unit tests do however suggest consistency with the XML database at least. 35 | 36 | ## Reference 37 | 38 | _Note, in most cases enum values are simply the full name of the property value converted to camelcase. Perhaps I will eventually create a rustdoc version that will be more helpful._ 39 | 40 | In the tables below, the first column is the name of the property, and the second column is the method name. The methods are implemented via the `ucd::Codepoint` trait on `char`. 41 | 42 | | General | Method | Return Type | Note | 43 | | ---- | --- | --- | --- | 44 | | Age | `age` | `Option<(u8,u8)>` | Return `None` if the character is unassigned, else a tuple of major and minor age | 45 | | Block | `block` | `Option` | | 46 | | General_Category | `category` | `UnicodeCategory` | Return `Unassigned` if unassigned | 47 | | ISO_Comment (deprecated, stabilized) | `iso_comment` | `&str` | All characters are null, i.e. `""` is returned | 48 | 49 | | Function and Appearance | Method | Return Type | Note | 50 | | ---- | --- | --- | --- | 51 | | Alphabetic | `Codepoint::is_alphabetic` or `is_alpha` | `bool` | Rust's `char` already defines a method `is_alphabetic` which shadows this implementation and provides slightly different results (possibly by using an outdated version of the UCD). Use the namespace, or the `is_alpha` alias instead. | 52 | | ASCII_Hex_Digit | `is_hex_digit_ascii` | `bool` | | 53 | | Dash | `is_dash` | `bool` | | 54 | | Default_Ignorable_Code_Point | `is_default_ignorable` | `bool` | | 55 | | Deprecated | `is_deprecated` | `bool` | | 56 | | Diacritic | `is_diacritic` | `bool` | | 57 | | Extender | `is_extender` | `bool` | | 58 | | Hex_Digit | `is_hex_digit` | `bool` | | 59 | | Hyphen _(deprecated, stabilized)_ | `is_hyphen` | `bool` | | 60 | | Logical_Order_Exception | `is_logical_order_exception` | `bool` | | 61 | | Math | `is_math` | `bool` | | 62 | | Noncharacter_Code_Point | `is_noncharacter` | `bool` | | 63 | | Other_Alphabetic | `is_alphabetic_other` | `bool` | | 64 | | Other_Default_Ignorable_Code_Point | `is_default_ignorable_other` | `bool` | | 65 | | Other_Math | `is_math_other` | `bool` | | 66 | | Prepended_Concatenation_Mark | `is_prepended_concatentation_mark` | `bool` | | 67 | | Quotation_Mark | `is_quotation_mark` | `bool` | | 68 | | Sentence_Terminal | `is_sentence_terminal` | `bool` | | 69 | | Soft_Dotted | `is_soft_dotted` | `bool` | | 70 | | Terminal_Punctuation | `is_terminal_punctuation` | `bool` | | 71 | | Variation_Selector | `is_variation_selector` | `bool` | | 72 | | White_Space | `Codepoint::is_whitespace` or `is_white` | `bool` | Again, `char` shadows this with its own implementation so use the namespace or alias. | 73 | 74 | | Numeric | Method | Return Type | Note | 75 | | ---- | --- | --- | --- | 76 | | Numeric_Type | `numeric_type` | `Option` | | 77 | | Numeric_Value | `numeric_value` | `Option` | The `Number` type is an enum of `Integer(i64)` and `Rational(i32,u32)`, to cover values as large as 10^12 and as small as 1/160. | 78 | 79 | | Identifiers and Syntax | Method | Return Type | Note | 80 | | ---- | --- | --- | --- | 81 | | ID_Continue | `is_id_continue` | `bool` | | 82 | | ID_Start | `is_id_start` | `bool` | | 83 | | Other_ID_Continue | `is_id_continue_other` | `bool` | | 84 | | Other_ID_Start | `is_id_start_other` | `bool` | | 85 | | Pattern_Syntax | `is_pattern_syntax` | `bool` | | 86 | | Pattern_White_Space | `is_pattern_whitespace` | `bool` | | 87 | | XID_Continue | `is_id_continue_nfkc` | `bool` | | 88 | | XID_Start | `is_id_start_nfkc` | `bool` | | 89 | 90 | | Scripts | Method | Return Type | Note | 91 | | ---- | --- | --- | --- | 92 | | East_Asian_Width | `east_asian_width` | `EastAsianWidth` | | 93 | | Hangul_Syllable_Type | `hangul_syllable_type` | `Option` | | 94 | | Ideographic | `is_ideograph` | `bool` | | 95 | | IDS_Binary_Operator | `is_ideograph_description_sequence_binary_operator` | `bool` | | 96 | | IDS_Trinary_Operator | `is_ideograph_description_sequence_trinary_operator` | `bool` | | 97 | | Indic_Positional_Category | `indic_positional_category` | `Option` | | 98 | | Indic_Syllabic_Category | `indic_syllabic_category` | `Option` | | 99 | | Jamo_Short_Name | `jamo_short_name` | `Option<&str>` | | 100 | | Join_Control | `join_control` | `bool` | | 101 | | Joining_Group | `joining_group` | `JoiningGroup` | | 102 | | Joining_Type | `joining_type` | `JoiningType` | | 103 | | Radical | `is_ideograph_description_sequence_radical` | `bool` | | 104 | | Script | `script` | `Option