From aa88da63179b8ccd3b809e98b489c25199b06cf7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 10 Mar 2015 16:29:02 -0700 Subject: std: Tweak some unstable features of `str` This commit clarifies some of the unstable features in the `str` module by moving them out of the blanket `core` and `collections` features. The following methods were moved to the `str_char` feature which generally encompasses decoding specific characters from a `str` and dealing with the result. It is unclear if any of these methods need to be stabilized for 1.0 and the most conservative route for now is to continue providing them but to leave them as unstable under a more specific name. * `is_char_boundary` * `char_at` * `char_range_at` * `char_at_reverse` * `char_range_at_reverse` * `slice_shift_char` The following methods were moved into the generic `unicode` feature as they are specifically enabled by the `unicode` crate itself. * `nfd_chars` * `nfkd_chars` * `nfc_chars` * `graphemes` * `grapheme_indices` * `width` --- src/libunicode/u_str.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'src/libunicode') diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index 917c2d2dfbe..0fbc98ea73c 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -244,7 +244,7 @@ impl<'a> Iterator for Graphemes<'a> { } self.cat = if take_curr { - idx = self.string.char_range_at(idx).next; + idx = idx + len_utf8(self.string.char_at(idx)); None } else { Some(cat) @@ -256,6 +256,11 @@ impl<'a> Iterator for Graphemes<'a> { } } +#[cfg(stage0)] +fn len_utf8(c: char) -> usize { UCharExt::len_utf8(c) } +#[cfg(not(stage0))] +fn len_utf8(c: char) -> usize { c.len_utf8() } + impl<'a> DoubleEndedIterator for Graphemes<'a> { #[inline] fn next_back(&mut self) -> Option<&'a str> { -- cgit 1.4.1-3-g733a5