8000 Apply rustfmt · unicode-rs/unicode-normalization@84ca78b · GitHub
[go: up one dir, main page]

Skip to content

Commit 84ca78b

Browse files
committed
Apply rustfmt
1 parent 1dbcb5f commit 84ca78b

File tree

12 files changed

+195
-153
lines changed

12 files changed

+195
-153
lines changed

benches/bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![feature(test)]
22
#![feature(iterator_step_by)]
3-
extern crate unicode_normalization;
43
extern crate test;
4+
extern crate unicode_normalization;
55

66
use std::fs;
77
use test::Bencher;

src/__test_api.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use crate::stream_safe::StreamSafe;
88
pub fn stream_safe(s: &str) -> String {
9-
StreamSafe::new(s.chars()).collect()
9+
StreamSafe::new(s.chars()).collect()
1010
}
1111
pub mod quick_check {
1212
pub use crate::quick_check::*;

src/decompose.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
use tinyvec::TinyVec;
1110
use std::fmt::{self, Write};
1211
use std::iter::Fuse;
1312
use std::ops::Range;
13+
use tinyvec::TinyVec;
1414

1515
#[derive(Clone)]
1616
enum DecompositionType {
@@ -37,7 +37,7 @@ pub struct Decompositions<I> {
3737
}
3838

3939
#[inline]
40-
pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
40+
pub fn new_canonical<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
4141
Decompositions {
4242
kind: self::DecompositionType::Canonical,
4343
iter: iter.fuse(),
@@ -47,7 +47,7 @@ pub fn new_canonical<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
4747
}
4848

4949
#[inline]
50-
pub fn new_compatible<I: Iterator<Item=char>>(iter: I) -> Decompositions<I> {
50+
pub fn new_compatible<I: Iterator<Item = char>>(iter: I) -> Decompositions<I> {
5151
Decompositions {
5252
kind: self::DecompositionType::Compatible,
5353
iter: iter.fuse(),
@@ -99,7 +99,7 @@ impl<I> Decompositions<I> {
9999
}
100100
}
101101

102-
impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
102+
impl<I: Iterator<Item = char>> Iterator for Decompositions<I> {
103103
type Item = char;
104104

105105
#[inline]
@@ -149,7 +149,7 @@ impl<I: Iterator<Item=char>> Iterator for Decompositions<I> {
149149
}
150150
}
151151

152-
impl<I: Iterator<Item=char> + Clone> fmt::Display for Decompositions<I> {
152+
impl<I: Iterator<Item = char> + Clone> fmt::Display for Decompositions<I> {
153153
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
154154
for c in self.clone() {
155155
f.write_char(c)?;

src/lib.rs

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,60 +38,51 @@
3838
//! ```
3939
4040
#![deny(missing_docs, unsafe_code)]
41-
#![doc(html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png",
42-
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png")]
41+
#![doc(
42+
html_logo_url = "https://unicode-rs.github.io/unicode-rs_sm.png",
43+
html_favicon_url = "https://unicode-rs.github.io/unicode-rs_sm.png"
44+
)]
4345

4446
extern crate tinyvec;
4547

46-
pub use crate::tables::UNICODE_VERSION;
4748
pub use crate::decompose::Decompositions;
4849
pub use crate::quick_check::{
50+
is_nfc, is_nfc_quick, is_nfc_stream_safe, is_nfc_stream_safe_quick, is_nfd, is_nfd_quick,
51+
is_nfd_stream_safe, is_nfd_stream_safe_quick, is_nfkc, is_nfkc_quick, is_nfkd, is_nfkd_quick,
4952
IsNormalized,
50-
is_nfc,
51-
is_nfc_quick,
52-
is_nfkc,
53-
is_nfkc_quick,
54-
is_nfc_stream_safe,
55-
is_nfc_stream_safe_quick,
56-
is_nfd,
57-
is_nfd_quick,
58-
is_nfkd,
59-
is_nfkd_quick,
60-
is_nfd_stream_safe,
61-
is_nfd_stream_safe_quick,
6253
};
6354
pub use crate::recompose::Recompositions;
6455
pub use crate::stream_safe::StreamSafe;
56+
pub use crate::tables::UNICODE_VERSION;
6557
use std::str::Chars;
6658

6759
mod decompose;
6860
mod lookups;
6961
mod normalize;
7062
mod perfect_hash;
71-
mod recompose;
7263
mod quick_check;
64+
mod recompose;
7365
mod stream_safe;
7466

7567
#[rustfmt::skip]
7668
mod tables;
7769

78-
#[cfg(test)]
79-
mod test;
8070
#[doc(hidden)]
8171
pub mod __test_api;
72+
#[cfg(test)]
73+
mod test;
8274

8375
/// Methods for composing and decomposing characters.
8476
pub mod char {
85-
pub use crate::normalize::{decompose_canonical, decompose_compatible, compose};
77+
pub use crate::normalize::{compose, decompose_canonical, decompose_compatible};
8678

8779
pub use crate::lookups::{canonical_combining_class, is_combining_mark};
8880
}
8981

90-
9182
/// Methods for iterating over strings while applying Unicode normalizations
9283
/// as described in
9384
/// [Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/).
94-
pub trait UnicodeNormalization<I: Iterator<Item=char>> {
85+
pub trait UnicodeNormalization<I: Iterator<Item = char>> {
9586
/// Returns an iterator over the string in Unicode Normalization Form D
9687
/// (canonical decomposition).
9788
fn nfd(self) -> Decompositions<I>;
@@ -140,7 +131,7 @@ impl<'a> UnicodeNormalization<Chars<'a>> for &'a str {
140131
}
141132
}
142133

143-
impl<I: Iterator<Item=char>> UnicodeNormalization<I> for I {
134+
impl<I: Iterator<Item = char>> UnicodeNormalization<I> for I {
144135
#[inline]
145136
fn nfd(self) -> Decompositions<I> {
146137
decompose::new_canonical(self)

src/lookups.rs

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,42 +14,77 @@ use crate::perfect_hash::mph_lookup;
1414
use crate::tables::*;
1515

1616
/// Look up the canonical combining class for a codepoint.
17-
///
17+
///
1818
/// The value returned is as defined in the Unicode Character Database.
1919
pub fn canonical_combining_class(c: char) -> u8 {
20-
mph_lookup(c.into(), CANONICAL_COMBINING_CLASS_SALT, CANONICAL_COMBINING_CLASS_KV,
21-
u8_lookup_fk, u8_lookup_fv, 0)
20+
mph_lookup(
21+
c.into(),
22+
CANONICAL_COMBINING_CLASS_SALT,
23+
CANONICAL_COMBINING_CLASS_KV,
24+
u8_lookup_fk,
25+
u8_lookup_fv,
26+
0,
27+
)
2228
}
2329

2430
pub(crate) fn composition_table(c1: char, c2: char) -> Option<char> {
2531
if c1 < '\u{10000}' && c2 < '\u{10000}' {
26-
mph_lookup((c1 as u32) << 16 | (c2 as u32),
27-
COMPOSITION_TABLE_SALT, COMPOSITION_TABLE_KV,
28-
pair_lookup_fk, pair_lookup_fv_opt, None)
32+
mph_lookup(
33+
(c1 as u32) << 16 | (c2 as u32),
34+
COMPOSITION_TABLE_SALT,
35+
COMPOSITION_TABLE_KV,
36+
pair_lookup_fk,
37+
pair_lookup_fv_opt,
38+
None,
39+
)
2940
} else {
3041
composition_table_astral(c1, c2)
3142
}
3243
}
3344

3445
pub(crate) fn canonical_fully_decomposed(c: char) -> Option<&'static [char]> {
35-
mph_lookup(c.into(), CANONICAL_DECOMPOSED_SALT, CANONICAL_DECOMPOSED_KV,
36-
pair_lookup_fk, pair_lookup_fv_opt, None)
46+
mph_lookup(
47+
c.into(),
48+
CANONICAL_DECOMPOSED_SALT,
49+
CANONICAL_DECOMPOSED_KV,
50+
pair_lookup_fk,
51+
pair_lookup_fv_opt,
52+
None,
53+
)
3754
}
3855

3956
pub(crate) fn compatibility_fully_decomposed(c: char) -> Option<&'static [char]> {
40-
mph_lookup(c.into(), COMPATIBILITY_DECOMPOSED_SALT, COMPATIBILITY_DECOMPOSED_KV,
41-
pair_lookup_fk, pair_lookup_fv_opt, None)
57+
mph_lookup(
58+
c.into(),
59+
COMPATIBILITY_DECOMPOSED_SALT,
60+
COMPATIBILITY_DECOMPOSED_KV,
61+
pair_lookup_fk,
62+
pair_lookup_fv_opt,
63+
None,
64+
)
4265
}
4366

4467
/// Return whether the given character is a combining mark (`General_Category=Mark`)
4568
pub fn is_combining_mark(c: char) -> bool {
46-
mph_lookup(c.into(), COMBINING_MARK_SALT, COMBINING_MARK_KV,
47-
bool_lookup_fk, bool_lookup_fv, false)
69+
mph_lookup(
70+
c.into(),
71+
COMBINING_MARK_SALT,
72+
COMBINING_MARK_KV,
73+
bool_lookup_fk,
74+
bool_lookup_fv,
75+
false,
76+
)
4877
}
4978

5079
pub fn stream_safe_trailing_nonstarters(c: char) -> usize {
51-
mph_lookup(c.into(), TRAILING_NONSTARTERS_SALT, TRAILING_NONSTARTERS_KV,
52-
u8_lookup_fk, u8_lookup_fv, 0) as usize
80+
mph_lookup(
81+
c.into(),
82+
TRAILING_NONSTARTERS_SALT,
83+
TRAILING_NONSTARTERS_KV,
84+
u8_lookup_fk,
85+
u8_lookup_fv,
86+
0,
87+
) as usize
5388
}
5489

5590
/// Extract the key in a 24 bit key and 8 bit value packed in a u32.

src/normalize.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,20 @@
99
// except according to those terms.
1010

1111
//! Functions for computing canonical and compatible decompositions for Unicode characters.
12+
use crate::lookups::{
13+
canonical_fully_decomposed, compatibility_fully_decomposed, composition_table,
14+
};
1215
use std::char;
1316
use std::ops::FnMut;
14-
use crate::lookups::{canonical_fully_decomposed, composition_table, compatibility_fully_decomposed};
1517

1618
/// Compute canonical Unicode decomposition for character.
1719
/// See [Unicode Standard Annex #15](http://www.unicode.org/reports/tr15/)
1820
/// for more information.
1921
#[inline]
20-
pub fn decompose_canonical<F>(c: char, emit_char: F) where F: FnMut(char) {
22+
pub fn decompose_canonical<F>(c: char, emit_char: F)
23+
where
24+
F: FnMut(char),
25+
{
2126
decompose(c, canonical_fully_decomposed, emit_char)
2227
}
2328

@@ -26,14 +31,16 @@ pub fn decompose_canonical<F>(c: char, emit_char: F) where F: FnMut(char) {
2631
/// for more information.
2732
#[inline]
2833
pub fn decompose_compatible<F: FnMut(char)>(c: char, emit_char: F) {
29-
let decompose_char = |c| compatibility_fully_decomposed(c)
30-
.or_else(|| canonical_fully_decomposed(c));
34+
let decompose_char =
35+
|c| compatibility_fully_decomposed(c).or_else(|| canonical_fully_decomposed(c));
3136
decompose(c, decompose_char, emit_char)
3237
}
3338

3439
#[inline]
3540
fn decompose<D, F>(c: char, decompose_char: D, mut emit_char: F)
36-
where D: Fn(char) -> Option<&'static [char]>, F: FnMut(char)
41+
where
42+
D: Fn(char) -> Option<&'static [char]>,
43+
F: FnMut(char),
3744
{
3845
// 7-bit ASCII never decomposes
3946
if c <= '\x7f' {
@@ -93,7 +100,10 @@ pub(crate) fn is_hangul_syllable(c: char) -> bool {
93100
// Decompose a precomposed Hangul syllable
94101
#[allow(unsafe_code)]
95102
#[inline(always)]
96-
fn decompose_hangul<F>(s: char, mut emit_char: F) where F: FnMut(char) {
103+
fn decompose_hangul<F>(s: char, mut emit_char: F)
104+
where
105+
F: FnMut(char),
106+
{
97107
let s_index = s as u32 - S_BASE;
98108
let l_index = s_index / N_COUNT;
99109
unsafe {
@@ -113,7 +123,11 @@ fn decompose_hangul<F>(s: char, mut emit_char: F) where F: FnMut(char) {
113123
pub(crate) fn hangul_decomposition_length(s: char) -> usize {
114124
let si = s as u32 - S_BASE;
115125
let ti = si % T_COUNT;
116-
if ti > 0 { 3 } else { 2 }
126+
if ti > 0 {
127+
3
128+
} else {
129+
2
130+
}
117131
}
118132

119133
// Compose a pair of Hangul Jamo
@@ -124,17 +138,17 @@ fn compose_hangul(a: char, b: char) -> Option<char> {
124138
let (a, b) = (a as u32, b as u32);
125139
match (a, b) {
126140
// Compose a leading consonant and a vowel together into an LV_Syllable
127-
(L_BASE ... L_LAST, V_BASE ... V_LAST) => {
141+
(L_BASE...L_LAST, V_BASE...V_LAST) => {
128142
let l_index = a - L_BASE;
129143
let v_index = b - V_BASE;
130144
let lv_index = l_index * N_COUNT + v_index * T_COUNT;
131145
let s = S_BASE + lv_index;
132-
Some(unsafe {char::from_u32_unchecked(s)})
133-
},
146+
Some(unsafe { char::from_u32_unchecked(s) })
147+
}
134148
// Compose an LV_Syllable and a trailing consonant into an LVT_Syllable
135-
(S_BASE ... S_LAST, T_FIRST ... T_LAST) if (a - S_BASE) % T_COUNT == 0 => {
136-
Some(unsafe {char::from_u32_unchecked(a + (b - T_BASE))})
137-
},
149+
(S_BASE...S_LAST, T_FIRST...T_LAST) if (a - S_BASE) % T_COUNT == 0 => {
150+
Some(unsafe { char::from_u32_unchecked(a + (b - T_BASE)) })
151+
}
138152
_ => None,
139153
}
140154
}

src/perfect_hash.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,25 @@ fn my_hash(key: u32, salt: u32, n: usize) -> usize {
2020
}
2121

2222
/// Do a lookup using minimal perfect hashing.
23-
///
23+
///
2424
/// The table is stored as a sequence of "salt" values, then a sequence of
2525
/// values that contain packed key/value pairs. The strategy is to hash twice.
2626
/// The first hash retrieves a salt value that makes the second hash unique.
2727
/// The hash function doesn't have to be very good, just good enough that the
2828
/// resulting map is unique.
2929
#[inline]
30-
pub(crate) fn mph_lookup<KV, V, FK, FV>(x: u32, salt: &[u16], kv: &[KV], fk: FK, fv: FV,
31-
default: V) -> V
32-
where KV: Copy, FK: Fn(KV) -> u32, FV: Fn(KV) -> V
30+
pub(crate) fn mph_lookup<KV, V, FK, FV>(
31+
x: u32,
32+
salt: &[u16],
33+
kv: &[KV],
34+
fk: FK,
35+
fv: FV,
36+
default: V,
37+
) -> V
38+
where
39+
KV: Copy,
40+
FK: Fn(KV) -> u32,
41+
FV: Fn(KV) -> V,
3342
{
3443
let s = salt[my_hash(x, 0, salt.len())] as u32;
3544
let key_val = kv[my_hash(x, s, salt.len())];

0 commit comments

Comments
 (0)
0