URL Parser Combinator
(updated 2016-10-16)
It has bugged me that there is no parser of an URL so I made one.Parser Combinator
Scala provides an excellent tool of parsing using a mix of code in DSL (domain specific language) and regular expressions. Together with unapply it's easy to match and take out the matching pieces.
URL
From Wikipedia there are the following parts of an URL (some are optional):
scheme:[//[user:password@]host[:port]][/]path[?query][#fragment]
Code
Enjoy, I won't go into detail other than it breaks down the URL in the following order:
- Split URL by
- Mandatory scheme
- Optional domain
- Mandatory path
- Optional query and fragment
- Domain is split by
- Authorization
- Domain
- Port
Usually a greedy regexp matcher is used until a delimiter.
Inga kommentarer:
Skicka en kommentar