This causes issues in crates using it because they need to have "jid"
listed as a direct dependency when it's not always obvious (version
mismatch etc. when something already uses jid as a dep)
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
The idna crate validates against UTS 46, which supports domains using
either IDNA2003 or IDNA2008. This allows us to support both old and
new internationalized domain names.
This dependency isn’t a new one in the tree, as hickory-proto, url and
tokio-xmpp all were already depending on it.
There are a bunch of other checks that have to be performed, this is
inspired by slixmpp’s JID implementation.
This additionally should optimize the parsing a tiny bit by looking for
both @ and / at the same time and iterating on them, instead of one by
one.
Thanks nicoco for the report!
This provides a non-copying API, which is generally favourable. The
other accessors were removed, because the intent was to provide this
"most sensible" API via the "default" (i.e. shortest, most concisely
named) functions.
stringprep can make transformations to a JID, the most well-known one is
making the nodepart and domainpart lowercase but it does much more than
that.
It is extremely common to have to validate already-normalised JIDs
though, and since https://github.com/sfackler/rust-stringprep/pull/4
this is exactly what the stringprep crate does, by returning
Cow::Borrowed() for common ASCII-only cases.
This commit further reduces time spent by an additional -15%..-58% when
already using this stringprep improvement, in addition to the
89.5%..98.5% change brought by this improvement (and +1.3% total when
the JID isn’t normalised yet).
For instance, my own full JID parses in 1.83 µs before these changes,
132 ns with just the stringprep optimisation, and 46 ns with also this
commit, on an i7-8700K.