How swc handle UTF-8 string #7701
-
Hi, I am new to Rust and I am reading SWC source code to learn how to build a Rust parser. I encounter some issues with UTF-8 string. It is ok to iterate UTF-8 string with use swc_common::input::{StringInput, Input};
use swc_common::BytePos;
fn main() {
let utf8_str = "中文字串";
let mut input = StringInput::new("中文字串", BytePos(0), BytePos(utf8_str.len().try_into().unwrap()));
println!("{:?}", input.slice(BytePos(0), BytePos(3))); // want to slice string like input.slice(BytePos(0), BytePos(1)) to get frist utf-8 char not bytes
println!("{:?}", &utf8_str[0..3]);
} |
Beta Was this translation helpful? Give feedback.
Answered by
kdy1
Jul 25, 2023
Replies: 1 comment 3 replies
-
Lines 110 to 112 in 11efd4e |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
kdy1
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
swc/crates/testing/src/lib.rs
Lines 110 to 112 in 11efd4e
swc/crates/swc_ecma_parser/examples/parse-all.rs
Line 25 in 11efd4e