#![no_std]
#![cfg_attr(not(any(target_arch = "wasm32", feature = "wasm")), forbid(unsafe_code))]
#![deny(missing_docs)]
#![cfg_attr(docsrs, feature(doc_cfg))]
extern crate alloc;
pub mod shape;
pub mod ubidi;
pub use shape::*;
pub use ubidi::*;
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
use alloc::vec::Vec;
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
use core::mem;
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
use lol_alloc::{AssumeSingleThreaded, FreeListAllocator};
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
#[global_allocator]
static ALLOCATOR: AssumeSingleThreaded<FreeListAllocator> =
unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) };
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
mod wasm_specific {
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
}
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
extern "C" {
fn setUnicodeArray(ptr: *const u16, size: usize);
}
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
#[no_mangle]
pub unsafe extern "C" fn processText(input_ptr: *const u16, len: usize, options: u32) {
let input_slice = core::slice::from_raw_parts(input_ptr, len);
let result_vec = shape_unicode(input_slice, &options);
setUnicodeArray(result_vec.as_ptr(), result_vec.len());
}
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
#[no_mangle]
pub unsafe extern "C" fn allocUnicodeArray(size: usize) -> *mut u16 {
let mut buffer: Vec<u16> = Vec::with_capacity(size);
buffer.capacity();
buffer.set_len(size);
let ptr = buffer.as_mut_ptr();
mem::forget(buffer);
ptr
}
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
#[no_mangle]
pub unsafe extern "C" fn free(ptr: *mut u16, size: usize) {
let _ = core::slice::from_raw_parts_mut(ptr, size);
alloc::alloc::dealloc(ptr as *mut u8, alloc::alloc::Layout::array::<u16>(size).unwrap());
}
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
#[no_mangle]
pub extern "C" fn isRTL(input: u16) -> bool {
is_rtl(&input)
}
#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
#[no_mangle]
pub extern "C" fn isCJK(input: u16) -> bool {
is_cjk(&input)
}