Skip to content

Commit

Permalink
std: Rename str::Normalizations to str::Decompositions
Browse files Browse the repository at this point in the history
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]
  • Loading branch information
Florob authored and alexcrichton committed May 14, 2014
1 parent 8c54d5b commit df802a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
12 changes: 6 additions & 6 deletions src/etc/unicode.py
Expand Up @@ -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");
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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"])
Expand All @@ -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()
4 changes: 2 additions & 2 deletions src/libcore/char.rs
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/unicode.rs
Expand Up @@ -104,7 +104,7 @@ pub mod general_category {

}

pub mod decompose {
pub mod normalization {
use option::Option;
use option::{Some, None};
use slice::ImmutableVector;
Expand Down
32 changes: 16 additions & 16 deletions src/libstd/str.rs
Expand Up @@ -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)) => {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/unicode.rs
Expand Up @@ -12,7 +12,7 @@

#![allow(missing_doc, non_uppercase_statics)]

pub mod decompose {
pub mod normalization {
use option::{Some, None};
use slice::ImmutableVector;

Expand Down

0 comments on commit df802a2

Please sign in to comment.