[openbeos] Re: BString

  • From: "Earl Colby Pottinger" <earlcp@xxxxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Mon, 12 Nov 2001 06:46:42 EST

>>> Just quickie, I am writing a version of BString, just to cut
>>> my teeth, any objections/suggestions?
>>>       Keith


>> Sorry I have not posted back earlier.  I believe that BStrings as
>> it presently exists in BeOS is broken.  The reason, it treats it's
>> strings like 'C' strings in some cases using a zero byte to make
>> the end of thestring and at other times using the Length()
>> function to tell it the string length to control string functions.

>> I believe that BStrings should always use the Length() function
>> and thus allow bytes containing zeros(0) to exist inside a string.

>> Also note:  If you read the BeBook BString section that there is
>> no mention that BStrings are zero terminated, only that the String()
>> function will return a zero terminated string.

>>          Earl Colby Pottinger

>> PS.  I am working a small test program to show what I mean, I will
>> post the code as soon as possible.


>The internal representation of the characters in a BString should not 
>make any difference. Keith should pick whatever implementation works 
>the best. Users of the class should make no assumption about how the 
>data is stored -- if they do, they deserve whatever trouble they get, 
>haha!

Right!  I did not do this and that is why I had problems, I assumed
that BStrings would do what the BeBook said they will do.

>So yes, users should only rely on calling Length() and not on finding a 
>terminating null. However, I would recommend *not allowing* zero bytes 
>in BStrings. It would work technically, but from a design standpoint, 
>it would confuse people. Making it clear that BString is only meant for 
>textual strings and not binary data is in keeping with BString's API 
>(for example, the buffer returned by String() is guaranteed to be null-
>terminated).

Where in the BeBook does it say BStrings are for text only?
If it is for text only, how will it handle UNICODE without zeros?

>If the need for a binary string class becomes necessary, we could write 
>BBinaryString (or something to that effect) to handle that -- altho I 
>think that good ole char * would be simpler.

??? if you use char * then you are back to square one and have to write
all the functions available in BStrings yourself.  That is what I did
and it made my code a mess compared to the BString version which worked
90% of the time but failed 10% because it is undocumented about how
zero bytes affect BStrings.

          Earl Colby Pottinger

Other related posts: