ctb_formats_encoding/
encoding.rs

1// SPDX-License-Identifier: AGPL-3.0-or-later
2/*
3This file is part of Collective Toolbox, a database and document workspace and utilities.
4Copyright (C) 2026 Collective Toolbox Developers
5Contact: info@collectivetoolbox.com
6
7This program is free software: you can redistribute it and/or modify it under
8the terms of the GNU Affero General Public License as published by the Free
9Software Foundation, either version 3 of the License, or (at your option) any
10later version.
11
12This program is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more details.
15
16You should have received a copy of the GNU Affero General Public License along
17with this program.  If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Character encoding and decoding definitions.
21
22#[allow(
23    unused_imports,
24    clippy::wildcard_imports,
25    reason = "Standard workspace crate prelude"
26)]
27pub(crate) use ctb_utilities::*;
28
29use include_dir::{Dir, include_dir};
30
31pub mod altura;
32pub mod cp437;
33pub mod line_endings;
34pub mod mapping;
35pub mod neo;
36pub mod standard;
37pub mod unicode;
38
39pub use mapping::{
40    CharEncoding, LineEndingFormat, LineEndingKind, LineEndingOption, LowArea,
41    NeoRegion, SingleByteMapping, TerminationMode, asc, chr, chr_char, decode,
42    decode_with_options, encode, encode_with_options, mapping, transcode,
43};
44
45static ENCODING_DATA_DIR: Dir = include_dir!("$CARGO_MANIFEST_DIR/data");
46
47pub(crate) fn get_encoding_data(key: &str) -> Option<Vec<u8>> {
48    if key.starts_with("fixtures/") {
49        return ctb_utilities::load_manifest_fixture(
50            env!("CARGO_MANIFEST_DIR"),
51            key,
52        );
53    }
54    get_embedded_asset(&ENCODING_DATA_DIR, key)
55}
56
57#[cfg(test)]
58#[allow(
59    clippy::panic,
60    clippy::expect_used,
61    clippy::unwrap_used,
62    clippy::unwrap_in_result,
63    clippy::panic_in_result_fn,
64    clippy::indexing_slicing,
65    clippy::arithmetic_side_effects,
66    reason = "Standard repository test boilerplate"
67)]
68mod tests {
69    use super::*;
70
71    #[crate::ctb_test]
72    fn test_placeholder() {
73        // unless there's a placeholder, the use super::*; will be deleted by
74        // formatting
75        assert!(true);
76    }
77}