mirror of https://github.com/boa-dev/boa.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
427 B
16 lines
427 B
2 years ago
|
use proc_macro::TokenStream;
|
||
|
use quote::quote;
|
||
|
use syn::{parse_macro_input, LitStr};
|
||
|
|
||
|
/// Construct a utf-16 array literal from a utf-8 [`str`] literal.
|
||
|
#[proc_macro]
|
||
|
pub fn utf16(input: TokenStream) -> TokenStream {
|
||
|
let literal = parse_macro_input!(input as LitStr);
|
||
|
let utf8 = literal.value();
|
||
|
let utf16 = utf8.encode_utf16().collect::<Vec<_>>();
|
||
|
quote! {
|
||
|
[#(#utf16),*].as_slice()
|
||
|
}
|
||
|
.into()
|
||
|
}
|