Re: [GLib] How to get substrings?



On Thu, 2004-11-11 at 17:08 +0100, Iago Rubio wrote:
On Tue, 2004-11-09 at 19:28, Martyn Russell wrote:
You probably would want to move pos1 on the length of needle1  before
looking for needle2 first, otherwise if you look for something between
"$" and "$" pos2 will be the same as pos1.

You snipped the line were pos1 is moved.
if( (pos1 += strlen(needle1)) >= pos2) 

Yes, because your implementation meant that if you had a string
"sometext$string$moretext" and you want "string" by looking between the
two "$" characters it would not work. 

With your implementation it would just return NULL if the "s" (pos1) in
"string" was >= to the "$" (pos2) in "$string" which it is not.  E.g.

        "sometext$string$moretext"
                  ^ = pos1
                 ^ = pos2
                
Logically, it makes sense to look for needle1, move to needle1
+strlen(needle1) then look for needle2 (from needle1).  Then needle1 and
needle2 can be the same.

-- 
Regards,
Martyn



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