Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/syntax/src/ast/token_ext.rs')
-rw-r--r--crates/syntax/src/ast/token_ext.rs64
1 files changed, 32 insertions, 32 deletions
diff --git a/crates/syntax/src/ast/token_ext.rs b/crates/syntax/src/ast/token_ext.rs
index 44e49d6d44..b39006e2ff 100644
--- a/crates/syntax/src/ast/token_ext.rs
+++ b/crates/syntax/src/ast/token_ext.rs
@@ -478,6 +478,38 @@ impl Radix {
}
}
+impl ast::Char {
+ pub fn value(&self) -> Option<char> {
+ let mut text = self.text();
+ if text.starts_with('\'') {
+ text = &text[1..];
+ } else {
+ return None;
+ }
+ if text.ends_with('\'') {
+ text = &text[0..text.len() - 1];
+ }
+
+ unescape_char(text).ok()
+ }
+}
+
+impl ast::Byte {
+ pub fn value(&self) -> Option<u8> {
+ let mut text = self.text();
+ if text.starts_with("b\'") {
+ text = &text[2..];
+ } else {
+ return None;
+ }
+ if text.ends_with('\'') {
+ text = &text[0..text.len() - 1];
+ }
+
+ unescape_byte(text).ok()
+ }
+}
+
#[cfg(test)]
mod tests {
use crate::ast::{self, make, FloatNumber, IntNumber};
@@ -579,35 +611,3 @@ bcde", b"abcde",
check_int_value("1_1_1_1_1_1", 111111);
}
}
-
-impl ast::Char {
- pub fn value(&self) -> Option<char> {
- let mut text = self.text();
- if text.starts_with('\'') {
- text = &text[1..];
- } else {
- return None;
- }
- if text.ends_with('\'') {
- text = &text[0..text.len() - 1];
- }
-
- unescape_char(text).ok()
- }
-}
-
-impl ast::Byte {
- pub fn value(&self) -> Option<u8> {
- let mut text = self.text();
- if text.starts_with("b\'") {
- text = &text[2..];
- } else {
- return None;
- }
- if text.ends_with('\'') {
- text = &text[0..text.len() - 1];
- }
-
- unescape_byte(text).ok()
- }
-}