Re: rfind and lyxstring
> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: Lars> I think I prefere this, yours with a small minor change. This is exactly what I commited! I knew you would prefer it :) JMarc
Re: rfind and lyxstring
> "Dekel" == Dekel Tsur <[EMAIL PROTECTED]> writes: Dekel> This works, but I would write I commited something like what you wrote, and it seems to work. Dekel> And for lyxstring::rfind(lyxstring const & a, size_type) I Dekel> would write if (rep->sz < a.length()) return npos; ... Dekel> Actually, it appears that lyxstring::rfind(lyxstring const & a, Dekel> size_type) is completely broken... It looks suspicious... Fortunately, a grep shows that we do not use it :) JMarc
Re: rfind and lyxstring
Dekel Tsur <[EMAIL PROTECTED]> writes: | On Wed, Jan 10, 2001 at 11:54:36AM +0100, Lars Gullik Bjønnes wrote: | > Then I end up with something like: | > | > size_type const sz = rep->sz; | > if (!sz) return npos; | > | > size_type ii = min(sz - 1, i); | > for (int t = ii; t <= 0; --t) { |^^^ this should be t >= 0 | | > if (rep->s[t] == c) return t; | > } | > return npos; | > | > Can you test it. | | This works, but I would write | | if (rep->sz < 1) return npos; | size_type ii = min(rep->sz - 1, i); | do { | if (rep->s[ii] == c) return ii; | } while (ii-- > 0); | return npos; I have never been very fond of do while, but this for version is not overly pretty. if (rep->sz == 0) return npos; size_type ii = min(rep->sz - 1, i) + 1; for (; ii--;) if (rep->s[ii] == c) return ii; return npos; I think I prefere this, yours with a small minor change. size_type const sz = rep->sz; if (!sz) return npos; size_type ii = min(sz - 1, i); do { if (rep->s[ii] == c) return ii; } while (ii--); return npos; | And for lyxstring::rfind(lyxstring const & a, size_type) I would write | if (rep->sz < a.length()) return npos; | ... | | Actually, it appears that lyxstring::rfind(lyxstring const & a, size_type) | is completely broken... Possibly, but let's not change this now... we can wait until it bite or fix1. Lgb
Re: rfind and lyxstring
On Wed, Jan 10, 2001 at 11:54:36AM +0100, Lars Gullik Bj&resh;nnes wrote: > Then I end up with something like: > > size_type const sz = rep->sz; > if (!sz) return npos; > > size_type ii = min(sz - 1, i); > for (int t = ii; t <= 0; --t) { ^^^ this should be t >= 0 > if (rep->s[t] == c) return t; > } > return npos; > > Can you test it. This works, but I would write if (rep->sz < 1) return npos; size_type ii = min(rep->sz - 1, i); do { if (rep->s[ii] == c) return ii; } while (ii-- > 0); return npos; And for lyxstring::rfind(lyxstring const & a, size_type) I would write if (rep->sz < a.length()) return npos; ... Actually, it appears that lyxstring::rfind(lyxstring const & a, size_type) is completely broken...
Re: rfind and lyxstring
Jean-Marc Lasgouttes <[EMAIL PROTECTED]> writes: | cxx makes a very resonable objection: | | cxx: Warning: ../../../lyx-devel/src/support/lyxstring.C, line 1031: pointless | comparison of unsigned integer with zero | for (size_type t = ii; t >= 0; --t) { | -^ | | What about returning npos if the string is empty? What about using this: int ii = min(rep->sz - 1, i); for (int t = ii; t >= 0; --t) { if (rep->s[t] == c) return t; } return npos; Actually this will not work... our npos is too big... I don't like to special case rep->sz == 0, but it seems that will be the easiest solution. Then I end up with something like: size_type const sz = rep->sz; if (!sz) return npos; size_type ii = min(sz - 1, i); for (int t = ii; t <= 0; --t) { if (rep->s[t] == c) return t; } return npos; This can still fail but only for strings that are _very_ large. Can you test it. Lgb
Re: rfind and lyxstring
> "Lars" == Lars Gullik Bjønnes <[EMAIL PROTECTED]> writes: Lars> None om my compiler uses lyxstring anymore so I'd be grateful if Lars> someone could test the current cvs. cxx makes a very resonable objection: cxx: Warning: ../../../lyx-devel/src/support/lyxstring.C, line 1031: pointless comparison of unsigned integer with zero for (size_type t = ii; t >= 0; --t) { -^ What about returning npos if the string is empty? JMarc
rfind and lyxstring
None om my compiler uses lyxstring anymore so I'd be grateful if someone could test the current cvs. Lgb