use super::*;
pub const INPUT_EMPTY: u32 = 0;
pub const OUTPUT_FULL: u32 = 0xFFFFFFFF;
pub const ENCODING_NAME_MAX_LENGTH: usize = super::LONGEST_NAME_LENGTH;
pub struct ConstEncoding(*const Encoding);
unsafe impl Sync for ConstEncoding {}
#[no_mangle]
pub static BIG5_ENCODING: ConstEncoding = ConstEncoding(BIG5);
#[no_mangle]
pub static EUC_JP_ENCODING: ConstEncoding = ConstEncoding(EUC_JP);
#[no_mangle]
pub static EUC_KR_ENCODING: ConstEncoding = ConstEncoding(EUC_KR);
#[no_mangle]
pub static GBK_ENCODING: ConstEncoding = ConstEncoding(GBK);
#[no_mangle]
pub static IBM866_ENCODING: ConstEncoding = ConstEncoding(IBM866);
#[no_mangle]
pub static ISO_2022_JP_ENCODING: ConstEncoding = ConstEncoding(ISO_2022_JP);
#[no_mangle]
pub static ISO_8859_10_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_10);
#[no_mangle]
pub static ISO_8859_13_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_13);
#[no_mangle]
pub static ISO_8859_14_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_14);
#[no_mangle]
pub static ISO_8859_15_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_15);
#[no_mangle]
pub static ISO_8859_16_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_16);
#[no_mangle]
pub static ISO_8859_2_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_2);
#[no_mangle]
pub static ISO_8859_3_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_3);
#[no_mangle]
pub static ISO_8859_4_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_4);
#[no_mangle]
pub static ISO_8859_5_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_5);
#[no_mangle]
pub static ISO_8859_6_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_6);
#[no_mangle]
pub static ISO_8859_7_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_7);
#[no_mangle]
pub static ISO_8859_8_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_8);
#[no_mangle]
pub static ISO_8859_8_I_ENCODING: ConstEncoding = ConstEncoding(ISO_8859_8_I);
#[no_mangle]
pub static KOI8_R_ENCODING: ConstEncoding = ConstEncoding(KOI8_R);
#[no_mangle]
pub static KOI8_U_ENCODING: ConstEncoding = ConstEncoding(KOI8_U);
#[no_mangle]
pub static SHIFT_JIS_ENCODING: ConstEncoding = ConstEncoding(SHIFT_JIS);
#[no_mangle]
pub static UTF_16BE_ENCODING: ConstEncoding = ConstEncoding(UTF_16BE);
#[no_mangle]
pub static UTF_16LE_ENCODING: ConstEncoding = ConstEncoding(UTF_16LE);
#[no_mangle]
pub static UTF_8_ENCODING: ConstEncoding = ConstEncoding(UTF_8);
#[no_mangle]
pub static GB18030_ENCODING: ConstEncoding = ConstEncoding(GB18030);
#[no_mangle]
pub static MACINTOSH_ENCODING: ConstEncoding = ConstEncoding(MACINTOSH);
#[no_mangle]
pub static REPLACEMENT_ENCODING: ConstEncoding = ConstEncoding(REPLACEMENT);
#[no_mangle]
pub static WINDOWS_1250_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1250);
#[no_mangle]
pub static WINDOWS_1251_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1251);
#[no_mangle]
pub static WINDOWS_1252_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1252);
#[no_mangle]
pub static WINDOWS_1253_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1253);
#[no_mangle]
pub static WINDOWS_1254_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1254);
#[no_mangle]
pub static WINDOWS_1255_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1255);
#[no_mangle]
pub static WINDOWS_1256_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1256);
#[no_mangle]
pub static WINDOWS_1257_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1257);
#[no_mangle]
pub static WINDOWS_1258_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_1258);
#[no_mangle]
pub static WINDOWS_874_ENCODING: ConstEncoding = ConstEncoding(WINDOWS_874);
#[no_mangle]
pub static X_MAC_CYRILLIC_ENCODING: ConstEncoding = ConstEncoding(X_MAC_CYRILLIC);
#[no_mangle]
pub static X_USER_DEFINED_ENCODING: ConstEncoding = ConstEncoding(X_USER_DEFINED);
impl CoderResult {
fn as_u32(&self) -> u32 {
match self {
&CoderResult::InputEmpty => INPUT_EMPTY,
&CoderResult::OutputFull => OUTPUT_FULL,
}
}
}
impl DecoderResult {
fn as_u32(&self) -> u32 {
match self {
&DecoderResult::InputEmpty => INPUT_EMPTY,
&DecoderResult::OutputFull => OUTPUT_FULL,
&DecoderResult::Malformed(bad, good) => ((good as u32) << 8) | (bad as u32),
}
}
}
impl EncoderResult {
fn as_u32(&self) -> u32 {
match self {
&EncoderResult::InputEmpty => INPUT_EMPTY,
&EncoderResult::OutputFull => OUTPUT_FULL,
&EncoderResult::Unmappable(c) => c as u32,
}
}
}
fn option_to_ptr(opt: Option<&'static Encoding>) -> *const Encoding {
match opt {
None => ::std::ptr::null(),
Some(e) => e,
}
}
#[no_mangle]
pub unsafe extern "C" fn encoding_for_label(label: *const u8, label_len: usize) -> *const Encoding {
let label_slice = ::std::slice::from_raw_parts(label, label_len);
option_to_ptr(Encoding::for_label(label_slice))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_for_label_no_replacement(label: *const u8,
label_len: usize)
-> *const Encoding {
let label_slice = ::std::slice::from_raw_parts(label, label_len);
option_to_ptr(Encoding::for_label_no_replacement(label_slice))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_for_name(name: *const u8, name_len: usize) -> *const Encoding {
let name_slice = ::std::slice::from_raw_parts(name, name_len);
option_to_ptr(Encoding::for_name(name_slice))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_for_bom(buffer: *const u8, buffer_len: usize) -> *const Encoding {
let buffer_slice = ::std::slice::from_raw_parts(buffer, buffer_len);
option_to_ptr(Encoding::for_bom(buffer_slice))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_name(encoding: *const Encoding, name_out: *mut u8) -> usize {
let bytes = (*encoding).name().as_bytes();
::std::ptr::copy_nonoverlapping(bytes.as_ptr(), name_out, bytes.len());
bytes.len()
}
#[no_mangle]
pub unsafe extern "C" fn encoding_can_encode_everything(encoding: *const Encoding) -> bool {
(*encoding).can_encode_everything()
}
#[no_mangle]
pub unsafe extern "C" fn encoding_is_ascii_compatible(encoding: *const Encoding) -> bool {
(*encoding).is_ascii_compatible()
}
#[no_mangle]
pub unsafe extern "C" fn encoding_output_encoding(encoding: *const Encoding) -> *const Encoding {
(*encoding).output_encoding()
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_decoder(encoding: *const Encoding) -> *mut Decoder {
Box::into_raw(Box::new((*encoding).new_decoder()))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_decoder_with_bom_removal(encoding: *const Encoding)
-> *mut Decoder {
Box::into_raw(Box::new((*encoding).new_decoder_with_bom_removal()))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_decoder_without_bom_handling(encoding: *const Encoding)
-> *mut Decoder {
Box::into_raw(Box::new((*encoding).new_decoder_without_bom_handling()))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_decoder_into(encoding: *const Encoding,
decoder: *mut Decoder) {
*decoder = (*encoding).new_decoder();
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_decoder_with_bom_removal_into(encoding: *const Encoding,
decoder: *mut Decoder) {
*decoder = (*encoding).new_decoder_with_bom_removal();
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_decoder_without_bom_handling_into(encoding: *const Encoding,
decoder: *mut Decoder) {
*decoder = (*encoding).new_decoder_without_bom_handling();
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_encoder(encoding: *const Encoding) -> *mut Encoder {
Box::into_raw(Box::new((*encoding).new_encoder()))
}
#[no_mangle]
pub unsafe extern "C" fn encoding_new_encoder_into(encoding: *const Encoding,
encoder: *mut Encoder) {
*encoder = (*encoding).new_encoder();
}
#[no_mangle]
pub unsafe extern "C" fn decoder_free(decoder: *mut Decoder) {
let _ = Box::from_raw(decoder);
}
#[no_mangle]
pub unsafe extern "C" fn decoder_encoding(decoder: *const Decoder) -> *const Encoding {
(*decoder).encoding()
}
#[no_mangle]
pub unsafe extern "C" fn decoder_max_utf16_buffer_length(decoder: *const Decoder,
u16_length: usize)
-> usize {
(*decoder).max_utf16_buffer_length(u16_length)
}
#[no_mangle]
pub unsafe extern "C" fn decoder_max_utf8_buffer_length_without_replacement(decoder: *const Decoder,
byte_length: usize)
-> usize {
(*decoder).max_utf8_buffer_length_without_replacement(byte_length)
}
#[no_mangle]
pub unsafe extern "C" fn decoder_max_utf8_buffer_length(decoder: *const Decoder,
byte_length: usize)
-> usize {
(*decoder).max_utf8_buffer_length(byte_length)
}
#[no_mangle]
pub unsafe extern "C" fn decoder_decode_to_utf16_without_replacement(decoder: *mut Decoder,
src: *const u8,
src_len: *mut usize,
dst: *mut u16,
dst_len: *mut usize,
last: bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written) = (*decoder).decode_to_utf16_without_replacement(src_slice,
dst_slice,
last);
*src_len = read;
*dst_len = written;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn decoder_decode_to_utf8_without_replacement(decoder: *mut Decoder,
src: *const u8,
src_len: *mut usize,
dst: *mut u8,
dst_len: *mut usize,
last: bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written) = (*decoder).decode_to_utf8_without_replacement(src_slice,
dst_slice,
last);
*src_len = read;
*dst_len = written;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn decoder_decode_to_utf16(decoder: *mut Decoder,
src: *const u8,
src_len: *mut usize,
dst: *mut u16,
dst_len: *mut usize,
last: bool,
had_replacements: *mut bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written, replaced) = (*decoder).decode_to_utf16(src_slice, dst_slice, last);
*src_len = read;
*dst_len = written;
*had_replacements = replaced;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn decoder_decode_to_utf8(decoder: *mut Decoder,
src: *const u8,
src_len: *mut usize,
dst: *mut u8,
dst_len: *mut usize,
last: bool,
had_replacements: *mut bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written, replaced) = (*decoder).decode_to_utf8(src_slice, dst_slice, last);
*src_len = read;
*dst_len = written;
*had_replacements = replaced;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn encoder_free(encoder: *mut Encoder) {
let _ = Box::from_raw(encoder);
}
#[no_mangle]
pub unsafe extern "C" fn encoder_encoding(encoder: *const Encoder) -> *const Encoding {
(*encoder).encoding()
}
#[no_mangle]
pub unsafe extern "C" fn encoder_max_buffer_length_from_utf16_without_replacement(encoder: *const Encoder,
u16_length: usize)
-> usize {
(*encoder).max_buffer_length_from_utf16_without_replacement(u16_length)
}
#[no_mangle]
pub unsafe extern "C" fn encoder_max_buffer_length_from_utf8_without_replacement(encoder: *const Encoder,
byte_length: usize)
-> usize {
(*encoder).max_buffer_length_from_utf8_without_replacement(byte_length)
}
#[no_mangle]
pub unsafe extern "C" fn encoder_max_buffer_length_from_utf16_if_no_unmappables
(encoder: *const Encoder,
u16_length: usize)
-> usize {
(*encoder).max_buffer_length_from_utf16_if_no_unmappables(u16_length)
}
#[no_mangle]
pub unsafe extern "C" fn encoder_max_buffer_length_from_utf8_if_no_unmappables
(encoder: *const Encoder,
byte_length: usize)
-> usize {
(*encoder).max_buffer_length_from_utf8_if_no_unmappables(byte_length)
}
#[no_mangle]
pub unsafe extern "C" fn encoder_encode_from_utf16_without_replacement(encoder: *mut Encoder,
src: *const u16,
src_len: *mut usize,
dst: *mut u8,
dst_len: *mut usize,
last: bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written) = (*encoder).encode_from_utf16_without_replacement(src_slice,
dst_slice,
last);
*src_len = read;
*dst_len = written;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn encoder_encode_from_utf8_without_replacement(encoder: *mut Encoder,
src: *const u8,
src_len: *mut usize,
dst: *mut u8,
dst_len: *mut usize,
last: bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let string = ::std::str::from_utf8_unchecked(src_slice);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written) = (*encoder).encode_from_utf8_without_replacement(string,
dst_slice,
last);
*src_len = read;
*dst_len = written;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn encoder_encode_from_utf16(encoder: *mut Encoder,
src: *const u16,
src_len: *mut usize,
dst: *mut u8,
dst_len: *mut usize,
last: bool,
had_replacements: *mut bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written, replaced) = (*encoder)
.encode_from_utf16(src_slice, dst_slice, last);
*src_len = read;
*dst_len = written;
*had_replacements = replaced;
result.as_u32()
}
#[no_mangle]
pub unsafe extern "C" fn encoder_encode_from_utf8(encoder: *mut Encoder,
src: *const u8,
src_len: *mut usize,
dst: *mut u8,
dst_len: *mut usize,
last: bool,
had_replacements: *mut bool)
-> u32 {
let src_slice = ::std::slice::from_raw_parts(src, *src_len);
let string = ::std::str::from_utf8_unchecked(src_slice);
let dst_slice = ::std::slice::from_raw_parts_mut(dst, *dst_len);
let (result, read, written, replaced) = (*encoder).encode_from_utf8(string, dst_slice, last);
*src_len = read;
*dst_len = written;
*had_replacements = replaced;
result.as_u32()
}