[haiku-development] Re: BString method SymbolAt() proposal

  • From: Ingo Weinhold <ingo_weinhold@xxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Sat, 19 Jun 2010 18:56:19 +0200

On 2010-06-19 at 18:34:23 [+0200], Oliver Tappe <zooey@xxxxxxxxxxxxxxx> wrote:
> On 2010-06-19 at 12:39:47 [+0200], Reinhard Scharnagl <rescharn@xxxxxxx>
> wrote:
> > The BString class seems to be not complete. Typical UTF8 symbols
> > like '€' do not fit into one char but into an int32. Nevertheless BString
> > methods only support char parameters, where handling a single UTF8
> > symbol is intended.
> 
> That's not at all true, there are:
>             const char*    CharAt(int32 charIndex, int32* bytes = NULL) 
>             const;
>             bool            CharAt(int32 charIndex, char* buffer,
>                                 int32* bytes) const;

Those do have O(n) complexity, though, which makes iteration unnecessarily 
expensive. Not much of a problem for short strings, but not so nice for a 
generic API. A BUnicodeString with O(n) string conversion and O(1) random 
character access would be much nicer.

CU, Ingo

PS: @Reinhard: "Symbol" is really not the right term. The Unicode terminology 
consistently uses "character".

Other related posts: