summaryrefslogtreecommitdiff
path: root/src/morpho-server/URLEncoding.hs
diff options
context:
space:
mode:
authorbjorn <bjorn@bringert.net>2008-08-24 19:31:12 +0000
committerbjorn <bjorn@bringert.net>2008-08-24 19:31:12 +0000
commitb3ab690dddc76f3a33cc9c48d300518e73af041d (patch)
treed93d3b1ef63dcd3ec1a65f9e8bfdd476fc9a41ef /src/morpho-server/URLEncoding.hs
parenta8f054657448348ef8564d06958269fd4cf1adb9 (diff)
First (hacky) working version of FastCGI JSON morphology server.
Diffstat (limited to 'src/morpho-server/URLEncoding.hs')
-rw-r--r--src/morpho-server/URLEncoding.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/morpho-server/URLEncoding.hs b/src/morpho-server/URLEncoding.hs
new file mode 100644
index 000000000..ad5fb0dd9
--- /dev/null
+++ b/src/morpho-server/URLEncoding.hs
@@ -0,0 +1,18 @@
+module URLEncoding where
+
+import Data.Bits (shiftL, (.|.))
+import Data.Char (chr,digitToInt,isHexDigit)
+
+
+urlDecodeUnicode :: String -> String
+urlDecodeUnicode [] = ""
+urlDecodeUnicode ('%':'u':x1:x2:x3:x4:s)
+ | all isHexDigit [x1,x2,x3,x4] =
+ chr ( digitToInt x1 `shiftL` 12
+ .|. digitToInt x2 `shiftL` 8
+ .|. digitToInt x3 `shiftL` 4
+ .|. digitToInt x4) : urlDecodeUnicode s
+urlDecodeUnicode ('%':x1:x2:s) | isHexDigit x1 && isHexDigit x2 =
+ chr ( digitToInt x1 `shiftL` 4
+ .|. digitToInt x2) : urlDecodeUnicode s
+urlDecodeUnicode (c:s) = c : urlDecodeUnicode s