Skip to content

Commit

Permalink
deprecate Unicode functions that will be moved to crates.io
Browse files Browse the repository at this point in the history
This deprecates the following functionality:

1. char.width() and str.width(): use unicode-width crate

2. str.graphemes() and str.grapheme_indices():
   use unicode-segmentation crate

3. str.nfd_chars(), str.nfkd_chars(), str.nfc_chars(), str.nfkc_chars(),
   char.compose(), char.decompose_canonical(), char.decompose_compatible():
   use unicode-normalization crate
  • Loading branch information
kwantam committed Apr 15, 2015
1 parent dabf0c6 commit d14a96c
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/libcollections/str.rs
Expand Up @@ -161,6 +161,9 @@ enum DecompositionType {
/// External iterator for a string decomposition's characters.
///
/// For use with the `std::iter` module.
#[allow(deprecated)]
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[derive(Clone)]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand All @@ -172,6 +175,7 @@ pub struct Decompositions<'a> {
sorted: bool
}

#[allow(deprecated)]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Decompositions<'a> {
type Item = char;
Expand Down Expand Up @@ -254,6 +258,9 @@ enum RecompositionState {
/// External iterator for a string recomposition's characters.
///
/// For use with the `std::iter` module.
#[allow(deprecated)]
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[derive(Clone)]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand All @@ -266,6 +273,7 @@ pub struct Recompositions<'a> {
last_ccc: Option<u8>
}

