Skip to content

Commit 5b327c7

Browse files
hrideshmgcanihavesomecoffee
authored andcommitted
fix: replace iconv with encoding_rs
1 parent 17247da commit 5b327c7

File tree

3 files changed

+23
-20
lines changed

3 files changed

+23
-20
lines changed

src/rust/Cargo.lock

Lines changed: 10 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ crate-type = ["staticlib"]
1313
[dependencies]
1414
log = "0.4.26"
1515
env_logger = "0.8.4"
16-
iconv = "0.1.1"
1716
palette = "0.6.1"
1817
rsmpeg = { version = "0.14.2", optional = true, features = [
1918
"link_system_ffmpeg",
@@ -28,6 +27,7 @@ cfg-if = "1.0.0"
2827
num-integer = "0.1.46"
2928
lib_ccxr = { path = "lib_ccxr" }
3029
url = "2.5.4"
30+
encoding_rs = "0.8.5"
3131

3232
[build-dependencies]
3333
bindgen = "0.64.0"

src/rust/src/decoder/tv_screen.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use crate::{
1717
bindings::*,
1818
utils::{is_false, is_true},
1919
};
20+
use encoding_rs::Encoding;
2021

2122
use log::{debug, warn};
2223

@@ -232,8 +233,17 @@ impl dtvcc_tv_screen {
232233
};
233234
debug!("Charset: {}", charset);
234235

235-
let op = iconv::decode(&buf, charset).map_err(|err| err.to_string())?;
236-
writer.write_to_file(op.as_bytes())?;
236+
// Look up the encoding by label (name)
237+
if let Some(encoding) = Encoding::for_label(charset.as_bytes()) {
238+
let (cow, _encoding_used, had_errors) = encoding.decode(&buf);
239+
if had_errors {
240+
println!("Warning: Had errors during encoding from {charset} to UTF-8");
241+
}
242+
if _encoding_used != encoding {
243+
println!("Warning: Encoding specified ({}) does not match encoding detected ({})",charset,_encoding_used.name());
244+
}
245+
writer.write_to_file(cow.as_bytes())?;
246+
}
237247
}
238248
} else {
239249
writer.write_to_file(&buf)?;

0 commit comments

Comments
 (0)