Wide string support
This commit is contained in:
parent
345f022678
commit
37991a2363
|
|
@ -71,6 +71,8 @@ fn main() {
|
|||
.blacklist_type("rosidl_message_type_support_t")
|
||||
.blacklist_type("rosidl_generator_c__String")
|
||||
.blacklist_type("rosidl_generator_c__String__Sequence")
|
||||
.blacklist_type("rosidl_generator_c__U16String")
|
||||
.blacklist_type("rosidl_generator_c__U16String__Sequence")
|
||||
.blacklist_type("rosidl_generator_c__float32__Sequence")
|
||||
.blacklist_type("rosidl_generator_c__float__Sequence")
|
||||
.blacklist_type("rosidl_generator_c__float64__Sequence")
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ fn field_type(t: u8) -> String {
|
|||
// move to common
|
||||
if t == (rosidl_typesupport_introspection_c__ROS_TYPE_STRING as u8) {
|
||||
"std::string::String".to_owned()
|
||||
} else if t == (rosidl_typesupport_introspection_c__ROS_TYPE_WSTRING as u8) {
|
||||
"std::string::String".to_owned()
|
||||
} else if t == (rosidl_typesupport_introspection_c__ROS_TYPE_BOOLEAN as u8) {
|
||||
"bool".to_owned()
|
||||
} else if t == (rosidl_typesupport_introspection_c__ROS_TYPE_CHAR as u8) {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ edition = "2018"
|
|||
[dependencies]
|
||||
libc = "0.2.0"
|
||||
paste = "0.1.6"
|
||||
widestring = "0.4.0"
|
||||
|
||||
[build-dependencies]
|
||||
bindgen = "0.50.0"
|
||||
|
|
|
|||
|
|
@ -54,6 +54,45 @@ impl rosidl_generator_c__String {
|
|||
}
|
||||
}
|
||||
|
||||
use widestring::U16String;
|
||||
impl rosidl_generator_c__U16String {
|
||||
pub fn to_str(&self) -> String {
|
||||
let s = unsafe { U16String::from_ptr(self.data, self.size) };
|
||||
// U16Str = U16String::from_ptr(buffer, strlen as usize);
|
||||
// let s = unsafe { CStr::from_ptr(self.data as *mut i8) };
|
||||
//s.to_str().unwrap_or("")
|
||||
s.to_string_lossy()
|
||||
}
|
||||
|
||||
pub fn assign(&mut self, other: &str) -> () {
|
||||
let wstr = U16String::from_str(other);
|
||||
let to_send_ptr = wstr.as_ptr() as *const uint_least16_t;
|
||||
unsafe {
|
||||
rosidl_generator_c__U16String__assignn(self as *mut _, to_send_ptr, wstr.len());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl rosidl_generator_c__U16String__Sequence {
|
||||
pub fn update(&mut self, values: &[String]) {
|
||||
unsafe { rosidl_generator_c__U16String__Sequence__fini(self as *mut _); }
|
||||
unsafe { rosidl_generator_c__U16String__Sequence__init(self as *mut _, values.len()); }
|
||||
let strs = unsafe { std::slice::from_raw_parts_mut(self.data, values.len()) };
|
||||
for (target, source) in strs.iter_mut().zip(values) {
|
||||
target.assign(&source);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to_vec(&self) -> Vec<String> {
|
||||
let mut target = Vec::with_capacity(self.size);
|
||||
let strs = unsafe { std::slice::from_raw_parts(self.data, self.size) };
|
||||
for s in strs {
|
||||
target.push(s.to_str().to_owned());
|
||||
}
|
||||
target
|
||||
}
|
||||
}
|
||||
|
||||
impl rosidl_generator_c__String__Sequence {
|
||||
pub fn update(&mut self, values: &[String]) {
|
||||
unsafe { rosidl_generator_c__String__Sequence__fini(self as *mut _); }
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@
|
|||
#include <rosidl_generator_c/string.h>
|
||||
#include <rosidl_generator_c/string_functions.h>
|
||||
|
||||
#include <rosidl_generator_c/u16string.h>
|
||||
#include <rosidl_generator_c/u16string_functions.h>
|
||||
|
||||
#include <rosidl_generator_c/primitives_sequence.h>
|
||||
#include <rosidl_generator_c/primitives_sequence_functions.h>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue