summary refs log tree commit diff stats
path: root/lib/pure/uri.nim
diff options
context:
space:
mode:
authordom96 <dominikpicheta@googlemail.com>2012-05-06 23:18:07 +0100
committerdom96 <dominikpicheta@googlemail.com>2012-05-06 23:18:07 +0100
commitcf87759e2911cb44aaf1e107f20417df74d2a606 (patch)
treedb7e90de763571a5cf7b4fa1f6103828f926bf93 /lib/pure/uri.nim
parent92a7933504adc8624c90de74f2ec2a1477b68a42 (diff)
downloadNim-cf87759e2911cb44aaf1e107f20417df74d2a606.tar.gz
Added uri module.
Diffstat (limited to 'lib/pure/uri.nim')
-rw-r--r--lib/pure/uri.nim35
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/pure/uri.nim b/lib/pure/uri.nim
new file mode 100644
index 000000000..cfe424dc6
--- /dev/null
+++ b/lib/pure/uri.nim
@@ -0,0 +1,35 @@
+#
+#
+#            Nimrod's Runtime Library
+#        (c) Copyright 2012 Dominik Picheta
+#
+#    See the file "copying.txt", included in this
+#    distribution, for details about the copyright.
+#
+import strutils
+type
+  TUrl* = distinct string
+
+proc `$`*(url: TUrl): string = return string(url)
+
+proc `/`*(a, b: TUrl): TUrl =
+  ## Joins two URLs together, separating them with / if needed.
+  var urlS = $a
+  var bS = $b
+  echo(urlS, " & ", bS)
+  if urlS == "": return b
+  if urlS[urlS.len-1] != '/':
+    urlS.add('/')
+  if bS[0] == '/':
+    urlS.add(bS.substr(1))
+  else:
+    urlS.add(bs)
+  result = TUrl(urlS)
+  echo(result)
+
+proc add*(url: var TUrl, a: TUrl) =
+  ## Appends url to url.
+  url = url / a
+
+when isMainModule:
+  assert($("http://".TUrl / "localhost:5000".TUrl) == "http://localhost:5000")
\ No newline at end of file