extern "C" {
fn simdutf_change_endianness_utf16(src: *const u16, len: usize, dst: *mut u16);
fn simdutf_autodetect_encoding(src: *const u8, len: usize) -> u32;
fn simdutf_detect_encodings(src: *const u8, len: usize) -> u32;
}
#[inline]
pub unsafe fn change_endianness_utf16(src: *const u16, len: usize, dst: *mut u16) {
simdutf_change_endianness_utf16(src, len, dst);
}
bitflags::bitflags! {
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct Encoding: u32 {
const UNSPECIFIED = 0;
const UTF8 = 1;
const UTF16_LE = 2;
const UTF16_BE = 4;
const UTF32_LE = 8;
const UTF32_BE = 16;
}
}
#[inline]
#[must_use]
pub fn autodetect_single_encoding(src: &[u8]) -> Encoding {
unsafe {
let ans = simdutf_autodetect_encoding(src.as_ptr(), src.len());
Encoding::from_bits_retain(ans)
}
}
#[inline]
#[must_use]
pub fn autodetect_encodings(src: &[u8]) -> Encoding {
unsafe {
let ans = simdutf_detect_encodings(src.as_ptr(), src.len());
Encoding::from_bits_retain(ans)
}
}
#[repr(C)]
#[derive(Debug, Clone, Copy)]
pub struct Result {
pub error: ErrorCode,
pub count: usize,
}
#[repr(u32)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum ErrorCode {
Success = 0,
HeaderBits = 1,
TooShort = 2,
TooLong = 3,
OverLong = 4,
TooLarge = 5,
Surrogate = 6,
InvalidBase64Character = 7,
Base64InputRemainder = 8,
Base64ExtraBits = 9,
OutputBufferTooSmall = 10,
Other = 11,
}
#[repr(u64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum Base64Options {
Default = 0,
Url = 1,
DefaultNoPadding = 2,
UrlWithPadding = 3,
DefaultAcceptGarbage = 4,
UrlAcceptGarbage = 5,
DefaultOrUrl = 8,
DefaultOrUrlAcceptGarbage = 12,
}
#[repr(u64)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum LastChunkHandlingOptions {
Loose = 0,
Strict = 1,
StopBeforePartial = 2,
OnlyFullChunks = 3,
}