Add an nsstring_to_string method
This is a helper to convert `NSString` Objects into Rust `String`, so
that it's easy to parse the parameter passed to application:openFile:
#[cfg(all(target_os = "macos", not(feature="dummy")))]
pub use osx::parse_url_event;
+#[cfg(all(target_os = "macos", not(feature="dummy")))]
+pub use osx::nsstring_to_string;
+
#[cfg(any(not(target_os = "macos"), feature="dummy"))]
/// Docs in OS X build.
pub enum FruitCallbackKey {
}
let subevent: *mut Object = msg_send![event, paramDescriptorForKeyword: ::keyDirectObject];
let nsstring: *mut Object = msg_send![subevent, stringValue];
+ nsstring_to_string(nsstring)
+ }
+}
+
+/// Convert an NSString to a Rust `String`
+pub fn nsstring_to_string(nsstring: *mut Object) -> String {
+ unsafe {
let cstr: *const i8 = msg_send![nsstring, UTF8String];
if cstr != std::ptr::null() {
- let rstr = std::ffi::CStr::from_ptr(cstr).to_string_lossy().into_owned();
- return rstr;
+ std::ffi::CStr::from_ptr(cstr)
+ .to_string_lossy()
+ .into_owned()
+ } else {
+ "".into()
}
}
- "".into()
}
/// ObjcSubclass is a subclass of the objective-c NSObject base class.