Browse Source

replaced jidParts by a more readble Version

master
Philipp Balzarek 14 years ago
parent
commit
0e412cd782
  1. 54
      src/Network/XMPP/JID.hs

54
src/Network/XMPP/JID.hs

@ -120,25 +120,43 @@ isFull jid = not $ isBare jid
-- Parses an JID string and returns its three parts. It performs no -- Parses an JID string and returns its three parts. It performs no
-- validation or transformations. We are using Parsec to parse the -- validation or transformations. We are using Parsec to parse the
-- JIDs. There is no input for which 'jidParts' fails. -- JIDs. There is no input for which 'jidParts' fails.
jidParts :: AP.Parser (Maybe Text, Text, Maybe Text)
jidParts = do jidParts = do
a <- firstPartP -- Read until we reach an '@', a '/', or EOF.
b <- Just <$> domainPartP <|> (return Nothing) a <- AP.takeWhile1 (AP.notInClass ['@', '/'])
c <- Just <$> resourcePartP <|> (return Nothing) -- Case 1: We found an '@', and thus the localpart. At least the
case (a,b,c) of -- domainpart is remaining. Read the '@' and until a '/' or EOF.
-- Whether or not we have a resource part, if there is no "@" do
-- x is the domain b <- domainPartP
(x, Nothing, z) -> return (Nothing, x, z) -- Case 1A: We found a '/' and thus have all the JID parts. Read
-- When we do have an "@", x is the localpart -- the '/' and until EOF.
(x, Just y, z) -> return (Just x, y, z) do
c <- resourcePartP -- Parse resourcepart
firstPartP = AP.takeWhile1 (AP.notInClass ['@', '/']) return (Just a, b, Just c)
domainPartP = do -- Case 1B: We have reached EOF; the JID is in the form
_ <- AP.char '@' -- localpart@domainpart.
AP.takeWhile1 (/= '/') <|> do
resourcePartP = do AP.endOfInput
_ <- AP.char '/' return (Just a, b, Nothing)
AP.takeText -- Case 2: We found a '/'; the JID is in the form
-- domainpart/resourcepart.
<|> do
b <- resourcePartP
AP.endOfInput
return (Nothing, a, Just b)
-- Case 3: We have reached EOF; we have an JID consisting of only
-- a domainpart.
<|> do
AP.endOfInput
return (Nothing, a, Nothing)
where
domainPartP = do
_ <- AP.char '@'
AP.takeWhile1 (/= '/')
resourcePartP = do
_ <- AP.char '/'
AP.takeText
nodeprepProfile :: SP.StringPrepProfile nodeprepProfile :: SP.StringPrepProfile
nodeprepProfile = SP.Profile nodeprepProfile = SP.Profile

Loading…
Cancel
Save