Copyright | (c) Soostone Inc. 2014-2015 Michael Xavier 2014-2015 Julian Ospald 2024 |
---|---|
License | BSD3 |
Maintainer | hasufell@posteo.de |
Stability | experimental |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
System.URI.File
aims to be an RFC8089 compliant URI file parser that uses
efficient ByteStrings for parsing and representing the data.
As such it only parses a subset of RFC3986, but is better at interpreting the file paths. Filepaths are always absolute according to the spec.
Part of this module was ripped off of the uri-bytestring package from Soostone (specifically the host part parsing).
Synopsis
- data FileURI = FileURI {}
- data ParseSyntax
- parseFileURI :: ParseSyntax -> ByteString -> Either String FileURI
- fileURIStrictP :: Parser FileURI
- fileURIExtendedPosixP :: Parser FileURI
- fileURIExtendedWindowsP :: Parser FileURI
Data types
A parsed file URI. It can have an auth/host part.
FileURI | |
|
data ParseSyntax Source #
RFC syntax configuration.
StrictPosix | Only parses the strict syntax according to section 2 of RFC 8089, which is technically posix paths. |
ExtendedPosix | Also parses extended user information described in E.1 |
ExtendedWindows | Parses windows paths according to E.1, E.2 and E.3. Unlike the spec, posix paths are rejected. |
Instances
Show ParseSyntax Source # | |
Defined in System.URI.File.Internal showsPrec :: Int -> ParseSyntax -> ShowS # show :: ParseSyntax -> String # showList :: [ParseSyntax] -> ShowS # | |
Eq ParseSyntax Source # | |
Defined in System.URI.File.Internal (==) :: ParseSyntax -> ParseSyntax -> Bool # (/=) :: ParseSyntax -> ParseSyntax -> Bool # |
Parsing
:: ParseSyntax | RFC syntax configuration |
-> ByteString | input file URI |
-> Either String FileURI |
Parse a file URI such as file:///foo/bar
into FileURI
.
>>>
parseFileURI StrictPosix "file:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "/path/to/file"})>>>
parseFileURI StrictPosix "file:///path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "/path/to/file"})>>>
parseFileURI StrictPosix "file://hostname/path/to/file"
Right (FileURI {fileAuth = Just "hostname", filePath = "/path/to/file"})>>>
parseFileURI StrictPosix "file://localhost/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "/path/to/file"})>>>
parseFileURI StrictPosix "http://localhost/path/to/file"
Left "string">>>
parseFileURI StrictPosix "/path/to/file"
Left "string">>>
parseFileURI ExtendedWindows "file://///host.example.com/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "//host.example.com/path/to/file"})>>>
parseFileURI ExtendedWindows "file:///c:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "c:/path/to/file"})>>>
parseFileURI ExtendedWindows "file:/c:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "c:/path/to/file"})>>>
parseFileURI ExtendedWindows "file:c:/path/to/file"
Right (FileURI {fileAuth = Nothing, filePath = "c:/path/to/file"})
Attoparsec parsers
fileURIStrictP :: Parser FileURI Source #
Parse a file URI according to the main ABNF in RFC 8089, without any extended rules, which is as follows:
file-URI = file-scheme ":" file-hier-part file-scheme = "file" file-hier-part = ( "//" auth-path ) / local-path auth-path = [ file-auth ] path-absolute local-path = path-absolute file-auth = "localhost" / host
fileURIExtendedPosixP :: Parser FileURI Source #
Parse a file URI according to the main ABNF in RFC 8089, with extended rule E.1.
file-URI = file-scheme ":" file-hier-part file-scheme = "file" file-hier-part = ( "//" auth-path ) / local-path auth-path = [ file-auth ] path-absolute local-path = path-absolute file-auth = "localhost" / [ userinfo "@" ] host
fileURIExtendedWindowsP :: Parser FileURI Source #
Parse a file URI according for windows according to E.1, E.2 and E.3. Unlike the spec, posix paths are rejected. The ABNF is a slight modification of Appendix F.
file-URI = file-scheme ":" file-hier-part file-scheme = "file" file-hier-part = ( "//" auth-path ) / local-path auth-path = [ file-auth ] file-absolute / unc-authority path-absolute local-path = drive-letter path-absolute / file-absolute file-auth = "localhost" / [ userinfo "@" ] host unc-authority = 2*3"/" file-host file-host = inline-IP IPv4address reg-name inline-IP = "%5B" ( IPv6address / IPvFuture ) "%5D" file-absolute = "/" drive-letter path-absolute drive-letter = ALPHA ":" / ALPHA "|"