Skip to content

Commit ca0a10f

Browse files
committed
v2.0: Track position where normalization failed, bump MSRV, edition 2021
1 parent ec98c83 commit ca0a10f

File tree

8 files changed

+189
-146
lines changed

8 files changed

+189
-146
lines changed

.travis.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

Cargo.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22

33
name = "unicode-normalization"
4-
version = "0.1.24"
4+
version = "0.2.0"
55
authors = [
66
"kwantam <[email protected]>",
77
"Manish Goregaokar <[email protected]>",
@@ -27,17 +27,16 @@ Decomposition and Recomposition, as described in
2727
Unicode Standard Annex #15.
2828
"""
2929

30-
rust-version = "1.36"
30+
rust-version = "1.84"
3131

32-
edition = "2018"
32+
edition = "2021"
3333

3434
exclude = ["target/*", "Cargo.lock", "scripts/tmp", "*.txt", "tests/*"]
3535

3636
[dependencies.tinyvec]
3737
version = "1"
3838
features = ["alloc"]
3939

40-
4140
[features]
4241
default = ["std"]
4342
std = []

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
# unicode-normalization
22

3-
[![Build Status](https://travis-ci.org/unicode-rs/unicode-normalization.svg)](https://travis-ci.org/unicode-rs/unicode-normalization)
43
[![Docs](https://docs.rs/unicode-normalization/badge.svg)](https://docs.rs/unicode-normalization/)
54

65
Unicode character composition and decomposition utilities
76
as described in
87
[Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/).
98

10-
This crate requires Rust 1.36+.
9+
This crate requires Rust 1.84+.
1110

1211
```rust
1312
extern crate unicode_normalization;
@@ -31,21 +30,9 @@ to your `Cargo.toml`:
3130

3231
```toml
3332
[dependencies]
34-
unicode-normalization = "0.1.24"
33+
unicode-normalization = "0.2.0"
3534
```
3635

3736
## `no_std` + `alloc` support
3837

3938
This crate is completely `no_std` + `alloc` compatible. This can be enabled by disabling the `std` feature, i.e. specifying `default-features = false` for this crate on your `Cargo.toml`.
40-
41-
## Note about MSRV
42-
43-
Dependencies' MSRVs evolve independently of this crate's MSRV.
44-
Old versions of cargo will always try to get the most recent versions of the dependencies.
45-
Therefore, if you are having troubles compiling on an old Rust version, try to install an older version of the incompatible dependency.
46-
47-
For instance, to compile on Rust 1.36, `tinyvec` must be `<=1.6.0`
48-
49-
```sh
50-
cargo update -p tinyvec --precise 1.6.0
51-
```

fuzz/fuzz_targets/unicode-normalization.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,66 @@
44
extern crate libfuzzer_sys;
55

66
use unicode_normalization::{
7-
is_nfc, is_nfc_quick, is_nfc_stream_safe, is_nfc_stream_safe_quick, is_nfd, is_nfd_quick,
8-
is_nfd_stream_safe, is_nfd_stream_safe_quick, is_nfkc, is_nfkc_quick, is_nfkd, is_nfkd_quick,
9-
IsNormalized, UnicodeNormalization,
7+
check_nfc_quick, check_nfc_stream_safe_quick, check_nfd_quick, check_nfd_stream_safe_quick,
8+
check_nfkc_quick, check_nfkd_quick, is_nfc, is_nfc_stream_safe, is_nfd, is_nfd_stream_safe,
9+
is_nfkc, is_nfkd, UnicodeNormalization,
1010
};
1111

12-
fn from_bool(is_normalized: bool) -> IsNormalized {
13-
if is_normalized {
14-
IsNormalized::Yes
15-
} else {
16-
IsNormalized::No
17-
}
18-
}
19-
2012
fuzz_target!(|input: String| {
2113
// The full predicates imply the quick predicates.
22-
assert_ne!(is_nfc_quick(input.chars()), from_bool(!is_nfc(&input)));
23-
assert_ne!(is_nfd_quick(input.chars()), from_bool(!is_nfd(&input)));
24-
assert_ne!(is_nfkc_quick(input.chars()), from_bool(!is_nfkc(&input)));
25-
assert_ne!(is_nfkd_quick(input.chars()), from_bool(!is_nfkd(&input)));
26-
assert_ne!(
27-
is_nfc_stream_safe_quick(input.chars()),
28-
from_bool(!is_nfc_stream_safe(&input))
14+
assert_eq!(check_nfc_quick(&input).is_ok(), is_nfc(&input));
15+
assert_eq!(check_nfd_quick(&input).is_ok(), is_nfd(&input));
16+
assert_eq!(check_nfkc_quick(&input).is_ok(), is_nfkc(&input));
17+
assert_eq!(check_nfkd_quick(&input).is_ok(), is_nfkd(&input));
18+
assert_eq!(
19+
check_nfc_stream_safe_quick(&input).is_ok(),
20+
is_nfc_stream_safe(&input)
2921
);
30-
assert_ne!(
31-
is_nfd_stream_safe_quick(input.chars()),
32-
from_bool(!is_nfd_stream_safe(&input))
22+
assert_eq!(
23+
check_nfd_stream_safe_quick(&input).is_ok(),
24+
is_nfd_stream_safe(&input)
3325
);
3426

3527
// Check NFC, NFD, NFKC, and NFKD normalization.
36-
let nfc = input.chars().nfc().collect::<String>();
28+
let nfc = input.nfc().collect::<String>();
3729
assert_eq!(nfc.is_empty(), input.is_empty());
38-
assert_ne!(is_nfc_quick(nfc.chars()), IsNormalized::No);
30+
assert!(check_nfc_quick(&nfc).is_ok());
3931
assert!(is_nfc(&nfc));
4032

41-
let nfd = input.chars().nfd().collect::<String>();
33+
let nfd = input.nfd().collect::<String>();
4234
assert!(nfd.len() >= nfc.len());
43-
assert_ne!(is_nfd_quick(nfd.chars()), IsNormalized::No);
35+
assert!(check_nfd_quick(&nfd).is_ok());
4436
assert!(is_nfd(&nfd));
4537

46-
let nfkc = input.chars().nfkc().collect::<String>();
38+
let nfkc = input.nfkc().collect::<String>();
4739
assert_eq!(nfkc.is_empty(), input.is_empty());
48-
assert_ne!(is_nfkc_quick(nfkc.chars()), IsNormalized::No);
40+
assert!(check_nfkc_quick(&nfkc).is_ok());
4941
assert!(is_nfkc(&nfkc));
5042

51-
let nfkd = input.chars().nfkd().collect::<String>();
43+
let nfkd = input.nfkd().collect::<String>();
5244
assert!(nfkd.len() >= nfkc.len());
53-
assert_ne!(is_nfkd_quick(nfkd.chars()), IsNormalized::No);
45+
assert!(check_nfkd_quick(&nfkd).is_ok());
5446
assert!(is_nfkd(&nfkd));
5547

5648
// Check stream-safe.
57-
let nfc_ss = nfc.chars().stream_safe().collect::<String>();
49+
let nfc_ss = nfc.stream_safe().collect::<String>();
5850
assert!(nfc_ss.len() >= nfc.len());
59-
assert_ne!(is_nfc_stream_safe_quick(nfc_ss.chars()), IsNormalized::No);
51+
assert!(check_nfc_stream_safe_quick(&nfc_ss).is_ok());
6052
assert!(is_nfc_stream_safe(&nfc_ss));
6153

62-
let nfd_ss = nfd.chars().stream_safe().collect::<String>();
54+
let nfd_ss = nfd.stream_safe().collect::<String>();
6355
assert!(nfd_ss.len() >= nfd.len());
64-
assert_ne!(is_nfd_stream_safe_quick(nfd_ss.chars()), IsNormalized::No);
56+
assert!(check_nfd_stream_safe_quick(&nfd_ss).is_ok());
6557
assert!(is_nfd_stream_safe(&nfd_ss));
6658

6759
// Check that NFC and NFD preserve stream-safe.
68-
let ss_nfc = input.chars().stream_safe().nfc().collect::<String>();
60+
let ss_nfc = input.stream_safe().nfc().collect::<String>();
6961
assert_eq!(ss_nfc.is_empty(), input.is_empty());
70-
assert_ne!(is_nfc_stream_safe_quick(ss_nfc.chars()), IsNormalized::No);
62+
assert!(check_nfc_stream_safe_quick(&ss_nfc).is_ok());
7163
assert!(is_nfc_stream_safe(&ss_nfc));
7264

73-
let ss_nfd = input.chars().stream_safe().nfd().collect::<String>();
65+
let ss_nfd = input.stream_safe().nfd().collect::<String>();
7466
assert_eq!(ss_nfd.is_empty(), input.is_empty());
75-
assert_ne!(is_nfd_stream_safe_quick(ss_nfd.chars()), IsNormalized::No);
67+
assert!(check_nfd_stream_safe_quick(&ss_nfd).is_ok());
7668
assert!(is_nfd_stream_safe(&ss_nfd));
7769
});

scripts/unicode.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,8 @@ def gen_public_assigned(general_category_public_assigned, out):
463463
# This could be done as a hash but the table is somewhat small.
464464
out.write("#[inline]\n")
465465
out.write("pub fn is_public_assigned(c: char) -> bool {\n")
466-
out.write(" match c {\n")
466+
out.write(" matches!(\n")
467+
out.write(" c,\n")
467468

468469
start = True
469470
for first, last in general_category_public_assigned:
@@ -476,10 +477,9 @@ def gen_public_assigned(general_category_public_assigned, out):
476477
out.write("'\\u{%s}'" % hexify(first))
477478
else:
478479
out.write("'\\u{%s}'..='\\u{%s}'" % (hexify(first), hexify(last)))
479-
out.write(" => true,\n")
480+
out.write(",\n")
480481

481-
out.write(" _ => false,\n")
482-
out.write(" }\n")
482+
out.write(" )\n")
483483
out.write("}\n")
484484

485485
def gen_stream_safe(leading, trailing, out):

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//!
3535
//! ```toml
3636
//! [dependencies]
37-
//! unicode-normalization = "0.1.20"
37+
#![doc = concat!("unicode-normalization = \"", env!("CARGO_PKG_VERSION"), "\"")]
3838
//! ```
3939
4040
#![deny(missing_docs, unsafe_code)]
@@ -54,9 +54,10 @@ extern crate tinyvec;
5454

5555
pub use crate::decompose::Decompositions;
5656
pub use crate::quick_check::{
57-
is_nfc, is_nfc_quick, is_nfc_stream_safe, is_nfc_stream_safe_quick, is_nfd, is_nfd_quick,
58-
is_nfd_stream_safe, is_nfd_stream_safe_quick, is_nfkc, is_nfkc_quick, is_nfkd, is_nfkd_quick,
59-
IsNormalized,
57+
check_nfc, check_nfc_quick, check_nfc_stream_safe, check_nfc_stream_safe_quick, check_nfd,
58+
check_nfd_quick, check_nfd_stream_safe, check_nfd_stream_safe_quick, check_nfkc,
59+
check_nfkc_quick, check_nfkd, check_nfkd_quick, is_nfc, is_nfc_stream_safe, is_nfd,
60+
is_nfd_stream_safe, is_nfkc, is_nfkd, NormalizationError, QuickCheck,
6061
};
6162
pub use crate::recompose::Recompositions;
6263
pub use crate::replace::Replacements;

0 commit comments

Comments
 (0)