Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: modifying all string handling functions to uniform UTF-16 handling
- Loading branch information
1 parent
1a25f6b
commit 19573b4
Showing
5 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod function; | |
pub mod object_calculate; | ||
pub mod object_generate; | ||
pub mod pointer; | ||
pub mod string; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
use napi::{JsString, Result}; | ||
use std::ffi::CString; | ||
|
||
pub fn js_string_to_string(js_string: JsString) -> Result<String> { | ||
let s: String = js_string.into_utf16()?.try_into()?; | ||
Ok(s) | ||
} | ||
|
||
pub unsafe fn string_to_c_string(s: String) -> CString { | ||
let mut bytes = s.into_bytes(); | ||
bytes.push(0); | ||
let c_string = CString::from_vec_unchecked(bytes); | ||
c_string | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters