diff --git a/src/bindgen/ir/constant.rs b/src/bindgen/ir/constant.rs index f92ddc0..565484d 100644 --- a/src/bindgen/ir/constant.rs +++ b/src/bindgen/ir/constant.rs @@ -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), .. diff --git a/tests/expectations/both/constant.c b/tests/expectations/both/constant.c index 26993fe..719eebf 100644 --- a/tests/expectations/both/constant.c +++ b/tests/expectations/both/constant.c @@ -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 { diff --git a/tests/expectations/constant.c b/tests/expectations/constant.c index 4e4b6d3..2448224 100644 --- a/tests/expectations/constant.c +++ b/tests/expectations/constant.c @@ -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 { diff --git a/tests/expectations/constant.cpp b/tests/expectations/constant.cpp index f81fabe..14aa8ab 100644 --- a/tests/expectations/constant.cpp +++ b/tests/expectations/constant.cpp @@ -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 { diff --git a/tests/expectations/tag/constant.c b/tests/expectations/tag/constant.c index 0208c5d..60702cc 100644 --- a/tests/expectations/tag/constant.c +++ b/tests/expectations/tag/constant.c @@ -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 { diff --git a/tests/rust/constant.rs b/tests/rust/constant.rs index 4464306..eb32bc7 100644 --- a/tests/rust/constant.rs +++ b/tests/rust/constant.rs @@ -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)]