bug-gawk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug-gawk] funcsub func needed


From: Kjetil D. Midtlie
Subject: Re: [bug-gawk] funcsub func needed
Date: Mon, 8 Dec 2014 14:21:42 +0100 (CET)

Yes the awk impl of this new func is:


# kind of like gensub(global flag on)
# but expands grp-values
# ( userData is also a new feature )
#
# 60 TIMES slower than gensub !!!!!!!!!!
#
# .. I need a C version of this

# replaceFn has this signature:: (arr,userData) returns string

function funcsub(regex,replaceFn,userData,target){
  newVal = target

  while (match(target,regex,grps)) {
    singleHit = substr(target, RSTART, RLENGTH);
    sub(singleHit, @replaceFn(grps,userData),newVal)
    # shift;
    target = substr(target, RSTART + RLENGTH);
  }

  return newVal

} 

____________________________ 

Kjetil Flovild-Midtlie 
Utvikler/Softwarearkitekt

Docstream as 
Hvamstubben 17, N-2013 Skjetten 
Mobile (+47) 92 09 56 15 
Office (+47) 48 11 12 00 
Fax (+47) 63 84 08 12 
www.docstream.no 
____________________________ 

----- Opprinnelig melding -----
Fra: "Aharon Robbins" <address@hidden>
Til: address@hidden, address@hidden
Sendt: 7. desember 2014 18:53:35
Emne: Re: [bug-gawk] funcsub func needed

Hello.

Thank you for your note.

Passing in a function to execute is an interesting idea. However, it is
rather difficult to implement.  I suspect that simply using the
extended version of match() to pull out all the bits and then passing
the array to your own function would work pretty well.

Another alternative, if you need the text in between, is to use split()
or patsplit().

Thanks,

Arnold

> Date: Sat, 6 Dec 2014 20:20:48 +0100 (CET)
> From: "Kjetil D. Midtlie" <address@hidden>
> To: address@hidden
> Subject: [bug-gawk] funcsub func needed
>
> gensub needs an expression language in replace, and that language is awk:
>
> So a new function funcsub(regex,funcNameStr,how[,target]) extending gensub() 
> is born
> using "\\1" etc is such a pain when i need to modify the value 
>
> funcNameStr is "pointing" to a func w signature :
> fn( arr ) that returns string.
> arr contains all grp-matches expanded like how match() does
>
> (today you can only use a shift-type loop w the match() func to get the same 
> feature AND IT IS SLOOOW)
>
> This will be a killer feature for scenarios where u need to reduce/alter 
> grp-values before them ending up in output
>
> gensub is cool but I always end up doing a complex 2nd-pass-replace on 
> extracted grp-vales that can not be used directly in output....
> (Involving wrapping grp-values in bizarre placeholders that is unlikely to 
> appear in text otherwise)
>
> ____________________________ 
>
> Kjetil Flovild-Midtlie 
> Developer/Softwarearcitect
>
> Docstream as 
> Hvamstubben 17, N-2013 Skjetten 
> Mobile (+47) 92 09 56 15 
> Office (+47) 48 11 12 00 
> Fax (+47) 63 84 08 12 
> www.docstream.no 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]