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:
parent
8c54d5bf40
commit
df802a2754
@ -256,13 +256,13 @@ def format_table_content(f, content, indent):
|
||||
line = " "*indent + chunk
|
||||
f.write(line)
|
||||
|
||||
def emit_core_decomp_module(f, canon, compat):
|
||||
def emit_core_norm_module(f, canon, compat):
|
||||
canon_keys = canon.keys()
|
||||
canon_keys.sort()
|
||||
|
||||
compat_keys = compat.keys()
|
||||
compat_keys.sort()
|
||||
f.write("pub mod decompose {\n");
|
||||
f.write("pub mod normalization {\n");
|
||||
f.write(" use option::Option;\n");
|
||||
f.write(" use option::{Some, None};\n");
|
||||
f.write(" use slice::ImmutableVector;\n");
|
||||
@ -401,8 +401,8 @@ def emit_core_decomp_module(f, canon, compat):
|
||||
|
||||
""")
|
||||
|
||||
def emit_std_decomp_module(f, combine):
|
||||
f.write("pub mod decompose {\n");
|
||||
def emit_std_norm_module(f, combine):
|
||||
f.write("pub mod normalization {\n");
|
||||
f.write(" use option::{Some, None};\n");
|
||||
f.write(" use slice::ImmutableVector;\n");
|
||||
|
||||
@ -467,7 +467,7 @@ def gen_core_unicode():
|
||||
emit_bsearch_range_table(rf);
|
||||
emit_property_module(rf, "general_category", gencats)
|
||||
|
||||
emit_core_decomp_module(rf, canon_decomp, compat_decomp)
|
||||
emit_core_norm_module(rf, canon_decomp, compat_decomp)
|
||||
|
||||
derived = load_properties("DerivedCoreProperties.txt",
|
||||
["XID_Start", "XID_Continue", "Alphabetic", "Lowercase", "Uppercase"])
|
||||
@ -485,7 +485,7 @@ def gen_std_unicode():
|
||||
with open(r, "w") as rf:
|
||||
# Preamble
|
||||
rf.write(preamble)
|
||||
emit_std_decomp_module(rf, combines)
|
||||
emit_std_norm_module(rf, combines)
|
||||
|
||||
gen_core_unicode()
|
||||
gen_std_unicode()
|
||||
|
@ -30,9 +30,9 @@ use iter::{Iterator, range_step};
|
||||
use unicode::{derived_property, property, general_category, conversions};
|
||||
|
||||
/// Returns the canonical decomposition of a character.
|
||||
pub use unicode::decompose::decompose_canonical;
|
||||
pub use unicode::normalization::decompose_canonical;
|
||||
/// Returns the compatibility decomposition of a character.
|
||||
pub use unicode::decompose::decompose_compatible;
|
||||
pub use unicode::normalization::decompose_compatible;
|
||||
|
||||
#[cfg(not(test))] use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
|
||||
#[cfg(not(test))] use default::Default;
|
||||
|
@ -104,7 +104,7 @@ pub mod general_category {
|
||||
|
||||
}
|
||||
|
||||
pub mod decompose {
|
||||
pub mod normalization {
|
||||
use option::Option;
|
||||
use option::{Some, None};
|
||||
use slice::ImmutableVector;
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
#![allow(missing_doc, non_uppercase_statics)]
|
||||
|
||||
pub mod decompose {
|
||||
pub mod normalization {
|
||||
use option::{Some, None};
|
||||
use slice::ImmutableVector;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user