Kimono.KMacroExpanderBase.ExpandMacrosShellQuote C# (CSharp) Method

ExpandMacrosShellQuote() public method

Perform safe macro expansion (substitution) on a string for use in shell commands.

NIX notes

Explicitly supported shell constructs: \ '' "" $'' $"" {} () $(()) ${} $() `` Implicitly supported shell constructs: (()) Unsupported shell constructs that will cause problems: Shortened "case $v in pat)" syntax. Use "case $v in (pat)" instead. The rest of the shell (incl. bash) syntax is simply ignored, as it is not expected to cause problems. Note that bash contains a bug which makes macro expansion within double quoted substitutions ("${VAR:-%macro}") inherently insecure. For security reasons, never put expandos in command line arguments that are shell commands by themselves - "sh -c 'foo \%f'" is taboo. "file=\%f sh -c 'foo "$file"'" is OK.

Windows notes

All quoting syntax supported by KShell is supported here as well. Additionally, command grouping via parentheses is recognized - note however, that the parser is much stricter about unquoted parentheses than cmd itself. The rest of the cmd syntax is simply ignored, as it is not expected to cause problems - do not use commands that embed other commands, though - "for /f ..." is taboo. name="str" the string in which macros are expanded in-place name="pos" the position inside the string at which parsing/substitution should start, and upon exit where processing stopped
public ExpandMacrosShellQuote ( StringBuilder str, int &pos ) : bool
str StringBuilder
pos int
return bool
        public bool ExpandMacrosShellQuote(StringBuilder str, ref int pos)
        {
            StackItem[] stack = new StackItem[3];
            #if DEBUG
            stack[1].s_class = (IntPtr) DebugGCHandle.Alloc(str);
            #else
            stack[1].s_class = (IntPtr) GCHandle.Alloc(str);
            #endif
            stack[2].s_int = pos;
            interceptor.Invoke("expandMacrosShellQuote$$", "expandMacrosShellQuote(QString&, int&)", stack);
            #if DEBUG
            DebugGCHandle.Free((GCHandle) stack[1].s_class);
            #else
            ((GCHandle) stack[1].s_class).Free();
            #endif
            pos = stack[2].s_int;
            return stack[0].s_bool;
        }

Same methods

KMacroExpanderBase::ExpandMacrosShellQuote ( StringBuilder str ) : bool