From 540e71818048bcf8ce863d23d8597afce669304e Mon Sep 17 00:00:00 2001 From: Jephte Clain Date: Thu, 20 Apr 2017 23:19:55 +0400 Subject: [PATCH] =?UTF-8?q?base.core:=20qwc=20supporte=20les=20classes=20d?= =?UTF-8?q?e=20caract=C3=A8res?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/ulib/base.core | 71 +++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/lib/ulib/base.core b/lib/ulib/base.core index 8e42757..d96836b 100644 --- a/lib/ulib/base.core +++ b/lib/ulib/base.core @@ -107,7 +107,7 @@ function qvals() { } function qwc() { # Dans la chaine $*, remplacer \ par \\, " par \", $ par \$, ` par \`, puis -# quoter la chaine avec ", sauf les wildcards * et ? +# quoter la chaine avec ", sauf les wildcards *, ? et [class] # Cela permet de quoter une chaine permettant de glober des fichiers, e.g # eval "ls $(qwc "$value")" # Note: la protection de ! n'est pas effectuée, parce que le comportement du @@ -119,44 +119,45 @@ function qwc() { s="${s//\"/\\\"}" s="${s//\$/\\\$}" s="${s//\`/\\\`}" - local r a b + local r a b c while [ -n "$s" ]; do - if [[ "$s" == *\** ]]; then - if [[ "$s" == *\?* ]]; then - a="${s%%\**}" - b="${s%%\?*}" - if [ ${#a} -lt ${#b} ]; then - s="${s#*\*}" - r="$r\"$a\"*" - else - s="${s#*\?}" - r="$r\"$b\"?" - fi - else - a="${s%%\**}" - s="${s#*\*}" - r="$r\"$a\"*" - fi - elif [[ "$s" == *\?* ]]; then - if [[ "$s" == *\** ]]; then - a="${s%%\**}" - b="${s%%\?*}" - if [ ${#a} -lt ${#b} ]; then - s="${s#*\*}" - r="$r\"$a\"*" - else - s="${s#*\?}" - r="$r\"$b\"?" - fi - else - a="${s%%\?*}" - s="${s#*\?}" - r="$r\"$a\"?" - fi - else + a=; b=; c= + a=; [[ "$s" == *\** ]] && { a="${s%%\**}"; a=${#a}; } + b=; [[ "$s" == *\?* ]] && { b="${s%%\?*}"; b=${#b}; } + c=; [[ "$s" == *\[* ]] && { c="${s%%\[*}"; c=${#c}; } + if [ -z "$a" -a -z "$b" -a -z "$c" ]; then r="$r\"$s\"" break fi + if [ -n "$a" ]; then + [ -n "$b" ] && [ $a -lt $b ] && b= + [ -n "$c" ] && [ $a -lt $c ] && c= + fi + if [ -n "$b" ]; then + [ -n "$a" ] && [ $b -lt $a ] && a= + [ -n "$c" ] && [ $b -lt $c ] && c= + fi + if [ -n "$c" ]; then + [ -n "$a" ] && [ $c -lt $a ] && a= + [ -n "$b" ] && [ $c -lt $b ] && b= + fi + if [ -n "$a" ]; then # PREFIX* + a="${s%%\**}" + s="${s#*\*}" + [ -n "$a" ] && r="$r\"$a\"" + r="$r*" + elif [ -n "$b" ]; then # PREFIX? + a="${s%%\?*}" + s="${s#*\?}" + [ -n "$a" ] && r="$r\"$a\"" + r="$r?" + elif [ -n "$c" ]; then # PREFIX[class] + a="${s%%\[*}" + b="${s#*\[}"; b="${b%%\]*}" + s="${s:$((${#a} + ${#b} + 2))}" + [ -n "$a" ] && r="$r\"$a\"" + r="$r[$b]" + fi done recho_ "$r" }