Skip to content

Commit

Permalink
change encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
Sreyas-Sreelal committed Sep 2, 2023
1 parent 8b3f36d commit 70fa379
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/encode.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use encoding::all::WINDOWS_1251;
use encoding::all::UTF_8;
use encoding::{EncoderTrap, Encoding};
use std::str::from_utf8;

pub fn encode_replace(string: &str) -> Result<String, ()> {
match WINDOWS_1251.encode(string, EncoderTrap::Replace) {
pub fn encode_replace(string: &str) -> Result<String, String> {
match UTF_8.encode(string, EncoderTrap::Replace) {
Ok(bytes) => match from_utf8(&bytes) {
Ok(data) => Ok(String::from(data)),
Err(_) => Err(()),
Err(e) => Err(e.to_string()),
},
Err(_) => Err(()),
Err(e) => Err(e.to_string()),
}
}

0 comments on commit 70fa379

Please sign in to comment.