feat: align sizes

上级 d9f0d8a3
......@@ -23,7 +23,6 @@
use std::os::raw::c_int;
use std::ptr::null;
use std::{error, fmt, str};
/// This struture represents an error from the underlying Oniguruma libray.
......@@ -37,9 +36,9 @@ impl ScieOnigError {
ScieOnigError::new(code, info)
}
fn from_code(code: c_int) -> ScieOnigError {
ScieOnigError::new(code, null())
}
// fn from_code(code: c_int) -> ScieOnigError {
// ScieOnigError::new(code, null())
// }
fn new(code: c_int, info: *const onig_sys::OnigErrorInfo) -> ScieOnigError {
let buff = &mut [0; onig_sys::ONIG_MAX_ERROR_MESSAGE_LEN as usize];
......
......@@ -70,7 +70,7 @@ mod tests {
#[test]
fn it_works() {
ScieOnig::demo_new(r"^");
let _result = ScieOnig::demo_new(r"^");
assert!(true)
}
}
use unicode_segmentation::UnicodeSegmentation;
#[derive(Clone, Debug)]
pub struct OnigString {
pub utf16length: i32,
pub utf8length: i32,
pub utf16value: String,
pub utf8value: Vec<u8>,
pub utf16offset_to_utf8: Option<Vec<u32>>,
pub utf8offset_to_utf16: Option<Vec<u32>>,
pub utf16length: i32,
pub utf8length: i32,
pub utf16value: String,
pub utf8value: Vec<u8>,
pub utf16offset_to_utf8: Option<Vec<u32>>,
pub utf8offset_to_utf16: Option<Vec<u32>>,
}
impl OnigString {
pub fn new(str: String) -> Self {
let utf16length = str.len();
let utf8_str = str.graphemes(true).collect::<Vec<&str>>().clone();
println!("{:?}", utf8_str);
let utf8length = utf8_str.len();
let mut utf16_vec: Vec<u16> = str.encode_utf16().collect();
let utf16length = utf16_vec.len();
// let utf8_str = str.graphemes(true).collect::<Vec<&str>>().clone();
let utf8length = str.len();
let utf8value = str.clone().into_bytes();
OnigString {
utf16length: utf16length as i32,
utf8length: utf8length as i32,
utf16value: "".to_string(),
utf8value: vec![],
utf16value: str.clone(),
utf8value,
utf16offset_to_utf8: None,
utf8offset_to_utf16: None
}
......@@ -37,7 +38,9 @@ mod tests {
#[test]
fn it_show_works_works() {
let onig_string = OnigString::new(String::from("a💻bYX"));
assert_eq!(8, onig_string.utf16length);
assert_eq!(5, onig_string.utf8length);
println!("{:?}", onig_string);
assert_eq!(6, onig_string.utf16length);
assert_eq!(8, onig_string.utf8length);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册