Re: Global matches, eq, @matches = ($str=~/('[^']+')/g)

"Dean Arnold" <[email protected]> Fri, 25 Apr 2003 16:32:16 -0700
Newsgroups gmane.comp.jakarta.oro.user
Message-ID <000f01c30b82$ea3dab70$0d00a8c0@luckplane>
After studyin on it spell, both your initial solution, and my
implemented solution are satisfactory, since it just needs
a few lines to implement:

    int lastend = 0;
    Stack strlits = new Stack();
    Stack strlocs = new Stack();
    while (perl.match("/('[^']+')/", str.substring(lastend))) {
        strlits.push(perl.group(1));
        strlocs.push(perl.begin(1));
//    maybe add and endlocs stack too?
        lastend = perl.end(1);
    }

Thats pretty concise compared to many other Java constructs
(e.g., trying to read in a formatted bytestream from a network socket),
but if you get overly ambitious, it might be a nice feature.

Speaking of wishlists and reading formatted bytestreams: ever
consider adding "pack" and "unpack" implementations ?
e.g.,
DataInputStream dout = ...;
Object strm_vals[] = perl.unpack("S L d S/a*",  dout);

Object strm_vals[] = new Object[];
byte packed_vals[] = perl.pack("S L d S/a*",  strm_vals);

(OK, I know, if I want to use Perl then use Perl...but I can dream, can't I
?)

Thanks for a great tool,
Dean Arnold
Presicient Corp.
www.presicient.com

----- Original Message -----
From: "Daniel F. Savarese" <[email protected]>
To: "ORO Users List" <[email protected]>
Sent: Friday, April 25, 2003 3:22 PM
Subject: Re: Global matches, eq, @matches = ($str=~/('[^']+')/g)


>
> I didn't notice the example in the subject when I responded, so I
> may have misunderstood.  If there is demand for m//g, then my
> inclination would be to add MatchResult getMatch(int index) and
> int getMatches(), with getMatch() returning getMatch(0)
> and all of the MatchResult interface methods operating on
> getMatch(0).  The /c option would only have any meaning when a
> PatternMatcherInput was used as input.  The crufty part is that
> all of those MatchResult interface methods will now be confusing.
> Another possibility is to have a nextMatch() and previousMatch()
> to iterate through the matches and a method to reset back to
> the first match.  You'd still want to be able to index directly
> and also get the number of matches, but now when you choose a
> particular match, the MatchResult methods refer to the current
> match, instead of the first one.  I don't know, file an enhancement
> request through Bugzilla and we can hash it out.  It should
> probably go in after the v2.0.8 release.
>
> daniel
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]