From f8a7f09627aedda84984828f6b3fcb0c5b716bb9 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 2 Mar 2021 17:58:44 -0600 Subject: Document some more --- bollux | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bollux b/bollux index da93e43..a57e060 100644 --- a/bollux +++ b/bollux @@ -372,11 +372,20 @@ uwellform() { # directly from RFC 3986, Appendix B -- and if the URL provided doesn't match # it, the function bails. # -# `usplit' takes advantage ... [CONTINUE HERE] +# `usplit' takes advantage of bash's regex abilities: when the regex comparison +# operator `=~' is used, bash populates the array $BASH_REMATCH with the groups +# matched, and ${BASH_REMATCH[0]} is the entirety of the match. So `usplit' +# takes the matched URL, splits it using the regex, then assigns each part to an +# element of the url array NAME by using `printf -v', which prints to a +# variable. usplit() { # usplit NAME:ARRAY URL:STRING local re='^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?' [[ $2 =~ $re ]] || return $? + # ShellCheck doesn't see that I'm using these variables in the `for' + # loop below, because I'm not technically using them /as/ variables, but + # as names to the variables. The ${!c} formation in the `printf' call + # below performs a reverse lookup on the name to get the actual data. # shellcheck disable=2034 local url="${BASH_REMATCH[0]}" \ scheme="${BASH_REMATCH[2]}" \ -- cgit 1.4.1-21-gabe81