Implement the actual encoding selector. There are currently only two encodings in the selector used as placeholders, but more will be added in the future. As of now, the encoding picker is not actually triggered.
This commit is contained in:
parent
fae2f8ff1c
commit
5723987b59
10 changed files with 453 additions and 191 deletions
21
crates/fs/src/encodings.rs
Normal file
21
crates/fs/src/encodings.rs
Normal file
|
@ -0,0 +1,21 @@
|
|||
use encoding::Encoding;
|
||||
|
||||
pub enum CharacterEncoding {
|
||||
Utf8,
|
||||
Iso8859_1,
|
||||
Cp865,
|
||||
}
|
||||
|
||||
pub fn to_utf8<'a>(input: Vec<u8>, encoding: &'a impl encoding::Encoding) -> String {
|
||||
match encoding.decode(&input, encoding::DecoderTrap::Strict) {
|
||||
Ok(v) => return v,
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn to<'a>(input: String, target: &'a impl encoding::Encoding) -> Vec<u8> {
|
||||
match target.encode(&input, encoding::EncoderTrap::Strict) {
|
||||
Ok(v) => v,
|
||||
Err(_) => panic!(),
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue