mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Store hex digits in a stack-allocated buffer
This commit is contained in:
parent
c56db92d1f
commit
fdb9f06880
2 changed files with 45 additions and 5 deletions
|
@ -5,6 +5,7 @@ use crate::{
|
|||
ast::{self, AstNode},
|
||||
File,
|
||||
string_lexing::{self, CharComponentKind},
|
||||
utils::MutAsciiString,
|
||||
yellow::{
|
||||
SyntaxError,
|
||||
SyntaxErrorKind::*,
|
||||
|
@ -73,12 +74,18 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
|
|||
return;
|
||||
}
|
||||
|
||||
let mut code = String::new();
|
||||
let mut buf = &mut [0; 6];
|
||||
let mut code = MutAsciiString::new(buf);
|
||||
let mut closed = false;
|
||||
for c in text[3..].chars() {
|
||||
assert!(!closed, "no characters after escape is closed");
|
||||
|
||||
if c.is_digit(16) {
|
||||
if code.len() == 6 {
|
||||
errors.push(SyntaxError::new(OverlongUnicodeEscape, range));
|
||||
return;
|
||||
}
|
||||
|
||||
code.push(c);
|
||||
} else if c == '_' {
|
||||
// Reject leading _
|
||||
|
@ -103,10 +110,6 @@ fn validate_char(node: ast::Char, errors: &mut Vec<SyntaxError>) {
|
|||
return;
|
||||
}
|
||||
|
||||
if code.len() > 6 {
|
||||
errors.push(SyntaxError::new(OverlongUnicodeEscape, range));
|
||||
}
|
||||
|
||||
match u32::from_str_radix(&code, 16) {
|
||||
Ok(code_u32) if code_u32 > 0x10FFFF => {
|
||||
errors.push(SyntaxError::new(UnicodeEscapeOutOfRange, range));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue