ParseArgs


(:testpa a b c +d +e +f -g -h -i:)
Array
(
    [#] => Array
        (
            [0] => 
            [1] => a
            [2] => 
            [3] => b
            [4] => 
            [5] => c
            [6] => +
            [7] => d
            [8] => +
            [9] => e
            [10] => +
            [11] => f
            [12] => -
            [13] => g
            [14] => -
            [15] => h
            [16] => -
            [17] => i
        )

    [] => Array
        (
            [0] => a
            [1] => b
            [2] => c
        )

    [+] => Array
        (
            [0] => d
            [1] => e
            [2] => f
        )

    [-] => Array
        (
            [0] => g
            [1] => h
            [2] => i
        )

)
(:testpa positional0 positional1 a=1 b=2 test="quoted string" group={*$Group} 'positional 2':)
Array
(
    [#] => Array
        (
            [0] => 
            [1] => positional0
            [2] => 
            [3] => positional1
            [4] => a
            [5] => 1
            [6] => b
            [7] => 2
            [8] => test
            [9] => quoted string
            [10] => group
            [11] => Test
            [12] => 
            [13] => positional 2
        )

    [] => Array
        (
            [0] => positional0
            [1] => positional1
            [2] => positional 2
        )

    [a] => 1
    [b] => 2
    [test] => quoted string
    [group] => Test
)

Arguments in any order will work the same way, $args['a'] is always '1', $args['b'] is '2', etc.:

(:testpa a=1 b=2 c=3:)
(:testpa b=2 a=1 c=3:)
(:testpa c=3 b=2 a=1:)
Array
(
    [#] => Array
        (
            [0] => a
            [1] => 1
            [2] => b
            [3] => 2
            [4] => c
            [5] => 3
        )

    [a] => 1
    [b] => 2
    [c] => 3
)
Array
(
    [#] => Array
        (
            [0] => b
            [1] => 2
            [2] => a
            [3] => 1
            [4] => c
            [5] => 3
        )

    [b] => 2
    [a] => 1
    [c] => 3
)
Array
(
    [#] => Array
        (
            [0] => c
            [1] => 3
            [2] => b
            [3] => 2
            [4] => a
            [5] => 1
        )

    [c] => 3
    [b] => 2
    [a] => 1
)

Test some edge examples

(:testpa q=1 Q=a p=a,b,-c r='-z,-y' -s:imon :)
(:testpa dup=licate xed: y="something -onething dup=unique :) 
(:testpa 'x'=y 'v=a' str="ing :)
Array
(
    [#] => Array
        (
            [0] => q
            [1] => 1
            [2] => Q
            [3] => a
            [4] => p
            [5] => a,b,-c
            [6] => r
            [7] => -z,-y
            [8] => -
            [9] => s:imon
        )

    [q] => 1
    [Q] => a
    [p] => a,b,-c
    [r] => -z,-y
    [-] => Array
        (
            [0] => s:imon
        )

)
Array
(
    [#] => Array
        (
            [0] => dup
            [1] => licate
            [2] => 
            [3] => xed:
            [4] => y
            [5] => "something
            [6] => -
            [7] => onething
            [8] => dup
            [9] => unique
        )

    [dup] => unique
    [] => Array
        (
            [0] => xed:
        )

    [y] => "something
    [-] => Array
        (
            [0] => onething
        )

)
Array
(
    [#] => Array
        (
            [0] => 
            [1] => x
            [2] => 
            [3] => =y
            [4] => 
            [5] => v=a
            [6] => str
            [7] => "ing
        )

    [] => Array
        (
            [0] => x
            [1] => =y
            [2] => v=a
        )

    [str] => "ing
)
(:testpa test=parms,+with,-commas:)
(:testpa test="+quoted","parms","with","-commas":)
(:testpa test="+quoted,parms,with,-commas":)
(:testpa test=simon,[[~simon]] :)
Array
(
    [#] => Array
        (
            [0] => test
            [1] => parms,+with,-commas
        )

    [test] => parms,+with,-commas
)
Array
(
    [#] => Array
        (
            [0] => test
            [1] => +quoted
            [2] => 
            [3] => ,"parms","with","-commas"
        )

    [test] => +quoted
    [] => Array
        (
            [0] => ,"parms","with","-commas"
        )

)
Array
(
    [#] => Array
        (
            [0] => test
            [1] => +quoted,parms,with,-commas
        )

    [test] => +quoted,parms,with,-commas
)
Array
(
    [#] => Array
        (
            [0] => test
            [1] => simon,[[~simon]]
        )

    [test] => simon,[[~simon]]
)

Code:

Markup('testpa', 'directives', '/\\(:testpa(.*?):\\)/i', 'TestParseArgs');
function TestParseArgs($m) {
  $args = ParseArgs($m[1]);
  return '<:block>' . Keep(pre_r($args));
}
 0: 00.00 00.00 config start
 1: 00.01 00.00 config end
 2: 00.11 00.11 MarkupToHTML begin
 3: 00.11 00.11 MarkupToHTML begin
 4: 00.12 00.11 MarkupToHTML end
 5: 00.12 00.11 MarkupToHTML begin
 6: 00.12 00.12 MarkupToHTML end
 7: 00.12 00.12 MarkupToHTML begin
 8: 00.12 00.12 MarkupToHTML end
 9: 00.12 00.12 MarkupToHTML begin
10: 00.12 00.12 MarkupToHTML end
11: 00.12 00.12 MarkupToHTML begin
12: 00.12 00.12 MarkupToHTML end
13: 00.13 00.12 MarkupToHTML end
14: 00.13 00.13 MarkupToHTML begin
15: 00.14 00.13 ReadApprovedUrls SiteAdmin.ApprovedUrls begin
16: 00.14 00.14 ReadApprovedUrls SiteAdmin.ApprovedUrls end
17: 00.15 00.14 MarkupToHTML end
18: 00.15 00.14 MarkupToHTML begin
19: 00.16 00.15 MarkupToHTML end
20: 00.16 00.15 now
Peak memory: 3,422,080 bytes