Skip to content

Commit

Permalink
Use Windows-1252 encoding for RTF parsing; fixes #4
Browse files Browse the repository at this point in the history
  • Loading branch information
sammdot committed Mar 6, 2021
1 parent b3173b3 commit 848e02e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ name = "rtfcre"
crate_type = ["cdylib"]

[dependencies]
encoding_rs = "0.8.28"
linked-hash-map = "0.5.3"
lazy_static = "1.4.0"
regex = "1.4.2"
Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::path::PathBuf;
use std::process::exit;
use std::str::FromStr;

use encoding_rs::WINDOWS_1252;
use serde_json::Value;
use structopt::StructOpt;
use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor};
Expand Down Expand Up @@ -135,8 +136,11 @@ fn run_main() -> Result<(), RtfCreError> {

let mut input = File::open(args.input)?;
let mut output = File::create(output)?;
let mut contents = String::new();
input.read_to_string(&mut contents)?;
let mut buf = Vec::new();
input.read_to_end(&mut buf)?;
let (decoded, _, _) = WINDOWS_1252.decode(&buf[..]);
let contents = String::from(decoded);
println!("{:?}", contents);
match direction {
Direction::RtfToJson => {
let dict = match parse_file(&contents) {
Expand Down

0 comments on commit 848e02e

Please sign in to comment.