use crate::rubysys::{
constant::{FL_USER_8, FL_USER_9},
types::{
c_char, c_int, size_t, CallbackPtr, EncodingIndex, EncodingType, InternalValue, RBasic,
Value,
},
};
use std::mem;
pub const ENC_DUMMY_FLAG: isize = 1 << 24;
pub const ENC_INDEX_MASK: isize = !(!0 << 24);
pub const ENC_CODERANGE_UNKNOWN: isize = 0;
pub const ENC_CODERANGE_7BIT: isize = FL_USER_8;
pub const ENC_CODERANGE_VALID: isize = FL_USER_9;
pub const ENC_CODERANGE_BROKEN: isize = FL_USER_8 | FL_USER_9;
pub const ENC_CODERANGE_MASK: isize =
ENC_CODERANGE_7BIT | ENC_CODERANGE_VALID | ENC_CODERANGE_BROKEN;
extern "C" {
pub fn rb_enc_associate(obj: Value, enc: EncodingType) -> Value;
pub fn rb_enc_associate_index(obj: Value, idx: c_int) -> Value;
pub fn rb_enc_compatible(str1: Value, str2: Value) -> EncodingType;
pub fn rb_enc_default_external() -> Value;
pub fn rb_enc_default_internal() -> Value;
pub fn rb_enc_find_index(name: *const c_char) -> EncodingIndex;
pub fn rb_enc_from_encoding(encoding: EncodingType) -> Value;
pub fn rb_enc_from_index(index: EncodingIndex) -> EncodingType;
pub fn rb_enc_get_index(obj: Value) -> EncodingIndex;
pub fn rb_enc_set_index(obj: Value, encindex: EncodingIndex);
pub fn rb_enc_set_default_external(encoding: Value);
pub fn rb_enc_set_default_internal(encoding: Value);
pub fn rb_filesystem_encindex() -> EncodingIndex;
pub fn rb_locale_encindex() -> EncodingIndex;
pub fn rb_obj_encoding(obj: Value) -> Value;
pub fn rb_to_encoding(enc: Value) -> EncodingType;
pub fn rb_to_encoding_index(obj: Value) -> EncodingIndex;
pub fn rb_usascii_encindex() -> EncodingIndex;
pub fn rb_utf8_encindex() -> EncodingIndex;
pub fn rb_str_export_to_enc(str: Value, enc: EncodingType) -> Value;
pub fn rb_str_encode(str: Value, to: Value, ecflags: c_int, ecopts: Value) -> Value;
pub fn rb_econv_prepare_opts(opthash: Value, opts: *const Value) -> c_int;
pub fn rb_enc_codepoint_len(
ptr: *const c_char,
end: *const c_char,
len_p: *mut c_int,
enc: EncodingType,
) -> size_t;
}
pub unsafe fn coderange_set(obj: Value, code_range: InternalValue) {
let basic: *mut RBasic = mem::transmute(obj.value);
(*basic).flags = ((*basic).flags & !(ENC_CODERANGE_MASK as InternalValue)) | code_range
}
pub unsafe fn coderange_clear(obj: Value) {
coderange_set(obj, 0)
}