parseurl added
This commit is contained in:
parent
20962ca50f
commit
70465b5f06
3 changed files with 22 additions and 0 deletions
18
lib/pure/parseurl.nim
Executable file
18
lib/pure/parseurl.nim
Executable file
|
|
@ -0,0 +1,18 @@
|
||||||
|
import regexprs, strutils
|
||||||
|
|
||||||
|
type
|
||||||
|
TUrl* = tuple[protocol, subdomain, domain, port: string, path: seq[string]]
|
||||||
|
|
||||||
|
proc parseUrl*(url: string): TUrl =
|
||||||
|
#([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?
|
||||||
|
const pattern = r"([a-zA-Z]+://)?(\w+?\.)?(\w+)(\.\w+)(:[0-9]+)?(/.+)?"
|
||||||
|
var m: array[0..6, string] #Array with the matches
|
||||||
|
discard regexprs.match(url, pattern, m)
|
||||||
|
|
||||||
|
result = (protocol: m[1], subdomain: m[2], domain: m[3] & m[4],
|
||||||
|
port: m[5], path: m[6].split('/'))
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
var r = parseUrl(r"http://google.com/search?var=bleahdhsad")
|
||||||
|
echo(r.domain)
|
||||||
|
|
||||||
|
|
@ -53,6 +53,8 @@ import
|
||||||
|
|
||||||
# the parser treats ``<br />`` as ``<br></br>``
|
# the parser treats ``<br />`` as ``<br></br>``
|
||||||
|
|
||||||
|
## xmlElementCloseEnd, ## ``/>``
|
||||||
|
|
||||||
type
|
type
|
||||||
TXmlEventKind* = enum ## enumation of all events that may occur when parsing
|
TXmlEventKind* = enum ## enumation of all events that may occur when parsing
|
||||||
xmlError, ## an error ocurred during parsing
|
xmlError, ## an error ocurred during parsing
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,8 @@ Bugfixes
|
||||||
--------
|
--------
|
||||||
- The Posix version of ``os.copyFile`` has better error handling.
|
- The Posix version of ``os.copyFile`` has better error handling.
|
||||||
- Fixed bug #502670 (underscores in identifiers).
|
- Fixed bug #502670 (underscores in identifiers).
|
||||||
|
- Fixed a bug in the ``parsexml`` module concerning the parsing of
|
||||||
|
``<tag attr="value" />``.
|
||||||
|
|
||||||
|
|
||||||
Additions
|
Additions
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue