From 4648b3f74442675449ce4107c25d847d535fd142 Mon Sep 17 00:00:00 2001 From: Jephte CLAIN Date: Fri, 26 Feb 2016 11:19:30 +0400 Subject: [PATCH] awkrun: ajout de la fonction qarr() --- lib/ulib/awk | 4 ++++ lib/ulib/base | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ulib/awk b/lib/ulib/awk index 8631c39..e88e78c 100644 --- a/lib/ulib/awk +++ b/lib/ulib/awk @@ -72,6 +72,10 @@ sqvals(s) print \"mycmd\" sqvals() L'alias qsvals(s) existe pour compatibilité +qarr(vs) + quoter les valeurs du tableau vs pour le shell, e.g: + print \"values=(\" qarr(values) \")\" + qsubrepl(s) quoter une valeur pour l'argument r des fonctions sub() et gsub(). Les caractères suivants sont mis en échappement: \\ & diff --git a/lib/ulib/base b/lib/ulib/base index 8f6be8b..5cca546 100644 --- a/lib/ulib/base +++ b/lib/ulib/base @@ -1881,13 +1881,22 @@ function qvals( i, line) { line = "" for (i = 1; i <= NF; i++) { if (i > 1) line = line " " - line = line quote_value($i) + line = line qval($i) } return line } function sqvals() { return " " qvals() } +function qarr(values, i, count, line) { + line = "" + count = array_len(values) + for (i = 1; i <= count; i++) { + if (i > 1) line = line " " + line = line qval(values[i]) + } + return line +} function qregexp(s) { gsub(/[[\\.^$*+?()|{]/, "\\\\&", s) return s