pub struct ZipString { /* private fields */ }
Expand description
A string wrapper for handling different encodings.
Implementations§
Source§impl ZipString
impl ZipString
Sourcepub fn new(raw: Vec<u8>, encoding: StringEncoding) -> Self
pub fn new(raw: Vec<u8>, encoding: StringEncoding) -> Self
Constructs a new encoded string from its raw bytes and its encoding type.
§Note
If the provided encoding is StringEncoding::Utf8
but the raw bytes are not valid UTF-8 (ie. a call to
std::str::from_utf8()
fails), the encoding is defaulted back to StringEncoding::Raw
.
Sourcepub fn new_with_alternative(utf8: String, alternative: Vec<u8>) -> Self
pub fn new_with_alternative(utf8: String, alternative: Vec<u8>) -> Self
Constructs a new encoded string from utf-8 data, with an alternative in native MBCS encoding.
Sourcepub fn encoding(&self) -> StringEncoding
pub fn encoding(&self) -> StringEncoding
Returns the encoding type for this string.
Sourcepub fn alternative(&self) -> Option<&[u8]>
pub fn alternative(&self) -> Option<&[u8]>
Returns the alternative bytes (in native MBCS encoding) for this string.
Sourcepub fn as_str(&self) -> Result<&str>
pub fn as_str(&self) -> Result<&str>
Returns the raw bytes converted into a string slice.
§Note
A call to this method will only succeed if the encoding type is StringEncoding::Utf8
.
Sourcepub fn into_string(self) -> Result<String>
pub fn into_string(self) -> Result<String>
Returns the raw bytes converted to an owned string.
§Note
A call to this method will only succeed if the encoding type is StringEncoding::Utf8
.
Sourcepub fn into_alternative(self) -> Option<Vec<u8>>
pub fn into_alternative(self) -> Option<Vec<u8>>
Returns the alternative bytes (in native MBCS encoding) converted to the owned.
Sourcepub fn is_utf8_without_alternative(&self) -> bool
pub fn is_utf8_without_alternative(&self) -> bool
Returns whether this string is encoded as utf-8 without an alternative.