escape chars (#321)
* escape chars * heart char constant in tests * translate Rust unicode representation to C style unicode representation * apply rustfmt * check char constant length * nicer code Signed-off-by: Axel Nennker <axel.nennker@telekom.de>
This commit is contained in:
@@ -151,7 +151,10 @@ impl Literal {
|
||||
syn::Expr::Lit(syn::ExprLit {
|
||||
lit: syn::Lit::Char(ref value),
|
||||
..
|
||||
}) => Ok(Literal::Expr(format!("'{}'", value.value()))),
|
||||
}) => Ok(Literal::Expr(match value.value() as u32 {
|
||||
0..=255 => format!("'{}'", value.value().escape_default()),
|
||||
other_code => format!(r"L'\u{:X}'", other_code),
|
||||
})),
|
||||
syn::Expr::Lit(syn::ExprLit {
|
||||
lit: syn::Lit::Int(ref value),
|
||||
..
|
||||
|
||||
@@ -7,6 +7,16 @@
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define HEART L'\u2764'
|
||||
|
||||
#define LEFTCURLY '{'
|
||||
|
||||
#define NEWLINE '\n'
|
||||
|
||||
#define QUOTE '\''
|
||||
|
||||
#define TAB '\t'
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
typedef struct Foo {
|
||||
|
||||
@@ -7,6 +7,16 @@
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define HEART L'\u2764'
|
||||
|
||||
#define LEFTCURLY '{'
|
||||
|
||||
#define NEWLINE '\n'
|
||||
|
||||
#define QUOTE '\''
|
||||
|
||||
#define TAB '\t'
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
typedef struct {
|
||||
|
||||
@@ -6,6 +6,16 @@ static const wchar_t DELIMITER = ':';
|
||||
|
||||
static const int32_t FOO = 10;
|
||||
|
||||
static const wchar_t HEART = L'\u2764';
|
||||
|
||||
static const wchar_t LEFTCURLY = '{';
|
||||
|
||||
static const wchar_t NEWLINE = '\n';
|
||||
|
||||
static const wchar_t QUOTE = '\'';
|
||||
|
||||
static const wchar_t TAB = '\t';
|
||||
|
||||
static const float ZOM = 3.14;
|
||||
|
||||
struct Foo {
|
||||
|
||||
@@ -7,6 +7,16 @@
|
||||
|
||||
#define FOO 10
|
||||
|
||||
#define HEART L'\u2764'
|
||||
|
||||
#define LEFTCURLY '{'
|
||||
|
||||
#define NEWLINE '\n'
|
||||
|
||||
#define QUOTE '\''
|
||||
|
||||
#define TAB '\t'
|
||||
|
||||
#define ZOM 3.14
|
||||
|
||||
struct Foo {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
const FOO: i32 = 10;
|
||||
const BAR: &'static str = "hello world";
|
||||
pub const DELIMITER: char = ':';
|
||||
pub const LEFTCURLY: char = '{';
|
||||
pub const QUOTE: char = '\'';
|
||||
pub const TAB: char = '\t';
|
||||
pub const NEWLINE: char = '\n';
|
||||
pub const HEART: char = '❤';
|
||||
const ZOM: f32 = 3.14;
|
||||
|
||||
#[repr(C)]
|
||||
|
||||
Reference in New Issue
Block a user