]> git.proxmox.com Git - rustc.git/blobdiff - vendor/unicode-normalization/src/stream_safe.rs
New upstream version 1.46.0~beta.2+dfsg1
[rustc.git] / vendor / unicode-normalization / src / stream_safe.rs
index 2cfcc36a9239adf7517d13a7df8963ea7903f04a..1ba7d76106970aded8e476272c451c2ce5e5bf31 100644 (file)
@@ -1,12 +1,9 @@
-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}';
@@ -22,11 +19,15 @@ pub struct StreamSafe<I> {
 
 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]
@@ -72,7 +73,7 @@ pub(crate) fn classify_nonstarters(c: char) -> Decomposition {
             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) {
@@ -82,15 +83,12 @@ pub(crate) fn classify_nonstarters(c: char) -> Decomposition {
             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;
@@ -106,13 +104,14 @@ pub(crate) fn classify_nonstarters(c: char) -> Decomposition {
 
 #[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()
@@ -136,7 +135,7 @@ mod tests {
                 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);