Function icu_data::ucm::request_mapping_file [−][src]
pub fn request_mapping_file(mapping: &str) -> Result<String, IcuDataError>
Expand description
Given the name of an encoding known to ICU, return its raw UCM data as a String.
You should not request encoding filenames (with .ucm
), but it’ll still be understood.
Internally, this function considers 105 byte arrays stored as static strings. It takes the name
of the mapping and looks it up in CHARSET_LOOKUP
, which tells it what byte array contains the
mapping. For example, CHARSET_LOOKUP["ibm-737_P100-1997.ucm"]
is 58
. So, we know that
BYTES_58
contains the file. BYTES_58
is defined as:
include_bytes!("../../resources/brotli/ibm-737_P100-1997ibm-775_P100-1996ibm-803_P100-1999ibm-806_P100-1998ibm-808_P100-1999ibm-813_P100-1995ibm-819_P100-1999ibm-833_P100-1995ibm-834_P100-1995ibm-834_X100-1995.ucm.tar.b");
So, we un-Brotli compress the data in BYTES_58
and then send it through a .tar
file parser.
We iterate through the metadata entries until we find one equal to ibm-737_P100-1997.ucm
. We
then clone that data to a String
type because only the compressed versions are owned in
memory and return.
This function returns a Result<_, _>
type because users may provide unknown mappings. The
only error you should ever receive is IcuDataError::UnknownMappingRequested
, all the valid
mappings have been tested and decompress on my machine.