jvmti_rs/wrapper/decoder.rs
1use cesu8::from_java_cesu8;
2use log::error;
3use std::borrow::Cow;
4use std::os::raw::c_char;
5use std::ffi::CStr;
6
7pub fn to_modified_utf8<'a>(input: *const c_char) -> Cow<'a, str> {
8 unsafe {
9 let bytes = CStr::from_ptr(input).to_bytes();
10 match from_java_cesu8(bytes) {
11 Ok(s) => s,
12 Err(e) => {
13 error!("error decoding java cesu8: {:#?}", e);
14 String::from_utf8_lossy(bytes)
15 }
16 }
17 }
18}