Convert code to text-size

This commit is contained in:
Aleksey Kladov
2020-04-24 23:40:41 +02:00
parent 27a7718880
commit b1d5817dd1
75 changed files with 438 additions and 456 deletions

View File

@@ -2,7 +2,7 @@
use crate::{
ast::{AstToken, Comment, RawString, String, Whitespace},
TextRange, TextUnit,
TextRange, TextSize,
};
impl Comment {
@@ -94,14 +94,14 @@ impl QuoteOffsets {
return None;
}
let start = TextUnit::from(0);
let left_quote = TextUnit::from_usize(left_quote) + TextUnit::of_char('"');
let right_quote = TextUnit::from_usize(right_quote);
let end = TextUnit::of_str(literal);
let start = TextSize::from(0);
let left_quote = TextSize::from_usize(left_quote) + TextSize::of('"');
let right_quote = TextSize::from_usize(right_quote);
let end = TextSize::of(literal);
let res = QuoteOffsets {
quotes: [TextRange::from_to(start, left_quote), TextRange::from_to(right_quote, end)],
contents: TextRange::from_to(left_quote, right_quote),
quotes: [TextRange::new(start, left_quote), TextRange::new(right_quote, end)],
contents: TextRange::new(left_quote, right_quote),
};
Some(res)
}
@@ -168,7 +168,7 @@ impl HasStringValue for RawString {
impl RawString {
pub fn map_range_up(&self, range: TextRange) -> Option<TextRange> {
let contents_range = self.text_range_between_quotes()?;
assert!(range.is_subrange(&TextRange::offset_len(0.into(), contents_range.len())));
assert!(TextRange::up_to(contents_range.len()).contains_range(range));
Some(range + contents_range.start())
}
}
@@ -459,7 +459,7 @@ pub trait HasFormatSpecifier: AstToken {
while let Some((r, Ok(next_char))) = chars.peek() {
if next_char.is_ascii_digit() {
chars.next();
range = range.extend_to(r);
range = range.cover(*r);
} else {
break;
}
@@ -477,7 +477,7 @@ pub trait HasFormatSpecifier: AstToken {
while let Some((r, Ok(next_char))) = chars.peek() {
if *next_char == '_' || next_char.is_ascii_digit() || next_char.is_alphabetic() {
chars.next();
range = range.extend_to(r);
range = range.cover(*r);
} else {
break;
}
@@ -498,10 +498,8 @@ impl HasFormatSpecifier for String {
let mut res = Vec::with_capacity(text.len());
rustc_lexer::unescape::unescape_str(text, &mut |range, unescaped_char| {
res.push((
TextRange::from_to(
TextUnit::from_usize(range.start),
TextUnit::from_usize(range.end),
) + offset,
TextRange::new(TextSize::from_usize(range.start), TextSize::from_usize(range.end))
+ offset,
unescaped_char,
))
});
@@ -521,10 +519,8 @@ impl HasFormatSpecifier for RawString {
let mut res = Vec::with_capacity(text.len());
for (idx, c) in text.char_indices() {
res.push((
TextRange::from_to(
TextUnit::from_usize(idx),
TextUnit::from_usize(idx + c.len_utf8()),
) + offset,
TextRange::new(TextSize::from_usize(idx), TextSize::from_usize(idx + c.len_utf8()))
+ offset,
Ok(c),
));
}