From 99cb2a4aba70ebe032195e55c9e1902aa40d7ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Tyrychtr?= Date: Sun, 26 Mar 2023 04:06:57 +0200 Subject: [PATCH] Replace unmaitained encoding crate with encoding_rs (#222) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Lukáš Tyrychtr --- Cargo.toml | 2 +- src/document.rs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 67778ab..f688353 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ chrono = { version = "^0.4", optional = true, features = [ "std", "clock", ], default-features = false } -encoding = "^0.2" +encoding_rs = "0.8.32" flate2 = "^1.0" image = { version = "^0.24", optional = true } itoa = "^1.0" diff --git a/src/document.rs b/src/document.rs index d79d233..f597390 100644 --- a/src/document.rs +++ b/src/document.rs @@ -2,8 +2,7 @@ use super::encodings::{self, bytes_to_string, string_to_bytes}; use super::{Bookmark, Dictionary, Object, ObjectId}; use crate::xref::{Xref, XrefType}; use crate::{Error, Result, Stream}; -use encoding::all::UTF_16BE; -use encoding::types::{DecoderTrap, EncoderTrap, Encoding}; +use encoding_rs::UTF_16BE; use log::info; use std::cmp::max; use std::collections::{BTreeMap, HashMap}; @@ -433,7 +432,7 @@ impl Document { "MacRomanEncoding" => bytes_to_string(encodings::MAC_ROMAN_ENCODING, bytes), "MacExpertEncoding" => bytes_to_string(encodings::MAC_EXPERT_ENCODING, bytes), "WinAnsiEncoding" => bytes_to_string(encodings::WIN_ANSI_ENCODING, bytes), - "UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.decode(bytes, DecoderTrap::Ignore).unwrap(), + "UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.decode(bytes).0.to_string(), "Identity-H" => "?Identity-H Unimplemented?".to_string(), // Unimplemented _ => String::from_utf8_lossy(bytes).to_string(), } @@ -449,7 +448,7 @@ impl Document { "MacRomanEncoding" => string_to_bytes(encodings::MAC_ROMAN_ENCODING, text), "MacExpertEncoding" => string_to_bytes(encodings::MAC_EXPERT_ENCODING, text), "WinAnsiEncoding" => string_to_bytes(encodings::WIN_ANSI_ENCODING, text), - "UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.encode(text, EncoderTrap::Ignore).unwrap(), + "UniGB-UCS2-H" | "UniGB−UTF16−H" => UTF_16BE.encode(text).0.to_vec(), "Identity-H" => vec![], // Unimplemented _ => text.as_bytes().to_vec(), }