-use normalize::{
- hangul_decomposition_length,
- is_hangul_syllable,
-};
-use lookups::{
+use crate::lookups::{
canonical_combining_class, canonical_fully_decomposed, compatibility_fully_decomposed,
stream_safe_trailing_nonstarters,
};
-use tables::stream_safe_leading_nonstarters;
+use crate::normalize::{hangul_decomposition_length, is_hangul_syllable};
+use crate::tables::stream_safe_leading_nonstarters;
pub(crate) const MAX_NONSTARTERS: usize = 30;
const COMBINING_GRAPHEME_JOINER: char = '\u{034F}';
impl<I> StreamSafe<I> {
pub(crate) fn new(iter: I) -> Self {
- Self { iter, nonstarter_count: 0, buffer: None }
+ Self {
+ iter,
+ nonstarter_count: 0,
+ buffer: None,
+ }
}
}
-impl<I: Iterator<Item=char>> Iterator for StreamSafe<I> {
+impl<I: Iterator<Item = char>> Iterator for StreamSafe<I> {
type Item = char;
#[inline]
leading_nonstarters: 0,
trailing_nonstarters: 0,
decomposition_len: 1,
- }
+ };
}
// Next, special case Hangul, since it's not handled by our tables.
if is_hangul_syllable(c) {
decomposition_len: hangul_decomposition_length(c),
};
}
- let decomp = compatibility_fully_decomposed(c)
- .or_else(|| canonical_fully_decomposed(c));
+ let decomp = compatibility_fully_decomposed(c).or_else(|| canonical_fully_decomposed(c));
match decomp {
- Some(decomp) => {
- Decomposition {
- leading_nonstarters: stream_safe_leading_nonstarters(c),
- trailing_nonstarters: stream_safe_trailing_nonstarters(c),
- decomposition_len: decomp.len(),
- }
+ Some(decomp) => Decomposition {
+ leading_nonstarters: stream_safe_leading_nonstarters(c),
+ trailing_nonstarters: stream_safe_trailing_nonstarters(c),
+ decomposition_len: decomp.len(),
},
None => {
let is_nonstarter = canonical_combining_class(c) != 0;
#[cfg(test)]
mod tests {
- use super::{
- StreamSafe,
- classify_nonstarters,
- };
- use std::char;
- use normalize::decompose_compatible;
- use lookups::canonical_combining_class;
+ use super::{classify_nonstarters, StreamSafe};
+ use crate::lookups::canonical_combining_class;
+ use crate::normalize::decompose_compatible;
+
+ #[cfg(not(feature = "std"))]
+ use crate::no_std_prelude::*;
+
+ use core::char;
fn stream_safe(s: &str) -> String {
StreamSafe::new(s.chars()).collect()
None => continue,
};
let c = classify_nonstarters(ch);
- let mut s = vec![];
+ let mut s = Vec::new();
decompose_compatible(ch, |c| s.push(c));
assert_eq!(s.len(), c.decomposition_len);