#[allow(deprecated)]
#[stable(feature = "rust1", since = "1.0.0")]
impl<'a> Iterator for Recompositions<'a> {
type Item = char;
Expand Down Expand Up @@ -465,6 +473,9 @@ impl str {

/// Returns an iterator over the string in Unicode Normalization Form D
/// (canonical decomposition).
#[allow(deprecated)]
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[inline]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand All @@ -480,6 +491,9 @@ impl str {

/// Returns an iterator over the string in Unicode Normalization Form KD
/// (compatibility decomposition).
#[allow(deprecated)]
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[inline]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand All @@ -495,6 +509,9 @@ impl str {

/// An Iterator over the string in Unicode Normalization Form C
/// (canonical decomposition followed by canonical composition).
#[allow(deprecated)]
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[inline]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand All @@ -511,6 +528,9 @@ impl str {

/// An Iterator over the string in Unicode Normalization Form KC
/// (compatibility decomposition followed by canonical composition).
#[allow(deprecated)]
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[inline]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand Down Expand Up @@ -1690,6 +1710,8 @@ impl str {
///
/// assert_eq!(&gr2[..], b);
/// ```
#[deprecated(reason = "use the crates.io `unicode-segmentation` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality may only be provided by libunicode")]
pub fn graphemes(&self, is_extended: bool) -> Graphemes {
Expand All @@ -1709,6 +1731,8 @@ impl str {
///
/// assert_eq!(&gr_inds[..], b);
/// ```
#[deprecated(reason = "use the crates.io `unicode-segmentation` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality may only be provided by libunicode")]
pub fn grapheme_indices(&self, is_extended: bool) -> GraphemeIndices {
Expand Down Expand Up @@ -1749,6 +1773,8 @@ impl str {
/// recommends that these
/// characters be treated as 1 column (i.e., `is_cjk = false`) if the
/// locale is unknown.
#[deprecated(reason = "use the crates.io `unicode-width` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality may only be provided by libunicode")]
pub fn width(&self, is_cjk: bool) -> usize {
Expand Down
6 changes: 6 additions & 0 deletions src/libcollectionstest/str.rs
Expand Up @@ -19,6 +19,7 @@ fn test_le() {
assert!("foo" != "bar");
}

#[allow(deprecated)]
#[test]
fn test_len() {
assert_eq!("".len(), 0);
Expand Down Expand Up @@ -944,6 +945,7 @@ fn test_words() {
assert_eq!(words, ["Märy", "häd", "ä", "little", "lämb", "Little", "lämb"])
}

#[allow(deprecated)]
#[test]
fn test_nfd_chars() {
macro_rules! t {
Expand All @@ -963,6 +965,7 @@ fn test_nfd_chars() {
t!("\u{ac1c}", "\u{1100}\u{1162}");
}

#[allow(deprecated)]
#[test]
fn test_nfkd_chars() {
macro_rules! t {
Expand All @@ -982,6 +985,7 @@ fn test_nfkd_chars() {
t!("\u{ac1c}", "\u{1100}\u{1162}");
}

#[allow(deprecated)]
#[test]
fn test_nfc_chars() {
macro_rules! t {
Expand All @@ -1002,6 +1006,7 @@ fn test_nfc_chars() {
t!("a\u{300}\u{305}\u{315}\u{5ae}b", "\u{e0}\u{5ae}\u{305}\u{315}b");
}

#[allow(deprecated)]
#[test]
fn test_nfkc_chars() {
macro_rules! t {
Expand Down Expand Up @@ -1033,6 +1038,7 @@ fn test_lines() {
assert_eq!(lines, ["", "Märy häd ä little lämb", "", "Little lämb"]);
}

#[allow(deprecated)]
#[test]
fn test_graphemes() {
use std::iter::order;
Expand Down
1 change: 1 addition & 0 deletions src/libcoretest/char.rs
Expand Up @@ -210,6 +210,7 @@ fn test_len_utf16() {
assert!('\u{1f4a9}'.len_utf16() == 2);
}

#[allow(deprecated)]
#[test]
fn test_width() {
assert_eq!('\x00'.width(false),Some(0));
Expand Down
1 change: 1 addition & 0 deletions src/librustc_driver/lib.rs
Expand Up @@ -531,6 +531,7 @@ Additional help:
extra_help);
}

#[allow(deprecated)]
fn describe_lints(lint_store: &lint::LintStore, loaded_plugins: bool) {
println!("
Available lint options:
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/diagnostic.rs
Expand Up @@ -542,6 +542,7 @@ fn highlight_suggestion(err: &mut EmitterWriter,
Ok(())
}

#[allow(deprecated)]
fn highlight_lines(err: &mut EmitterWriter,
cm: &codemap::CodeMap,
sp: Span,
Expand Down Expand Up @@ -664,6 +665,7 @@ fn highlight_lines(err: &mut EmitterWriter,
/// than 6 lines), `end_highlight_lines` will print the first line, then
/// dot dot dot, then last line, whereas `highlight_lines` prints the first
/// six lines.
#[allow(deprecated)]
fn end_highlight_lines(w: &mut EmitterWriter,
cm: &codemap::CodeMap,
sp: Span,
Expand Down
2 changes: 2 additions & 0 deletions src/libunicode/char.rs
Expand Up @@ -445,6 +445,8 @@ impl char {
/// [Unicode Standard Annex #11](http://www.unicode.org/reports/tr11/)
/// recommends that these characters be treated as 1 column (i.e.,
/// `is_cjk` = `false`) if the context cannot be reliably determined.
#[deprecated(reason = "use the crates.io `unicode-width` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "needs expert opinion. is_cjk flag stands out as ugly")]
pub fn width(self, is_cjk: bool) -> Option<usize> { charwidth::width(self, is_cjk) }
Expand Down
12 changes: 12 additions & 0 deletions src/libunicode/normalize.rs
Expand Up @@ -33,9 +33,17 @@ fn bsearch_table<T>(c: char, r: &'static [(char, &'static [T])]) -> Option<&'sta
}

/// Compute canonical Unicode decomposition for character
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality will be moved to crates.io")]
pub fn decompose_canonical<F>(c: char, mut i: F) where F: FnMut(char) { d(c, &mut i, false); }

/// Compute canonical or compatible Unicode decomposition for character
#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality will be moved to crates.io")]
pub fn decompose_compatible<F>(c: char, mut i: F) where F: FnMut(char) { d(c, &mut i, true); }

// FIXME(#19596) This is a workaround, we should use `F` instead of `&mut F`
Expand Down Expand Up @@ -78,6 +86,10 @@ fn d<F>(c: char, i: &mut F, k: bool) where F: FnMut(char) {
(*i)(c);
}

#[deprecated(reason = "use the crates.io `unicode-normalization` library instead",
since = "1.0.0")]
#[unstable(feature = "unicode",
reason = "this functionality will be moved to crates.io")]
pub fn compose(a: char, b: char) -> Option<char> {
compose_hangul(a, b).or_else(|| {
match bsearch_table(a, composition_table) {
Expand Down
1 change: 1 addition & 0 deletions src/libunicode/u_str.rs
Expand Up @@ -75,6 +75,7 @@ impl UnicodeStr for str {
#[inline]
fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) }

#[allow(deprecated)]
#[inline]
fn width(&self, is_cjk: bool) -> usize {
self.chars().map(|c| c.width(is_cjk).unwrap_or(0)).sum()
Expand Down

0 comments on commit d14a96c

Please sign in to comment.