deno.land / std@0.224.0 / cli / testdata / unicode_width_crate / src / lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
use libc::c_char;use std::ffi::CStr;use serde_json;use unicode_width::UnicodeWidthStr;
fn from_c_char(ptr: *const c_char) -> &'static str { let c_str = unsafe { assert!(!ptr.is_null());
CStr::from_ptr(ptr) }; return c_str.to_str().unwrap();}
#[no_mangle]pub extern "C" fn unicode_width(json_str: *const c_char) -> usize { let json_str = from_c_char(json_str);
serde_json::from_str::<String>(json_str).unwrap().width()}
std

Version Info

Tagged at
6 months ago