diff options
author | bptato <nincsnevem662@gmail.com> | 2024-08-11 13:58:05 +0200 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-08-11 13:58:05 +0200 |
commit | 4393412d971269055401f2e8a6be766f4402e193 (patch) | |
tree | 8ac55ed62d46bc91f431249434bb2483d3a35e4f /adapter/tools | |
parent | 77aaafba20fd354625985bd65dce046cab759c63 (diff) | |
download | chawan-4393412d971269055401f2e8a6be766f4402e193.tar.gz |
urldec: merge into urlenc
also, move the ln command to make all
Diffstat (limited to 'adapter/tools')
-rw-r--r-- | adapter/tools/urldec.nim | 6 | ||||
-rw-r--r-- | adapter/tools/urlenc.nim | 34 |
2 files changed, 18 insertions, 22 deletions
diff --git a/adapter/tools/urldec.nim b/adapter/tools/urldec.nim deleted file mode 100644 index b26fcb68..00000000 --- a/adapter/tools/urldec.nim +++ /dev/null @@ -1,6 +0,0 @@ -# Percent-decode input received on stdin. -#TODO a streaming implementation of this could be useful - -import utils/twtstr - -stdout.write(percentDecode(stdin.readAll())) diff --git a/adapter/tools/urlenc.nim b/adapter/tools/urlenc.nim index 79d3e452..93a913b6 100644 --- a/adapter/tools/urlenc.nim +++ b/adapter/tools/urlenc.nim @@ -1,11 +1,12 @@ -# Percent-encode input received on stdin with a specified percent-encoding set. +# Percent-encode or decode input received on stdin with a specified +# percent-encoding set. #TODO a streaming implementation of this could be useful import std/os import utils/twtstr -proc usage() = +proc usage() {.noreturn.} = stderr.write(""" Usage: urlenc [set] The input to be decoded is read from stdin. @@ -18,24 +19,25 @@ The input to be decoded is read from stdin. component application-x-www-form-urlencoded """) + quit(1) proc main() = - if paramCount() != 1: + let isdec = paramStr(0).afterLast('/') == "urldec" + if not isdec and paramCount() != 1: usage() - quit(1) let s = stdin.readAll() - let enc = case paramStr(1) - of "control": percentEncode(s, ControlPercentEncodeSet) - of "fragment": percentEncode(s, FragmentPercentEncodeSet) - of "query": percentEncode(s, QueryPercentEncodeSet) - of "path": percentEncode(s, PathPercentEncodeSet) - of "userinfo": percentEncode(s, UserInfoPercentEncodeSet) - of "component": percentEncode(s, ComponentPercentEncodeSet) - of "application-x-www-form-urlencoded": - percentEncode(s, ApplicationXWWWFormUrlEncodedSet) + if isdec: + stdout.write(s.percentDecode()) else: - usage() - quit(1) - stdout.write(enc) + let set = case paramStr(1) + of "control": ControlPercentEncodeSet + of "fragment": FragmentPercentEncodeSet + of "query": QueryPercentEncodeSet + of "path": PathPercentEncodeSet + of "userinfo": UserInfoPercentEncodeSet + of "component": ComponentPercentEncodeSet + of "application-x-www-form-urlencoded": ApplicationXWWWFormUrlEncodedSet + else: usage() + stdout.write(s.percentEncode(set)) main() |