Skip to content

Commit

Permalink
docs: add to parse_measure_unit docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kazupon committed Jan 8, 2024
1 parent ee2a664 commit b269954
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub struct UnicodeLanguageIdentifier {
pub variants: Option<Vec<String>>,
}

/// 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).
///
Expand Down
2 changes: 1 addition & 1 deletion src/locale.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
///
Expand Down
25 changes: 22 additions & 3 deletions src/measure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,31 @@ impl FromStr for UnicodeMeasureUnit {
}
}

pub fn parse_unicode_measure_unit(chunk: &str) -> Result<UnicodeMeasureUnit, ParserError> {
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<UnicodeMeasureUnit, ParserError> {
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>(
Expand Down
2 changes: 1 addition & 1 deletion src/subdivision.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
///
Expand Down

0 comments on commit b269954

Please sign in to comment.