std: Rename str::Normalizations to str::Decompositions
The Normalizations iterator has been renamed to Decompositions. It does not currently include all forms of Unicode normalization, but only encompasses decompositions. If implemented recomposition would likely be a separate iterator which works on the result of this one. [breaking-change]
This commit is contained in:
committed by
Alex Crichton
parent
8c54d5bf40
commit
df802a2754
@@ -228,25 +228,25 @@ fn canonical_sort(comb: &mut [(char, u8)]) {
|
||||
}
|
||||
|
||||
#[deriving(Clone)]
|
||||
enum NormalizationForm {
|
||||
NFD,
|
||||
NFKD
|
||||
enum DecompositionType {
|
||||
Canonical,
|
||||
Compatible
|
||||
}
|
||||
|
||||
/// External iterator for a string's normalization's characters.
|
||||
/// External iterator for a string's decomposition's characters.
|
||||
/// Use with the `std::iter` module.
|
||||
#[deriving(Clone)]
|
||||
pub struct Normalizations<'a> {
|
||||
kind: NormalizationForm,
|
||||
pub struct Decompositions<'a> {
|
||||
kind: DecompositionType,
|
||||
iter: Chars<'a>,
|
||||
buffer: Vec<(char, u8)>,
|
||||
sorted: bool
|
||||
}
|
||||
|
||||
impl<'a> Iterator<char> for Normalizations<'a> {
|
||||
impl<'a> Iterator<char> for Decompositions<'a> {
|
||||
#[inline]
|
||||
fn next(&mut self) -> Option<char> {
|
||||
use unicode::decompose::canonical_combining_class;
|
||||
use unicode::normalization::canonical_combining_class;
|
||||
|
||||
match self.buffer.as_slice().head() {
|
||||
Some(&(c, 0)) => {
|
||||
@@ -262,8 +262,8 @@ impl<'a> Iterator<char> for Normalizations<'a> {
|
||||
}
|
||||
|
||||
let decomposer = match self.kind {
|
||||
NFD => char::decompose_canonical,
|
||||
NFKD => char::decompose_compatible
|
||||
Canonical => char::decompose_canonical,
|
||||
Compatible => char::decompose_compatible
|
||||
};
|
||||
|
||||
if !self.sorted {
|
||||
@@ -887,24 +887,24 @@ pub trait StrAllocating: Str {
|
||||
/// An Iterator over the string in Unicode Normalization Form D
|
||||
/// (canonical decomposition).
|
||||
#[inline]
|
||||
fn nfd_chars<'a>(&'a self) -> Normalizations<'a> {
|
||||
Normalizations {
|
||||
fn nfd_chars<'a>(&'a self) -> Decompositions<'a> {
|
||||
Decompositions {
|
||||
iter: self.as_slice().chars(),
|
||||
buffer: Vec::new(),
|
||||
sorted: false,
|
||||
kind: NFD
|
||||
kind: Canonical
|
||||
}
|
||||
}
|
||||
|
||||
/// An Iterator over the string in Unicode Normalization Form KD
|
||||
/// (compatibility decomposition).
|
||||
#[inline]
|
||||
fn nfkd_chars<'a>(&'a self) -> Normalizations<'a> {
|
||||
Normalizations {
|
||||
fn nfkd_chars<'a>(&'a self) -> Decompositions<'a> {
|
||||
Decompositions {
|
||||
iter: self.as_slice().chars(),
|
||||
buffer: Vec::new(),
|
||||
sorted: false,
|
||||
kind: NFKD
|
||||
kind: Compatible
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user