1#![no_std]
2#![cfg_attr(not(any(target_arch = "wasm32", feature = "wasm")), forbid(unsafe_code))]
3#![deny(missing_docs)]
4#![cfg_attr(docsrs, feature(doc_cfg))]
5extern crate alloc;
13
14pub mod shape;
16pub mod ubidi;
18
19pub use shape::*;
20pub use ubidi::*;
21
22#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
23use alloc::vec::Vec;
24#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
25use core::mem;
26#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
27use lol_alloc::{AssumeSingleThreaded, FreeListAllocator};
28
29#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
31#[global_allocator]
32static ALLOCATOR: AssumeSingleThreaded<FreeListAllocator> =
33 unsafe { AssumeSingleThreaded::new(FreeListAllocator::new()) };
34
35#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
37mod wasm_specific {
38 #[panic_handler]
39 fn panic(_info: &core::panic::PanicInfo) -> ! {
40 loop {}
41 }
42}
43
44#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
46extern "C" {
47 fn setUnicodeArray(ptr: *const u16, size: usize);
48}
49
50#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
54#[no_mangle]
55pub unsafe extern "C" fn processText(input_ptr: *const u16, len: usize, options: u32) {
56 let input_slice = core::slice::from_raw_parts(input_ptr, len);
58 let result_vec = shape_unicode(input_slice, &options);
60 setUnicodeArray(result_vec.as_ptr(), result_vec.len());
62}
63
64#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
68#[no_mangle]
69pub unsafe extern "C" fn allocUnicodeArray(size: usize) -> *mut u16 {
70 let mut buffer: Vec<u16> = Vec::with_capacity(size);
72 buffer.capacity();
73 buffer.set_len(size);
75 let ptr = buffer.as_mut_ptr();
77 mem::forget(buffer);
79
80 ptr
81}
82
83#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
87#[no_mangle]
88pub unsafe extern "C" fn free(ptr: *mut u16, size: usize) {
89 let _ = core::slice::from_raw_parts_mut(ptr, size);
91
92 alloc::alloc::dealloc(ptr as *mut u8, alloc::alloc::Layout::array::<u16>(size).unwrap());
94}
95
96#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
98#[no_mangle]
99pub extern "C" fn isRTL(input: u16) -> bool {
100 is_rtl(&input)
101}
102
103#[cfg(any(target_arch = "wasm32", feature = "wasm"))]
105#[no_mangle]
106pub extern "C" fn isCJK(input: u16) -> bool {
107 is_cjk(&input)
109}