Commit Graph

79 Commits

Author SHA1 Message Date
Jacob Kiesel e9b2c4499e Fix #75, implement UnicodeNormalization for char 2021-10-07 14:46:14 -06:00
Dan Gohman a8892812df Publish 0.1.19 2021-06-01 15:31:35 -07:00
Dan Gohman 33e73008da Fix is_public_assigned to include Hangul Syllable and other ranges.
Hangul Syllables and several other ranges are defined in UnicodeData.txt
as just their first and last values:

```
AC00;<Hangul Syllable, First>;Lo;0;L;;;;;N;;;;;
D7A3;<Hangul Syllable, Last>;Lo;0;L;;;;;N;;;;;
```

Teach the unicode.py script how to recognize these, so that it correctly
classifies them as assigned ranges, for the `is_public_assigned`
predicate.
2021-06-01 14:42:29 -07:00
Dan Gohman 8f31969fc7 Publish 0.1.18 2021-05-28 10:50:58 -07:00
Dan Gohman aaa72a31da Add an is_public_assigned predicate.
Add an `is_public_assigned` predicate, which tests whether a given
`char` is assigned (`General_Category` != `Unassigned`) in the currently
supported version of Unicode, and not Private-Use (`General_Category`
!= `Private_Use`).

This comes up in some use cases sensitive to the stability of NFC over
Unicode version changes. An unassigned codepoint could become assigned in
the future, and new normalizations could apply to it.

For further details, see
 - <https://unicode.org/reports/tr15/#Versioning>
2021-05-28 09:13:34 -07:00
Dan Gohman dba17f95a2 Use ArrayVec to panic instead of resizing on overflow. 2021-01-06 09:54:32 -08:00
Dan Gohman 0083e1014e Rename svar to cjk_compat_variants. 2021-01-05 22:51:46 -08:00
Dan Gohman 052e6d7367 Avoid saying "non-standard" in a comment.
The standardized variations sequences are standardized, so don't imply
otherwise.
2021-01-04 07:35:50 -08:00
Dan Gohman 6b376dbea8 Don't decompose Hangul in the svar iterator. 2020-12-07 11:56:16 -08:00
Dan Gohman f362213cfb Switch to a more explicit API.
Switch to a dedicated `svar()` iterator function, which just does
standardized variation sequences, rather than framing this functionality
as an open-ended "extended" version of the standard normalization
algorithms. This makes for a more factored API, gives users more control
over exactly what transformations are done, and has less impact on users
that don't need this new functionality.
2020-12-06 08:26:50 -08:00
Dan Gohman 107879735b Add new normalization algorithms using Standardized Variants
The standard normalization algorithm decomposes CJK compatibility ideographs
into nominally equivalent codepoints, but which traditionally look different,
and is one of the main reasons normalization is considered destructive in
practice.

[Unicode 6.3] introduced a solution for this, by providing
[standardized variation sequences] for these codepoints. For example, while
U+2F8A6 "CJK COMPATIBILITY-IDEOGRAPH-2F8A6" canonically decomposes to U+6148
with a different appearance, in Unicode 6.3 and later the standardized variation
sequences in the StandardizedVariants.txt file include the following:

> 6148 FE00; CJK COMPATIBILITY IDEOGRAPH-2F8A6;

which says that "CJK COMPATIBILITY IDEOGRAPH-2F8A6" corresponds to
U+6148 U+FE00, where U+FE00 is "VARIATION SELECTOR-1".

U+6148 and U+FE00 are both normalized codepoints, so we can transform text
containing U+2F8A6 into normal form without losing information about the
distinct appearance. At this time, many popular implementations ignore these
variation selectors, however this technique at least preserves the information
in a standardized way, so implementations could use it if they chose.

This PR adds "ext" versions of the `nfd`, `nfc`, `nfkd`, and `nkfd`
iterators, which perform the standard algorithms extended with this technique.
They don't match the standard decompositions, and don't guarantee stability,
but they do produce appropriately normalized output.

I used the generic term "ext" to reflect that other extensions could
theoretically be added in the future. The standard decomposition tables are
limited by their stability requirements, but these "ext" versions could be
free to adopt new useful rules.

I'm not an expert in any of these topics, so please correct me if I'm mistaken
in any of this. Also, I'm open to ideas about how to best present this
functionality in the API.

