[interfacekit] Re: more questions about BString
- From: Erik Jaesler <erik@xxxxxxxxxxxxxx>
- To: interfacekit@xxxxxxxxxxxxx
- Date: Mon, 03 Nov 2003 10:59:58 -0800
I don't know what the performance (or usability) ramifications might be,
but when I read this, it immediately occured to me that in python,
negative offsets have well-defined semantics that are quite useful. In
IFind(), for instance, using -4 as the offset would initiate the find
from whatever the fourth-from-last character/byte is. Depending on what
the issues are, it might be more useful to properly implement negative
offset handling than simply clamping to zero.
Thoughts?
e
Oliver Tappe wrote:
Hi everyone,
when implementing the BString-patch we spoke about earlier, I tried to
follow the idea that the BString-class should clamp all input values
(offsets) to sensible values (0 <= offset <= length).
As the resulting testrun shows, this causes the resulting behaviour to
differ from R5-BString in some ways:
- 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.
My suggestion would be to clamp negative offsets to 0 (yielding "INSERT
THIS" for the given example).
- 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".
- 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.
No I wonder what to do with that, since the BeBook doesn't have any info on
that...
Should I try to stick to R5 as much as possible (be as compatible as can
be)?
Or is it better to try to implement consistent behaviour and clamp *all*
offset parameters?
cheers,
Oliver
- Follow-Ups:
- [interfacekit] Re: more questions about BString
- From: Andrew Bachmann
- References:
- [interfacekit] more questions about BString
- From: Oliver Tappe
Other related posts:
- » [interfacekit] more questions about BString
- » [interfacekit] Re: more questions about BString
- » [interfacekit] Re: more questions about BString
- » [interfacekit] Re: more questions about BString
- » [interfacekit] Re: more questions about BString
- » [interfacekit] Re: more questions about BString
- » [interfacekit] Re: more questions about BString
when implementing the BString-patch we spoke about earlier, I tried to follow the idea that the BString-class should clamp all input values (offsets) to sensible values (0 <= offset <= length).
As the resulting testrun shows, this causes the resulting behaviour to differ from R5-BString in some ways:
- 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.
My suggestion would be to clamp negative offsets to 0 (yielding "INSERT THIS" for the given example).
- 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".
- 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.
No I wonder what to do with that, since the BeBook doesn't have any info on that...
Should I try to stick to R5 as much as possible (be as compatible as can be)?
Or is it better to try to implement consistent behaviour and clamp *all* offset parameters?
cheers,
Oliver- [interfacekit] Re: more questions about BString
- From: Andrew Bachmann
- [interfacekit] more questions about BString
- From: Oliver Tappe