~ multimethod

Methods

~(something:Any, pred:Any)deprecated Source: stdlib.ngs:870
EXPERIMENTAL! Do not use! Especially don't count on returned value beyond obvios Bool(x) behaviour. Match anything.
~(arr:Arr, r:PredRange) Source: stdlib.ngs:1978
Check whether the array contains the given range. Finds first match.

Returns

Match

Example

a = %[a1 a2 b1 b2]
m = a ~ /^a/../^b/ # Exclusive range
# m.matches == [['a2']]
# m.before == ['a1']
# m.after == ['b1', 'b2']
~(haystack:Str, needle:Str, offset:Int=0) Source: stdlib.ngs:3508
Find substring in string. Uses pos().

Returns

Match

Example

"abc" ~ "bc"  # <MatchY ...>
"abc" ~ "X"   # <MatchN>
~(s:Str, pfx:Pfx) Source: stdlib.ngs:5357
Check whether s starts with pfx.

Returns

Match

Example

"abcde" ~ Pfx("ab")  # <MatchY matches=['ab'] before= after=cde>
"abcde" ~ Pfx("xy")  # <MatchN >
~(s:Str, i:Ifx) Source: stdlib.ngs:5364
Undocumented
~(s:Str, sfx:Sfx) Source: stdlib.ngs:5371
Check whether s ends with sfx.

Returns

Match

Example

"abcde" ~ Sfx("de")  # <MatchY matches=['de'] before=abc after=>
"abcde" ~ Pfx("xy")  # <MatchN >
~(s:Str, r:RegExp, offset:Int=0, options:Int=0) Source: stdlib.ngs:5401
Find PCRE regular expression in s. Empty string without options returns MatchN. Throws Error if more than 20 captures are used or if there is an error during matching.

Automatically called by NGS for syntax

my_str ~ my_regexp

Parameters

offsetsearch start offset
optionsoptions to pass to underlying PCRE_EXEC(3).

Returns

Match

Example

globals().keys().filter(/^C_PCRE/)  # lists possible options
"xabcy" ~ /a(.)c/  # <MatchY matches=['abc','b'] named={} positions=[[1,4],[2,3]] whole=abc before=x after=y>
m = ("xabcy" ~ /a(?P<mychar>.)c/)
echo(m.named.mychar)  # Outputs: b
~(argv:Arr, udm:UserDefinedMethod) Source: autoload/ArgvMatcher.ngs:51
Please do not use directly! Tries to match command line arguments with closure parameters.

Parameters

argvCommand line arguments, typically ARGV
udmUserDefinedMethod to match with

Returns

Match (ParamsMatchY on success, ParamsMatchN on failure). If ParamsMatchY is returned it has "matches" field with values in suitable order to call c. If ParamsMatchN is returned, it has "message" field explaining why there was no match. Currently it's not printed anywhere.

Example

ArgvMatcher; (["--b", "B", "A", "C"] ~ F(a,b,c) 7).matches  # %[A B C]
(["A", "C", "D", "--b", "B"] ~ ArgvMatcher("positionals", "a") do F(a,b) 7).matches  # %[%[A C D] B]