procmail
[Top] [All Lists]

Re: Getting partial matches from a string without forking an outside process

2005-01-09 11:49:01
On Sun, Jan 09, 2005 at 02:44:10PM +0100, Robert Allerstorfer wrote:

On Sun, 09 Jan 2005, 00:25 GMT+01 Dallman Ross wrote:

I don't see any need to save the right-hand part.  What for?

The intention of my 'av_split.inc' is to split a string
($av_SPLIT_STRING) into two pieces ($av_SPLIT_LEFT and
$av_SPLIT_RIGHT) at a given position ($av_N):

av_SPLIT_STRING = 'aaaBBBB'
                     ^
                     |____> we want to split it at position av_N = '3'
                            into the left and right piece, giving
                  'aaa'
            and      'BBBB'

Your recipe does only result in the left part, but not in the right
one.

Okay, but as Ruud showed, once we have our foreshortened string, it's
trivial to then find the right side.

  :0
  * fullstring ?? ^^$\leftpart\/.*
  { rightpart = "$MATCH" }

If you have a look into 'av_split.inc', you will see that my solution
is done using simple code:

 MATCH
 :0
  * av_SPLIT_STRING ?? ^^\/.
  {
     av_SPLIT_LEFT = "$av_SPLIT_LEFT$MATCH"
  }

 MATCH
 :0
  * av_SPLIT_STRING ?? ^^.\/.*
  {
     av_SPLIT_STRING = $MATCH
  }

 :0
  * $ $av_N ^0
  *      -1 ^0
  {
     av_N = $=
     INCLUDERC = $_
  }

 :0 E
  {
     av_SPLIT_RIGHT = $av_SPLIT_STRING
     av_SPLIT_STRING
  }

# We currently always break the string from left to right. If the right part
# is shorter than the left one, parsing from the other direction would be 
# faster. For the time being, however, I don't care. 

Neither do I.

Btw, I think the "E" flag there at the end is unnecessary, though harmless
enough.

-- 
dman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>