[−][src]Enum oem_cp::code_table_type::TableType
Wrapper enumerate for decoding tables
It has 2 types: Complete
, complete tables (it doesn't have undefined codepoints) / Incomplete
, incomplete tables (does have ones)
Variants
complete table, which doen't have any undefined codepoints
incomplete table, which has some undefined codepoints
Implementations
impl TableType
[src]
pub fn decode_string_checked<'a, T: Into<Cow<'a, [u8]>>>(
&self,
src: T
) -> Option<String>
[src]
&self,
src: T
) -> Option<String>
Wrapper function for decoding bytes encoded in SBCSs
This function returns None
if any bytes bumps into undefined codepoints
Arguments
src
- bytes encoded in SBCS
Examples
use oem_cp::code_table::{DECODING_TABLE_CP437, DECODING_TABLE_CP874}; use oem_cp::code_table_type::TableType; use TableType::{Complete,Incomplete}; assert_eq!(Complete(&DECODING_TABLE_CP437).decode_string_checked(vec![0xFB, 0xAC, 0x3D, 0xAB]), Some("√¼=½".to_string())); // means shrimp in Thai (U+E49 => 0xE9) assert_eq!(Incomplete(&DECODING_TABLE_CP874).decode_string_checked(vec![0xA1, 0xD8, 0xE9, 0xA7]), Some("กุ้ง".to_string())); // 0xDB-0xDE,0xFC-0xFF is invalid in CP874 in Windows (strict mode) assert_eq!(Incomplete(&DECODING_TABLE_CP874).decode_string_checked(vec![0x30, 0xDB]), None);
pub fn decode_string_lossy<'a, T: Into<Cow<'a, [u8]>>>(&self, src: T) -> String
[src]
Wrapper function for decoding bytes encoded in SBCSs
Undefined codepoints are replaced with U+FFFD.
Arguments
src
- bytes encoded in SBCS
Examples
use oem_cp::code_table::{DECODING_TABLE_CP437, DECODING_TABLE_CP874}; use oem_cp::code_table_type::TableType; use TableType::{Complete,Incomplete}; assert_eq!(Complete(&DECODING_TABLE_CP437).decode_string_lossy(vec![0xFB, 0xAC, 0x3D, 0xAB]), "√¼=½".to_string()); // means shrimp in Thai (U+E49 => 0xE9) assert_eq!(Incomplete(&DECODING_TABLE_CP874).decode_string_lossy(vec![0xA1, 0xD8, 0xE9, 0xA7]), "กุ้ง".to_string()); // 0xDB-0xDE,0xFC-0xFF is invalid in CP874 in Windows (strict mode) assert_eq!(Incomplete(&DECODING_TABLE_CP874).decode_string_lossy(vec![0x30, 0xDB]), "0\u{FFFD}".to_string());
Auto Trait Implementations
impl RefUnwindSafe for TableType
impl Send for TableType
impl Sync for TableType
impl Unpin for TableType
impl UnwindSafe for TableType
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,