www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Java Strings (in D)

I did a simple D implementation of:
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html
http://java.sun.com/j2se/1.4.2/docs/api/java/lang/StringBuffer.html


Well, more like a quick hack...
http://www.algonet.se/~afb/d/javastring/html/class_string.html
http://www.algonet.se/~afb/d/javastring/html/class_string_buffer.html

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...
http://www.algonet.se/~afb/d/javastring/html/_string_test_8d-source.html

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.
http://svn.dsource.org/svn/projects/mango/trunk/doc/html/classUText.html
http://dool.sourceforge.net/dool_String_String.html


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.

--anders

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