jid: Simplify *Part parsing

Reuse the main JID parsing blocks for the separate parts.
This commit is contained in:
Emmanuel Gil Peyrot 2025-02-05 21:41:17 +01:00
commit 7e260dd677
2 changed files with 7 additions and 27 deletions

View file

@ -16,19 +16,12 @@ pub enum Error {
/// Happens when the node is empty, that is the string starts with a @.
NodeEmpty,
/// Happens when there is no domain, that is either the string is empty,
/// starts with a /, or contains the @/ sequence.
DomainEmpty,
/// Happens when the resource is empty, that is the string ends with a /.
ResourceEmpty,
/// Happens when the localpart is longer than 1023 bytes.
NodeTooLong,
/// Happens when the domain is longer than 1023 bytes.
DomainTooLong,
/// Happens when the resource is longer than 1023 bytes.
ResourceTooLong,
@ -60,10 +53,8 @@ impl fmt::Display for Error {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.write_str(match self {
Error::NodeEmpty => "nodepart empty despite the presence of a @",
Error::DomainEmpty => "no domain found in this JID",
Error::ResourceEmpty => "resource empty despite the presence of a /",
Error::NodeTooLong => "localpart longer than 1023 bytes",
Error::DomainTooLong => "domain longer than 1023 bytes",
Error::ResourceTooLong => "resource longer than 1023 bytes",
Error::NodePrep => "localpart doesnt pass nodeprep validation",
Error::NamePrep => "domain doesnt pass nameprep validation",