Make LanguageTag::private_use return the private use subtag even if

the tag is only composed of private use subtags
pull/10/head
Tpt 6 years ago
parent 6ae3795a31
commit 9f6f3ca6d7
  1. 8
      lib/src/model/language_tag.rs

@ -134,7 +134,9 @@ impl LanguageTag {
/// Return the [private use subtags](https://tools.ietf.org/html/rfc5646#section-2.2.7).
#[inline]
pub fn private_use(&self) -> Option<&str> {
if self.extension_end == self.serialization.len() {
if self.serialization.starts_with("x-") {
Some(&self.serialization)
} else if self.extension_end == self.serialization.len() {
None
} else {
Some(&self.serialization[self.extension_end + 1..])
@ -903,6 +905,10 @@ fn test_privateuse() {
("el", Some("x-koine"), vec!["koine"]),
parts(&LanguageTag::from_str("el-x-koine").unwrap())
);
assert_eq!(
("x-fr-ch", Some("x-fr-ch"), vec!["fr", "ch"]),
parts(&LanguageTag::from_str("x-fr-ch").unwrap())
);
}
// Tests from RFC 5646 2.2.9

Loading…
Cancel
Save