diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-30 03:57:31 +0000 |
commit | dc0db358abe19481e475e10c32149b53370f1a1c (patch) | |
tree | ab8ce99c4b255ce46f99ef402c27916055b899ee /vendor/ucd-parse/src/extracted/derived_name.rs | |
parent | Releasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff) | |
download | rustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip |
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/ucd-parse/src/extracted/derived_name.rs')
-rw-r--r-- | vendor/ucd-parse/src/extracted/derived_name.rs | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/ucd-parse/src/extracted/derived_name.rs b/vendor/ucd-parse/src/extracted/derived_name.rs new file mode 100644 index 000000000..713a2afee --- /dev/null +++ b/vendor/ucd-parse/src/extracted/derived_name.rs @@ -0,0 +1,61 @@ +use std::path::Path; +use std::str::FromStr; + +use crate::common::{ + parse_codepoint_association, CodepointIter, Codepoints, UcdFile, + UcdFileByCodepoint, +}; +use crate::error::Error; + +/// A single row in the `extracted/DerivedName.txt` file. +/// +/// This file gives the derived values of the Name property. +#[derive(Clone, Debug, Default, Eq, PartialEq)] +pub struct DerivedName { + /// The codepoint or codepoint range for this entry. + pub codepoints: Codepoints, + /// The derived Name of the codepoints in this entry. + pub name: String, +} + +impl UcdFile for DerivedName { + fn relative_file_path() -> &'static Path { + Path::new("extracted/DerivedName.txt") + } +} + +impl UcdFileByCodepoint for DerivedName { + fn codepoints(&self) -> CodepointIter { + self.codepoints.into_iter() + } +} + +impl FromStr for DerivedName { + type Err = Error; + + fn from_str(line: &str) -> Result<DerivedName, Error> { + let (codepoints, name) = parse_codepoint_association(line)?; + Ok(DerivedName { codepoints, name: name.to_string() }) + } +} + +#[cfg(test)] +mod tests { + use super::DerivedName; + + #[test] + fn parse_single() { + let line = "0021 ; EXCLAMATION MARK\n"; + let row: DerivedName = line.parse().unwrap(); + assert_eq!(row.codepoints, 0x0021); + assert_eq!(row.name, "EXCLAMATION MARK"); + } + + #[test] + fn parse_range() { + let line = "3400..4DBF ; CJK UNIFIED IDEOGRAPH-*\n"; + let row: DerivedName = line.parse().unwrap(); + assert_eq!(row.codepoints, (0x3400, 0x4DBF)); + assert_eq!(row.name, "CJK UNIFIED IDEOGRAPH-*"); + } +} |