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-uax29 crate

3. str.nfd_chars(), str.nfkd_chars(), str.nfc_chars(), str.nfkc_chars():
   use unicode-decomp crate
  • Loading branch information
kwantam committed Apr 14, 2015
1 parent dabf0c6 commit 1e709bf
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/libcollections/str.rs
Expand Up @@ -161,6 +161,8 @@ enum DecompositionType {
/// External iterator for a string decomposition's characters.
///
/// For use with the `std::iter` module.
#[deprecated(reason = "use the crates.io `unicode-decomp` library instead",
since = "1.0.0-nightly-20150415")]
#[derive(Clone)]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand Down Expand Up @@ -254,6 +256,8 @@ enum RecompositionState {
/// External iterator for a string recomposition's characters.
///
/// For use with the `std::iter` module.
#[deprecated(reason = "use the crates.io `unicode-decomp` library instead",
since = "1.0.0-nightly-20150415")]
#[derive(Clone)]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand Down Expand Up @@ -465,6 +469,8 @@ impl str {

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

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

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

/// An Iterator over the string in Unicode Normalization Form KC
/// (compatibility decomposition followed by canonical composition).
#[deprecated(reason = "use the crates.io `unicode-decomp` library instead",
since = "1.0.0-nightly-20150415")]
#[inline]
#[unstable(feature = "unicode",
reason = "this functionality may be replaced with a more generic \
Expand Down Expand Up @@ -1690,6 +1702,8 @@ impl str {
///
/// assert_eq!(&gr2[..], b);
/// ```
#[deprecated(reason = "use the crates.io `unicode-uax29` library instead",
since = "1.0.0-nightly-20150415")]
#[unstable(feature = "unicode",
reason = "this functionality may only be provided by libunicode")]
pub fn graphemes(&self, is_extended: bool) -> Graphemes {
Expand All @@ -1709,6 +1723,8 @@ impl str {
///
/// assert_eq!(&gr_inds[..], b);
/// ```
#[deprecated(reason = "use the crates.io `unicode-uax29` library instead",
since = "1.0.0-nightly-20150415")]
#[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 +1765,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-nightly-20150415")]
#[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-nightly-20150415")]
#[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
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 1e709bf

Please sign in to comment.