use crate::charutils::*;
use crate::error::*;
pub const ESCAPE_MAP: [u8; 256] = [
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0x2f, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x5c, 0, 0, 0,
0, 0, 0x08, 0, 0, 0, 0x0c, 0, 0, 0, 0, 0, 0, 0, 0x0a, 0,
0, 0, 0x0d, 0, 0x09, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
#[cfg_attr(not(feature = "no-inline"), inline(always))]
pub fn handle_unicode_codepoint(
mut src_ptr: &[u8],
dst_ptr: &mut [u8],
) -> Result<(usize, usize), ErrorType> {
let mut code_point: u32 = hex_to_u32_nocheck(unsafe { src_ptr.get_unchecked(2..) });
src_ptr = unsafe { src_ptr.get_unchecked(6..) };
let mut src_offset = 6;
if code_point >= 0xd800 && code_point < 0xdc00 {
if (unsafe { *src_ptr.get_unchecked(0) } != b'\\')
|| unsafe { *src_ptr.get_unchecked(1) } != b'u'
{
return Ok((0, src_offset));
}
let code_point_2: u32 = hex_to_u32_nocheck(unsafe { src_ptr.get_unchecked(2..) });
if ((code_point | code_point_2) >> 16) != 0 {
return Ok((0, src_offset));
}
let c1 = if let Some(c) = code_point.checked_sub(0xd800) {
c
} else {
return Err(ErrorType::InvalidUTF8);
};
let c2 = if let Some(c) = code_point_2.checked_sub(0xdc00) {
c
} else {
return Err(ErrorType::InvalidUTF8);
};
code_point = ((c1 << 10) | c2) + 0x10000;
src_offset += 6;
}
let offset: usize = codepoint_to_utf8(code_point, dst_ptr);
Ok((offset, src_offset))
}