//! ```
#![stable(feature = "rust1", since = "1.0.0")]
-
// Many of the usings in this module are only used in the test configuration.
// It's cleaner to just turn off the unused_imports warning than to fix them.
#![allow(unused_imports)]
use core::borrow::{Borrow, BorrowMut};
-use core::str::pattern::{Pattern, Searcher, ReverseSearcher, DoubleEndedSearcher};
+use core::iter::FusedIterator;
use core::mem;
use core::ptr;
-use core::iter::FusedIterator;
+use core::str::pattern::{DoubleEndedSearcher, Pattern, ReverseSearcher, Searcher};
use core::unicode::conversions;
use crate::borrow::ToOwned;
use crate::vec::Vec;
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{FromStr, Utf8Error};
-#[allow(deprecated)]
+pub use core::str::pattern;
+#[stable(feature = "encode_utf16", since = "1.8.0")]
+pub use core::str::EncodeUtf16;
+#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
+pub use core::str::SplitAsciiWhitespace;
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{Lines, LinesAny};
+pub use core::str::SplitWhitespace;
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{Split, RSplit};
+pub use core::str::{from_utf8, from_utf8_mut, Bytes, CharIndices, Chars};
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{SplitN, RSplitN};
+pub use core::str::{from_utf8_unchecked, from_utf8_unchecked_mut, ParseBoolError};
+#[stable(feature = "str_escape", since = "1.34.0")]
+pub use core::str::{EscapeDebug, EscapeDefault, EscapeUnicode};
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{SplitTerminator, RSplitTerminator};
+pub use core::str::{FromStr, Utf8Error};
+#[allow(deprecated)]
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{Matches, RMatches};
+pub use core::str::{Lines, LinesAny};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::str::{MatchIndices, RMatchIndices};
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{from_utf8, from_utf8_mut, Chars, CharIndices, Bytes};
+pub use core::str::{Matches, RMatches};
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::{from_utf8_unchecked, from_utf8_unchecked_mut, ParseBoolError};
+pub use core::str::{RSplit, Split};
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::SplitWhitespace;
+pub use core::str::{RSplitN, SplitN};
#[stable(feature = "rust1", since = "1.0.0")]
-pub use core::str::pattern;
-#[stable(feature = "encode_utf16", since = "1.8.0")]
-pub use core::str::EncodeUtf16;
-#[stable(feature = "split_ascii_whitespace", since = "1.34.0")]
-pub use core::str::SplitAsciiWhitespace;
-#[stable(feature = "str_escape", since = "1.34.0")]
-pub use core::str::{EscapeDebug, EscapeDefault, EscapeUnicode};
+pub use core::str::{RSplitTerminator, SplitTerminator};
/// Note: `str` in `Concat<str>` is not meaningful here.
/// This type parameter of the trait only exists to enable another impl.
type Output = String;
fn join(slice: &Self, sep: &str) -> String {
- unsafe {
- String::from_utf8_unchecked( join_generic_copy(slice, sep.as_bytes()) )
- }
+ unsafe { String::from_utf8_unchecked(join_generic_copy(slice, sep.as_bytes())) }
}
}
macro_rules! copy_slice_and_advance {
($target:expr, $bytes:expr) => {
let len = $bytes.len();
- let (head, tail) = {$target}.split_at_mut(len);
+ let (head, tail) = { $target }.split_at_mut(len);
head.copy_from_slice($bytes);
$target = tail;
- }
+ };
}
// Optimized join implementation that works for both Vec<T> (T: Copy) and String's inner vec
// if the `len` calculation overflows, we'll panic
// we would have run out of memory anyway and the rest of the function requires
// the entire Vec pre-allocated for safety
- let len = sep_len.checked_mul(iter.len()).and_then(|n| {
- slice.iter()
- .map(|s| s.borrow().as_ref().len())
- .try_fold(n, usize::checked_add)
- }).expect("attempt to join into collection with len > usize::MAX");
+ let len = sep_len
+ .checked_mul(iter.len())
+ .and_then(|n| {
+ slice.iter().map(|s| s.borrow().as_ref().len()).try_fold(n, usize::checked_add)
+ })
+ .expect("attempt to join into collection with len > usize::MAX");
// crucial for safety
let mut result = Vec::with_capacity(len);
// See http://www.unicode.org/versions/Unicode7.0.0/ch03.pdf#G33992
// for the definition of `Final_Sigma`.
debug_assert!('Σ'.len_utf8() == 2);
- let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev()) &&
- !case_ignoreable_then_cased(from[i + 2..].chars());
+ let is_word_final = case_ignoreable_then_cased(from[..i].chars().rev())
+ && !case_ignoreable_then_cased(from[i + 2..].chars());
to.push_str(if is_word_final { "ς" } else { "σ" });
}
fn case_ignoreable_then_cased<I: Iterator<Item = char>>(iter: I) -> bool {
- use core::unicode::derived_property::{Cased, Case_Ignorable};
+ use core::unicode::derived_property::{Case_Ignorable, Cased};
match iter.skip_while(|&c| Case_Ignorable(c)).next() {
Some(c) => Cased(c),
None => false,
}
}
}
- return s;
+ s
}
/// Converts a [`Box<str>`] into a [`String`] without copying or allocating.