From b269954d70b1a4f1b5bb4c8b6eec872dfb64f2e8 Mon Sep 17 00:00:00 2001 From: kazuya kawaguchi Date: Tue, 9 Jan 2024 01:06:18 +0900 Subject: [PATCH] docs: add to `parse_measure_unit` docs --- src/lang.rs | 2 +- src/locale.rs | 2 +- src/measure.rs | 25 ++++++++++++++++++++++--- src/subdivision.rs | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/lang.rs b/src/lang.rs index e171761..be7fcfc 100644 --- a/src/lang.rs +++ b/src/lang.rs @@ -15,7 +15,7 @@ pub struct UnicodeLanguageIdentifier { pub variants: Option>, } -/// Parse the given string as a Unicode Language Identifier. +/// Parse the given string as an Unicode Language Identifier. /// /// This function parses according to [`unicode_language_id` EBNF defined in UTS #35](https://unicode.org/reports/tr35/#unicode_language_id). /// diff --git a/src/locale.rs b/src/locale.rs index ad67130..aee58b9 100644 --- a/src/locale.rs +++ b/src/locale.rs @@ -35,7 +35,7 @@ impl FromStr for UnicodeLocaleIdentifier { } } -/// Parse the given string as a Unicode Locale Identifier. +/// Parse the given string as an Unicode Locale Identifier. /// /// This function parses according to [`unicode_locale_id` EBNF defined in UTS #35](https://unicode.org/reports/tr35/#unicode_locale_id) /// diff --git a/src/measure.rs b/src/measure.rs index b1aa33e..b281d9c 100644 --- a/src/measure.rs +++ b/src/measure.rs @@ -30,12 +30,31 @@ impl FromStr for UnicodeMeasureUnit { } } -pub fn parse_unicode_measure_unit(chunk: &str) -> Result { - if chunk.is_empty() { +/// Parse the given string as an Unicode Measure Unit +/// +/// This function parses according to [`unicode_measure_unit` EBNF defined in UTS #35](https://unicode.org/reports/tr35/#unicode_measure_unit) +/// +/// # Examples +/// +/// ``` +/// use unicode_locale_parser::parse_measure_unit; +/// +/// let measure = parse_measure_unit("area-hectare").unwrap(); +/// assert_eq!(vec!["area", "hectare"], measure.values); +/// ``` +/// +/// # Errors +/// +/// This function returns an error in the following cases: +/// +/// - [`ParserError::Missing`] if the given measure unit is empty. +/// - [`ParserError::InvalidSubtag`] if the given measure unit is not a valid. +pub fn parse_unicode_measure_unit(measure_unit: &str) -> Result { + if measure_unit.is_empty() { return Err(ParserError::Missing); } - parse_unicode_measure_unit_from_iter(&mut split_str(chunk).peekable()) + parse_unicode_measure_unit_from_iter(&mut split_str(measure_unit).peekable()) } fn parse_unicode_measure_unit_from_iter<'a>( diff --git a/src/subdivision.rs b/src/subdivision.rs index 8f52807..044ea5a 100644 --- a/src/subdivision.rs +++ b/src/subdivision.rs @@ -25,7 +25,7 @@ impl FromStr for UnicodeSubdivisionIdentifier { } } -/// Parse the given string as a Unicode Subdivision Identifier. +/// Parse the given string as an Unicode Subdivision Identifier. /// /// This function parses according to [`unicode_subdivision_id` EBNF defined in UTS #35](https://unicode.org/reports/tr35/#unicode_subdivision_id) ///