Implement ExactSizeIterator for ToLowercase and ToUppercase
This commit is contained in:
parent
f47ec2ad5b
commit
988b3d5f9e
2 changed files with 26 additions and 0 deletions
|
@ -389,11 +389,17 @@ impl Iterator for ToLowercase {
|
||||||
fn next(&mut self) -> Option<char> {
|
fn next(&mut self) -> Option<char> {
|
||||||
self.0.next()
|
self.0.next()
|
||||||
}
|
}
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
self.0.size_hint()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "fused", since = "1.26.0")]
|
#[stable(feature = "fused", since = "1.26.0")]
|
||||||
impl FusedIterator for ToLowercase {}
|
impl FusedIterator for ToLowercase {}
|
||||||
|
|
||||||
|
#[stable(feature = "exact_size_case_mapping_iter", since = "1.34.0")]
|
||||||
|
impl ExactSizeIterator for ToLowercase {}
|
||||||
|
|
||||||
/// Returns an iterator that yields the uppercase equivalent of a `char`.
|
/// Returns an iterator that yields the uppercase equivalent of a `char`.
|
||||||
///
|
///
|
||||||
/// This `struct` is created by the [`to_uppercase`] method on [`char`]. See
|
/// This `struct` is created by the [`to_uppercase`] method on [`char`]. See
|
||||||
|
@ -411,11 +417,17 @@ impl Iterator for ToUppercase {
|
||||||
fn next(&mut self) -> Option<char> {
|
fn next(&mut self) -> Option<char> {
|
||||||
self.0.next()
|
self.0.next()
|
||||||
}
|
}
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
self.0.size_hint()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[stable(feature = "fused", since = "1.26.0")]
|
#[stable(feature = "fused", since = "1.26.0")]
|
||||||
impl FusedIterator for ToUppercase {}
|
impl FusedIterator for ToUppercase {}
|
||||||
|
|
||||||
|
#[stable(feature = "exact_size_case_mapping_iter", since = "1.34.0")]
|
||||||
|
impl ExactSizeIterator for ToUppercase {}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum CaseMappingIter {
|
enum CaseMappingIter {
|
||||||
Three(char, char, char),
|
Three(char, char, char),
|
||||||
|
@ -457,6 +469,16 @@ impl Iterator for CaseMappingIter {
|
||||||
CaseMappingIter::Zero => None,
|
CaseMappingIter::Zero => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||||
|
let size = match self {
|
||||||
|
CaseMappingIter::Three(..) => 3,
|
||||||
|
CaseMappingIter::Two(..) => 2,
|
||||||
|
CaseMappingIter::One(_) => 1,
|
||||||
|
CaseMappingIter::Zero => 0,
|
||||||
|
};
|
||||||
|
(size, Some(size))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for CaseMappingIter {
|
impl fmt::Display for CaseMappingIter {
|
||||||
|
|
|
@ -76,6 +76,8 @@ fn test_to_digit() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_lowercase() {
|
fn test_to_lowercase() {
|
||||||
fn lower(c: char) -> String {
|
fn lower(c: char) -> String {
|
||||||
|
let to_lowercase = c.to_uppercase();
|
||||||
|
assert_eq!(to_lowercase.len(), to_lowercase.count());
|
||||||
let iter: String = c.to_lowercase().collect();
|
let iter: String = c.to_lowercase().collect();
|
||||||
let disp: String = c.to_lowercase().to_string();
|
let disp: String = c.to_lowercase().to_string();
|
||||||
assert_eq!(iter, disp);
|
assert_eq!(iter, disp);
|
||||||
|
@ -101,6 +103,8 @@ fn test_to_lowercase() {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_to_uppercase() {
|
fn test_to_uppercase() {
|
||||||
fn upper(c: char) -> String {
|
fn upper(c: char) -> String {
|
||||||
|
let to_uppercase = c.to_uppercase();
|
||||||
|
assert_eq!(to_uppercase.len(), to_uppercase.count());
|
||||||
let iter: String = c.to_uppercase().collect();
|
let iter: String = c.to_uppercase().collect();
|
||||||
let disp: String = c.to_uppercase().to_string();
|
let disp: String = c.to_uppercase().to_string();
|
||||||
assert_eq!(iter, disp);
|
assert_eq!(iter, disp);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue