On Mon, Jun 18, 2012 at 12:10 AM, Cyrille Lefevre
<[email protected]> wrote:
> Roland Mainz <[email protected]> a écrit :
>
> > On Fri, Jun 15, 2012 at 10:59 PM, Josh Hurst <[email protected]> wrote:
> >
> > Erm... we can have the cake and eat it too... :-)
> > My proposal would be likt this:
> > 1. %(foo)q, e.g. operations with a single word ("foo" in this case)
> > define plain quoting operations to quote the given string to make it's
> > meaning "literal", e.g. all characters which may be special in the
> > target syntax are escaped/quoted. These operations do not throw any
> > errors regardless what's being fed in
> >
> > 2. %(foo2bar)q, e.g. operations with two worlds with a "2" in the
> > middle define conversion operations (from/to), e.g. from egrep syntax
> > to shell shell pattern expressions would be "egrep2shellre".
> > Conversion operations are allowed to trigger errors
>
> David... what do you think ?
>
> the proposal is intetesting, maybe not so simple to implement, however, I've
> a doubt about the syntax, how about using : instead of 2 ? i.e. :
> %(from:[to]|[from]:to)q where a missing from or to means literal, a single
> letter (RGEX...) would be sufficient...

Replacing the '2' with a ':' may be a good idea... but please keep the
remainder _simple_. The original proposal was just to have more than
one "quoting method" available to avoid having to write giant loops
walking a string character-by-character (where POSIX shells are
incredibly slow).

Example:
Before %(url)q was invented we had to do this to quote strings into a
url-"safe" format:
-- snip --
function urlencode_string
{
        nameref outbuf="$1"
        typeset inbuf="$2"
        typeset c
        typeset buf=''
        integer i
        integer inbuflen=${#inbuf}

        for (( i=0 ; i < inbuflen ; i++ )) ; do
                c="${inbuf:i:1}"
                case "${c}" in
                        ' ') c='+'   ;;
                        '!') c='%21' ;;
                        '*') c='%2A' ;;
                        "'") c='%27' ;;
                        '(') c='%28' ;;
                        ')') c='%29' ;;
                        ';') c='%3B' ;;
                        ':') c='%3A' ;;
                        '@') c='%40' ;;
                        '&') c='%26' ;;
                        '=') c='%3D' ;;
                        '+') c='%2B' ;;
                        '$') c='%24' ;;
                        ',') c='%2C' ;;
                        '/') c='%2F' ;;
                        '?') c='%3F' ;;
                        '%') c='%25' ;;
                        '#') c='%23' ;;
                        '[') c='%5B' ;;
                        '\') c='%5C' ;; # we need this to avoid the '\'-quoting 
hell
                        ']') c='%5D' ;;
                        *)   ;;
                esac
                buf+="${c}"
        done
        
        outbuf="${buf}"
        
        return 0
}
-- snip --
... compare this to a plain $ printf '%(url)q' "$str" #.

I really like to have this reduced to KISS (Keep-It-Simple&&Stupid)
form of the original proposal for now. It keeps the implementation
simple and maybe allows it that we can propose the %(...)q form to the
Austin Group for standartisation (together with the $'...' and
$"..."-style literals).

----

Bye,
Roland

-- 
  __ .  . __
 (o.\ \/ /.o) [email protected]
  \__\/\/__/  MPEG specialist, C&&JAVA&&Sun&&Unix programmer
  /O /==\ O\  TEL +49 641 3992797
 (;O/ \/ \O;)

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to