[Unicode 6.3]: https://www.unicode.org/versions/Unicode6.3.0/#Summary
[standardized variation sequences]: http://unicode.org/faq/vs.html
2020-12-06 08:18:20 -08:00
Sujay Jayakar 8dfab5ee50 Remove dependency on format! in test_all_nonstarters 2020-11-30 15:21:35 -08:00
Sujay Jayakar e9210364d8 Update nonstarter_count correctly + add test for all nonstarters string 2020-11-30 15:21:35 -08:00
Manish Goregaokar 933ee7948f Merge pull request #64 from sunfishcode/sunfishcode/nfd-buffering
Make the decompose iterator avoid buffering elements past a starter.
2020-11-18 13:32:05 -08:00
Dan Gohman 49654fcb12 Make the decompose iterator avoid buffering elements past a starter.
Once the decompose iterator sees a starter, it should immediately start
returning characters from the preceeding sequence. If the input happens
to be stream-safe, it should never get more than MAX_NONSTARTERS + plus
boundary values ahead of its inner iterator.
2020-11-18 11:16:13 -08:00
Dan Gohman 43948859e4 Reset the stream-safe position when a starter is seen.
This avoids inserting too many CGJs.
2020-11-18 11:15:42 -08:00
Manish Goregaokar 4621ed6b98 Reset stream safe iterator to buffered character when outputting CGJ 2020-11-17 19:39:16 -08:00
Pyfisch bd1fcfbfab Update to Unicode 13
Change version fields to u8 as the maximum value
of each field is 255 according to specification.
2020-04-13 11:58:40 +02:00
Hannes Karppila 1d77ba2bc4 Add no_std + alloc support 2020-04-10 23:37:38 +03:00
Hannes Karppila ca0037583e Apply rustfmt 2020-04-10 23:37:34 +03:00
Hannes Karppila b098399338 Do not automatically format tables 2020-04-10 23:35:20 +03:00
Hannes Karppila 36184100f7 Remove ignored inline annotations 2020-04-10 23:35:19 +03:00
Hannes Karppila 0d6e296cc4 Migrate to Rust 2018 edition 2020-04-09 19:10:25 +03:00
Sergey "Shnatsel" Davidoff 432074711b Improve comment 2020-03-16 00:37:04 +01:00
Sergey "Shnatsel" Davidoff 09fdcc2b81 Switch from SmallVec to 100% safe TinyVec 2020-01-13 19:56:13 +01:00
Kent Fredric beab8d66a0 Move "normalization" test data and dependent tests all into tests/
Leaves all other tests in place.

Provides a #[doc(hidden)] shim for accessing/using otherwise private
members from tests/
2019-11-20 03:57:38 +13:00
Kamat, Trivikram e1c602752f Allows ellipsis_inclusive_range_patterns
Refs: https://github.com/unicode-rs/unicode-normalization/issues/41
2019-10-13 12:42:06 -07:00
Raph Levien a6db7c0256 Move lookups into own module 2019-04-16 10:56:44 -07:00
Raph Levien 9aacd59532 Move code out of tables
The code has been moved out of the tables module into perfect_hash, and
there is a bit more explanation in comments.
2019-04-16 10:42:11 -07:00
Raph Levien 93d8afb900 Use perfect hashing for compose lookup 2019-04-09 17:51:03 -07:00
Raph Levien df37994166 Use perfect hashing for decomposition also 2019-04-09 17:20:27 -07:00
Raph Levien b68dbec11f More lookups moved to perfect hashing 2019-04-09 16:46:28 -07:00
Raph Levien 274b267525 Use minimal perfect hashing for combining class lookup 2019-04-09 12:26:24 -07:00
Sujay Jayakar 35cc77d8ad Bump version to 0.1.8 2019-01-21 13:02:48 -08:00
Sujay Jayakar d9e05260c6 Merge branch 'master' into smallvec 2019-01-21 11:22:08 -08:00
David Judd b114982681 Add comment 2019-01-17 08:41:47 -08:00
David Judd c6524d31d4 Use fuse 2019-01-17 08:28:15 -08:00
David Judd cc81a58409 Revert "restore done field to Decompositions"
This reverts commit 099fef3b72.
2019-01-17 08:25:11 -08:00
David Judd 099fef3b72 restore done field to Decompositions 2019-01-15 21:31:18 -08:00
Sujay Jayakar e03d61cce8 Merge pull request #36 from djudd/compatibility-quick-checks
Add quick check implementations for NFKC & NFKD
2019-01-14 22:40:37 +05:30
David Judd 5685166427 Add quick check implementations for NFKC & NFKD 2019-01-12 14:44:53 -08:00
David Judd 70741bd31d Use SmallVec in place of VecDeque in recompose 2019-01-12 11:01:54 -08:00
David Judd 29e7a0ba40 Use SmallVec in place of Vec in decompose & avoid remove(0) 2019-01-12 11:01:22 -08:00
David Judd 79e9942f2a Add smallvec 2019-01-12 10:59:23 -08:00
Björn Steinbrink 41914c5d30 Generate code that is friendlier to rustc's item_bodies_checking
Having the Some() constructor in each match arm body puts extras stress
on rustc's item_bodies_checking pass. We can work around that by moving
the Some() constructor around the match, and directly returning None
from the default arm, which is the only one that generates a None value.

On my box, this almost cuts the time spent in item_bodies_checking in
half, going from about 8.7s to about 4.6s, and reduces the complete
compile time from about 13s to about 9s, so about a third less.

There are no changes in performance in `cargo bench`.

Note that doing the same for the composition_table() function does not
yield any compile time wins, but would cause a performance regression.

cc #29
2019-01-08 17:02:41 +01:00
Sujay Jayakar 7389eb31f1 Bump version (and update docs) 2018-05-09 12:39:23 -07:00
Sujay Jayakar ef9a4dd691 Implement Stream-Safe QuickCheck variant 2018-05-07 20:55:59 -07:00
Sujay Jayakar ef810e3380 Update range naming 2018-05-07 20:02:04 -07:00
Sujay Jayakar 3156992b87 Factor out T_START from match statement 2018-05-07 19:14:55 -07:00
Sujay Jayakar 9f6cc853cc Fix corner case in Hangul composition 2018-05-07 15:34:22 -07:00