On Sat, Jan 12, 2013 at 8:32 PM, Alex Rousskov
<[email protected]> wrote:
> On 12/16/2012 03:02 PM, Kinkie wrote:
>>>> >> +        if (buf()+length() < tmp+str.length()) { //not enough chars to 
>>>> >> match the whole needle
>>>> >> +            debugs(SBUF_DEBUGSECTION,8,HERE << "needle too big for 
>>>> >> haystack");
>>>> >> +            end=tmp-1;
>>>> >> +            continue;
>>>> >> +        }
>>> >
>>> > If I interpret STL documentation correctly, the limit is not buf() +
>>> > length() but endpos. We should not match against characters beyond
>>> > endpos, even if the match _starts_ before endpos. Please double check me
>>> > on that.
>
>> I am not 100% sure I understand what you mean, but this simple test:
>
>> std::string haystack("foo bar gazonk");
>> std:;string needle("gazonka");
>> cout << "find overflow: " << haystack.find(needle) << endl;
>>
>> returns npos (as I'd expect)
>
> What I meant is that
>
>     "123".rfind("23", 2)
>
> should return npos instead of 1 because "23" is not found in the first
> two characters of the haystack ("123") string. So the above if-statement
> condition should use buf+endpos rather than buf+length().

Do we want to emulate the whole std::string API? Given StringNG's
substringing optimizations, the same activity could be expressed as
"123".substr(0,2).rfind("23")...

> Does that clarify?

Yes.

> The code has been rewritten since then, but it is still buggy:
>
>>     char *bufBegin = buf();
>>     char *cur = bufBegin+length()-needle.length();
>
> The "cur" variable should start with bufBegin+endPos-needle.length() or
> equivalent.
>
>
> BTW, this implies that you do not have a basic "match beyond head" unit
> test case:
>
>   "headtail".rfind("t", 4) == npos
>
> and I would also add
>
>     "headmiddletail".rfind("middle", 9) == npos
>     "headmiddletail".rfind("middle", 10) == 4
>
> (at least).

See my comment about using substringing. If that doesn't fly by you,
I'll certainly implement this.

> And, for every manually added haystack.*find(needle, n) test case, I
> would automatically add a haystack.substr(0, n).*find(needle) test case,
> since both must return the same value for every haystack, needle, and n
> (AFAICT).

Yes. I'm also considering having a parallel test with SBuf and
std::string, checking that the behavior is the same.

--
    /kinkie

Reply via email to