www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Java Strings (in D)

I did a simple D implementation of:

Well, more like a quick hack...

But it does cache hash and utf32 ?
Java "char" was replaced with "dchar".
StringBuffer is thread-safe (synchronized)

I found it to be an interesting class exercise, maybe you'll do too...

It's not really safe, since toString returns a reference to the internal
string which you can the mutilate to your hearts content. But otherwise?

For other, more advanced, string classes see the Mango or Dool projects.

I didn't bother duplicating any toString or toUTF# methods in the class.
So right now it only works with char[], which should be plenty for this.
It's not like D *wants* a string class anyway, with the built-in arrays.


PS. setCharAt is kinda expensive, with D strings. Those are the breaks.

     And, yes, I used '+' for concatenating strings... This was Java. :-)
Mar 07 2005