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:
Emilio Cobos Álvarez
2019-04-15 19:11:23 +02:00
committed by GitHub
6 changed files with 49 additions and 1 deletions
+4 -1
View File
@@ -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),
..
+10
View File
@@ -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 {
+10
View File
@@ -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 {
+10
View File
@@ -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 {
+10
View File
@@ -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 {
+5
View File
@@ -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)]