[interfacekit] Re: more questions about BString

> - R5 allows calls to Insert( const char* str, int32 pos) with negative 
> positions, giving IMHO weird results...
>       Insert( "INSERT THIS", -1) 
> on an empty BString yields a string that contains "NSERT THIS". 
> This behaviour ist not at all documented by the BeBook.

Yeah, that caused me so many headaches...
And BTW, that's the reason why BString::Insert(BString...) calls the const char 
* version. I didn't want to duplicate that ugly code.


> My suggestion would be to clamp negative offsets to 0 (yielding "INSERT 
> THIS" for the given example).

I'm unsure on this matter. I'll wait for someone else to comment.

> 
> - Remove( int32 fromOffset, int32 length) 
> silently accepts fromOffset<0 (using 0), but doesn't clamp length likewise:
>       BString s("A String");
>       s.Remove( 4, 30);
> yields "A String" instead of "A St".

Same here.
 
> - the (I)Find...()-methods seem to always return B_ERROR if you pass a
> negative fromOffset. My patched methods clamp fromOffset to 0 and then
> execute the search, possibly yielding positive results.

Hm, here I would stick to the existing behaviour. There could be situations 
where that thing would be handy (not that I could tell you one).




Other related posts: