aboutsummaryrefslogtreecommitdiff
path: root/rust/libnewsboat-ffi/src/charencoding.rs
blob: c6a06e63d392de52211ad3c388d5f808eb4df035 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use libnewsboat::charencoding;

#[cxx::bridge(namespace = "newsboat::charencoding::bridged")]
mod bridged {
    extern "Rust" {
        fn charset_from_bom(content: &[u8], output: &mut String) -> bool;
        fn charset_from_xml_declaration(content: &[u8], output: &mut String) -> bool;
        fn charset_from_content_type_header(content: &[u8], output: &mut String) -> bool;
    }
}

fn charset_from_bom(content: &[u8], output: &mut String) -> bool {
    match charencoding::charset_from_bom(content) {
        Some(charset) => {
            *output = charset.to_owned();
            true
        }
        None => false,
    }
}

fn charset_from_xml_declaration(content: &[u8], output: &mut String) -> bool {
    match charencoding::charset_from_xml_declaration(content) {
        Some(charset) => {
            *output = charset.to_owned();
            true
        }
        None => false,
    }
}

// Temporarily ignore clippy lint until PR is merged:
// https://github.com/rust-lang/rust-clippy/pull/12756
#[allow(clippy::assigning_clones)]
fn charset_from_content_type_header(content: &[u8], output: &mut String) -> bool {
    match charencoding::charset_from_content_type_header(content) {
        Some(charset) => {
            *output = charset.to_owned();
            true
        }
        None => false,
    }
}