11-02-2022, 01:49 PM
while this is not a member function could be made into a function
shown here as a sub function for simplicity.
also shows how to fix #1
shown here as a sub function for simplicity.
also shows how to fix #1
_s=
;public static void Main(string[] args)
;{
;;#if A
;;;;;part1
;;;;;part1
;#endif
;
;part
;part
;
;#if V
;;;;;part2
;;;;;part2
;;;;;part2
;#endif
;
;part
;part
;
;#if C
;;;;;part3
;;;;;part3
;#endif
;}
out
;;;keep these two tags and output them together
str a1
sub.Match(_s a1 1)
out a1
out "-------------------------------------------------"
;;output only whats inbetween
str a2
sub.Match(_s a2 0)
out a2
;; delete (#if...#endif)
out "-------------------------------------------------"
_s.replacerx("#if.*(?s)(.*?)#endif" "")
_s.replacerx("(?:(?:(?!\n)\s)*\n){2,}" "[]")
out _s
#sub Match
function ~s ~&s2 mode
;;mode 1=output #if #endif everything in between. 0=output only whats inbetween
str s1;int t1
if mode&1
,foreach s1 s
,,if(matchw(s1 "*#if*")) t1=1;
,,if(t1=1) s2.addline(s1 1)
,,if(matchw(s1 "*#endif*")) t1=0;
else
,foreach s1 s
,,if(matchw(s1 "*#if*")) t1=1; continue
,,if(matchw(s1 "*#endif*")) t1=0; continue
,,if(t1=1) s2.addline(s1.ltrim 1)
ret