pub struct DecodedString {
pub encoding: &'static dyn Encoding,
pub characters: Vec<DecodedCharacter>,
}
Expand description
A string that has been decoded using a particular character encoding.
Fields§
§encoding: &'static dyn Encoding
§characters: Vec<DecodedCharacter>
Implementations§
Source§impl DecodedString
impl DecodedString
Sourcepub fn decode(
string: &[u8],
encoding: EncodingRef,
) -> Result<DecodedString, Cow<'static, str>>
pub fn decode( string: &[u8], encoding: EncodingRef, ) -> Result<DecodedString, Cow<'static, str>>
Decode a sequence of bytes using a particular encoding.
Any characters that cannot be encoded will be represented using unicode replacement characters (U+FFFD).
§Errors
Returns an error if anything goes wrong with the underlying decoder. This shouldn’t actually happen(?)
Sourcepub fn format_bytes(&self) -> String
pub fn format_bytes(&self) -> String
Format the byte representation of the string using hex.
Sourcepub fn format_characters(&self) -> String
pub fn format_characters(&self) -> String
Format the string in an easy to understand way. ASCII characters are rendered normally. Tabs, carriage returns and newlines are represented as escape sequences. All other characters are rendered as their unicode codepoints.
§Limitations
This is not guaranteed to work properly if codepoints in hex are longer than the number of bytes used to represent it in the encoding; for example, latin characters in UTF-16.
Sourcepub fn wrap_lines(&self, max_line_width: usize) -> Vec<DecodedString>
pub fn wrap_lines(&self, max_line_width: usize) -> Vec<DecodedString>
Split into chunks so that the output of format_bytes and format_characters
fit within max_line_width
characters for each chunk.