diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-10 16:29:02 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-17 18:03:03 -0700 |
| commit | aa88da63179b8ccd3b809e98b489c25199b06cf7 (patch) | |
| tree | f6252e734ef2c02e57ff1d39cfb7b64b145830f5 /src/libsyntax/parse | |
| parent | c64d671671aea2e44ee7fc6eb00ee75fc30ed7b9 (diff) | |
| download | rust-aa88da63179b8ccd3b809e98b489c25199b06cf7.tar.gz rust-aa88da63179b8ccd3b809e98b489c25199b06cf7.zip | |
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`
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer/comments.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer/mod.rs | 16 |
2 files changed, 12 insertions, 11 deletions
diff --git a/src/libsyntax/parse/lexer/comments.rs b/src/libsyntax/parse/lexer/comments.rs index fb9e0480ceb..277f5365db3 100644 --- a/src/libsyntax/parse/lexer/comments.rs +++ b/src/libsyntax/parse/lexer/comments.rs @@ -20,7 +20,6 @@ use parse::lexer; use print::pprust; use std::io::Read; -use std::str; use std::usize; #[derive(Clone, Copy, PartialEq)] @@ -210,11 +209,11 @@ fn all_whitespace(s: &str, col: CharPos) -> Option<usize> { let mut col = col.to_usize(); let mut cursor: usize = 0; while col > 0 && cursor < len { - let r: str::CharRange = s.char_range_at(cursor); - if !r.ch.is_whitespace() { + let ch = s.char_at(cursor); + if !ch.is_whitespace() { return None; } - cursor = r.next; + cursor += ch.len_utf8(); col -= 1; } return Some(cursor); diff --git a/src/libsyntax/parse/lexer/mod.rs b/src/libsyntax/parse/lexer/mod.rs index d9887c28e5c..bb8f9da8917 100644 --- a/src/libsyntax/parse/lexer/mod.rs +++ b/src/libsyntax/parse/lexer/mod.rs @@ -22,7 +22,6 @@ use std::fmt; use std::mem::replace; use std::num; use std::rc::Rc; -use std::str; pub use ext::tt::transcribe::{TtReader, new_tt_reader, new_tt_reader_with_doc_flag}; @@ -291,7 +290,8 @@ impl<'a> StringReader<'a> { s: &'b str, errmsg: &'b str) -> Cow<'b, str> { let mut i = 0; while i < s.len() { - let str::CharRange { ch, next } = s.char_range_at(i); + let ch = s.char_at(i); + let next = i + ch.len_utf8(); if ch == '\r' { if next < s.len() && s.char_at(next) == '\n' { return translate_crlf_(self, start, s, errmsg, i).into_cow(); @@ -309,7 +309,8 @@ impl<'a> StringReader<'a> { let mut buf = String::with_capacity(s.len()); let mut j = 0; while i < s.len() { - let str::CharRange { ch, next } = s.char_range_at(i); + let ch = s.char_at(i); + let next = i + ch.len_utf8(); if ch == '\r' { if j < i { buf.push_str(&s[j..i]); } j = next; @@ -335,10 +336,11 @@ impl<'a> StringReader<'a> { if current_byte_offset < self.source_text.len() { assert!(self.curr.is_some()); let last_char = self.curr.unwrap(); - let next = self.source_text.char_range_at(current_byte_offset); - let byte_offset_diff = next.next - current_byte_offset; + let ch = self.source_text.char_at(current_byte_offset); + let next = current_byte_offset + ch.len_utf8(); + let byte_offset_diff = next - current_byte_offset; self.pos = self.pos + Pos::from_usize(byte_offset_diff); - self.curr = Some(next.ch); + self.curr = Some(ch); self.col = self.col + CharPos(1); if last_char == '\n' { self.filemap.next_line(self.last_pos); @@ -370,7 +372,7 @@ impl<'a> StringReader<'a> { let offset = self.byte_offset(self.pos).to_usize(); let s = &self.source_text[..]; if offset >= s.len() { return None } - let str::CharRange { next, .. } = s.char_range_at(offset); + let next = offset + s.char_at(offset).len_utf8(); if next < s.len() { Some(s.char_at(next)) } else { |
