mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Use u32 more
This commit is contained in:
parent
8012acc90e
commit
d683e22021
1 changed files with 4 additions and 6 deletions
|
@ -66,7 +66,7 @@ impl WideChar {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the length in UTF-16 or UTF-32 code units.
|
/// Returns the length in UTF-16 or UTF-32 code units.
|
||||||
fn wide_len(&self, enc: WideEncoding) -> usize {
|
fn wide_len(&self, enc: WideEncoding) -> u32 {
|
||||||
match enc {
|
match enc {
|
||||||
WideEncoding::Utf16 => {
|
WideEncoding::Utf16 => {
|
||||||
if self.len() == TextSize::from(4) {
|
if self.len() == TextSize::from(4) {
|
||||||
|
@ -75,7 +75,6 @@ impl WideChar {
|
||||||
1
|
1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
WideEncoding::Utf32 => 1,
|
WideEncoding::Utf32 => 1,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -157,12 +156,11 @@ impl LineIndex {
|
||||||
|
|
||||||
/// Transforms the `LineCol` with the given `WideEncoding` into a `WideLineCol`.
|
/// Transforms the `LineCol` with the given `WideEncoding` into a `WideLineCol`.
|
||||||
pub fn to_wide(&self, enc: WideEncoding, line_col: LineCol) -> Option<WideLineCol> {
|
pub fn to_wide(&self, enc: WideEncoding, line_col: LineCol) -> Option<WideLineCol> {
|
||||||
let col: TextSize = line_col.col.into();
|
let mut col = line_col.col;
|
||||||
let mut res: usize = col.into();
|
|
||||||
if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) {
|
if let Some(wide_chars) = self.line_wide_chars.get(&line_col.line) {
|
||||||
for c in wide_chars.iter() {
|
for c in wide_chars.iter() {
|
||||||
if u32::from(c.end) <= line_col.col {
|
if u32::from(c.end) <= line_col.col {
|
||||||
res -= usize::from(c.len()) - c.wide_len(enc);
|
col -= u32::from(c.len()) - c.wide_len(enc);
|
||||||
} else {
|
} else {
|
||||||
// From here on, all utf16 characters come *after* the character we are mapping,
|
// From here on, all utf16 characters come *after* the character we are mapping,
|
||||||
// so we don't need to take them into account
|
// so we don't need to take them into account
|
||||||
|
@ -170,7 +168,7 @@ impl LineIndex {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(WideLineCol { line: line_col.line, col: res as u32 })
|
Some(WideLineCol { line: line_col.line, col })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Transforms the `WideLineCol` with the given `WideEncoding` into a `LineCol`.
|
/// Transforms the `WideLineCol` with the given `WideEncoding` into a `LineCol`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue