ruma_identifiers_validation/
room_version_id.rs

1use crate::Error;
2
3/// Room version identifiers cannot be more than 32 code points.
4const MAX_CODE_POINTS: usize = 32;
5
6pub fn validate(s: &str) -> Result<(), Error> {
7    if s.is_empty() {
8        Err(Error::Empty)
9    } else if s.chars().count() > MAX_CODE_POINTS {
10        Err(Error::MaximumLengthExceeded)
11    } else if !s.chars().all(|c| c.is_alphanumeric() || ".-".contains(c)) {
12        Err(Error::InvalidCharacters)
13    } else {
14        Ok(())
15    }
16}