Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor update to encoding detection #90

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src-tauri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ pub fn decode_buffer(buf: Vec<u8>) -> (String, String) {
let actual_encoding = if chardet_encoding == "ascii" && charset_normalizer_encoding == "ascii" {
// Default to UTF-8 if both chardet and charset normalizer detect ASCII
Encoding::for_label("UTF_8".as_bytes()).unwrap_or(UTF_8)
} else if (chardetng_encoding == "gbk"
&& (chardet_encoding == "windows-1255" || charset_normalizer_encoding == "ibm866"))
} else if ((chardet_encoding == "koi8-r" && charset_normalizer_encoding == "koi8-r")
|| chardetng_encoding == "gbk"
&& (chardet_encoding == "windows-1255" || charset_normalizer_encoding == "ibm866"))
|| chardet_encoding == "x-mac-cyrillic"
|| charset_normalizer_encoding == "macintosh"
|| (chardet_encoding == "koi8-r" && charset_normalizer_encoding == "koi8-r")
|| (chardetng_encoding == "iso-8859-2" && chardet_encoding == "iso-8859-1")
{
// Use windows-1251 if both chardet and charset normalizer detect KOI8-R and for various other combinations
// Use windows-1251 for various combinations
Encoding::for_label("windows-1251".as_bytes()).unwrap_or(UTF_8)
} else if (chardetng_encoding == "windows-1252" && chardet_encoding == "windows-1251")
|| (chardet_encoding == "iso-8859-1"
&& (charset_normalizer_encoding == "iso-8859-2"
|| charset_normalizer_encoding == "windows-874"
|| charset_normalizer_encoding == "iso-8859-1"
|| charset_normalizer_encoding == "ibm866"))
|| (chardetng_encoding == "gbk" && chardet_encoding == "iso-8859-1")
|| charset_normalizer_encoding == "ibm866"
|| charset_normalizer_encoding == "euc-kr"))
|| (chardetng_encoding == "shift_jis" && chardet_encoding == "iso-8859-1")
{
// Use windows-1252 for various combinations
Expand Down