changeset 3:4c0057e71936

Made a class for StringBuffer
author Frank Benoit <benoit@tionex.de>
date Wed, 04 Mar 2009 22:35:46 +0100
parents 712ffca654f3
children 6bf2837c50fe
files java/src/java/lang/StringBuffer.d java/src/java/lang/all.d java/src/java/lang/util.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/DefaultContent.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyleRange.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyledText.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/FileTransfer.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/HTMLTransfer.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/RTFTransfer.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/TextTransfer.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/URLTransfer.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/graphics/FontData.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Compatibility.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/SWTEventListener.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/SWTEventObject.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsID.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Display.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Link.d org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Spinner.d rakefile
diffstat 20 files changed, 142 insertions(+), 59 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/java/src/java/lang/StringBuffer.d	Wed Mar 04 22:35:46 2009 +0100
@@ -0,0 +1,94 @@
+module java.lang.StringBuffer;
+
+import java.lang.util;
+
+static import tango.text.Text;
+static import tango.text.convert.Utf;
+
+class StringBuffer : CharSequence {
+    alias tango.text.Text.Text!(char) TBuf;
+    TBuf buf;
+
+    public this(){
+        buf = new TBuf();
+    }
+
+    public this( int cap ){
+        buf = new TBuf( cap );
+    }
+
+    public this( String content ){
+        buf = new TBuf( content );
+    }
+
+    char charAt(int index){
+        return buf.slice()[ index ];
+    }
+
+    int length(){
+        return buf.length();
+    }
+
+    CharSequence subSequence(int start, int end){
+        return new StringBuffer( buf.slice()[ start .. end ] );
+    }
+
+    String toString(){
+        return buf.slice();
+    }
+
+    StringBuffer append( String s ){
+        buf.append( s );
+        return this;
+    }
+
+    StringBuffer append( String s, int offset, int len ){
+        buf.append( s[ offset .. offset+len ] );
+        return this;
+    }
+
+    StringBuffer append( char c ){
+        buf.append( c );
+        return this;
+    }
+
+    StringBuffer append( wchar c ){
+        wchar[1] src;
+        src[0] = c;
+        char[2] trg;
+        auto s = tango.text.convert.Utf.toString( src, trg );
+        buf.append( s );
+        return this;
+    }
+
+    StringBuffer append( int i ){
+        buf.append( String_valueOf(i) );
+        return this;
+    }
+
+    StringBuffer append( dchar c ){
+        dchar[1] src;
+        src[0] = c;
+        char[4] trg;
+        auto s = tango.text.convert.Utf.toString( src, trg );
+        buf.append( s );
+        return this;
+    }
+
+
+    StringBuffer insert(int offset, String str){
+        buf.select(offset, 0);
+        buf.replace(str);
+        buf.select();
+        return this;
+    }
+
+    StringBuffer replace(int start, int end, String str) {
+        buf.select(start, end-start);
+        buf.replace(str);
+        buf.select();
+        return this;
+    }
+}
+
+
--- a/java/src/java/lang/all.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/java/src/java/lang/all.d	Wed Mar 04 22:35:46 2009 +0100
@@ -9,8 +9,10 @@
 public import java.lang.Float;
 public import java.lang.Double;
 public import java.lang.Runnable;
+public import java.lang.StringBuffer;
 
 public import java.lang.util;
+public import java.lang.exceptions;
 
 
 
--- a/java/src/java/lang/util.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/java/src/java/lang/util.d	Wed Mar 04 22:35:46 2009 +0100
@@ -29,8 +29,6 @@
     return Log.lookup( "org.eclipse.swt" );
 }
 
-alias tango.text.Text.Text!(char) StringBuffer;
-
 alias ArrayBoundsException ArrayIndexOutOfBoundsException;
 
 abstract class ArrayWrapper{
@@ -891,10 +889,10 @@
 }
 
 interface CharSequence {
-    char           charAt(int index);
-    int             length();
-    CharSequence    subSequence(int start, int end);
-    String          toString();
+    char         charAt(int index);
+    int          length();
+    CharSequence subSequence(int start, int end);
+    String       toString();
 }
 
 /++
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/DefaultContent.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/DefaultContent.d	Wed Mar 04 22:35:46 2009 +0100
@@ -26,8 +26,6 @@
 static import tango.io.model.IFile;
 static import tango.text.Text;
 
-alias tango.text.Text.Text!(char) StringBuffer;
-
 class DefaultContent : StyledTextContent {
     private final static String LineDelimiter = tango.io.model.IFile.FileConst.NewlineString;
 
@@ -502,13 +500,13 @@
         // gap is in the specified range, strip out the gap
         StringBuffer buf = new StringBuffer();
         int gapLength = gapEnd - gapStart;
-        buf.append(textStore[ start .. gapStart ] );
-        buf.append(textStore[ gapEnd .. gapEnd + length_ - gapLength - (gapStart - start) ]);
-        length_ = buf.length;
-        while ((length_ - 1 >=0) && isDelimiter(buf.slice[length_ - 1])) {
+        buf.append(textStore, start, gapStart - start);
+        buf.append(textStore, gapEnd, length_ - gapLength - (gapStart - start));
+        length_ = buf.length();
+        while ((length_ - 1 >=0) && isDelimiter(buf.charAt(length_ - 1))) {
             length_--;
         }
-        return buf.toString()[ 0 .. length_ ].dup;
+        return buf.toString().substring(0, length_);
     }
 }
 /**
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyleRange.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyleRange.d	Wed Mar 04 22:35:46 2009 +0100
@@ -23,9 +23,6 @@
 import org.eclipse.swt.custom.TextChangedEvent;
 import org.eclipse.swt.custom.TextChangingEvent;
 
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
-
 /**
  * <code>StyleRange</code> defines a set of styles for a specified
  * range of text.
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyledText.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/custom/StyledText.d	Wed Mar 04 22:35:46 2009 +0100
@@ -90,8 +90,6 @@
 import tango.util.Convert;
 import java.lang.all;
 
-alias tango.text.Text.Text!(char) StringBuffer;
-
 /**
  * A StyledText is an editable user interface object that displays lines
  * of text.  The following style attributes can be defined for the text:
@@ -1225,8 +1223,7 @@
         if (offset < 0 || offset > buffer.length()) {
             return;
         }
-        buffer.select( offset );
-        buffer.prepend( string );
+        buffer.insert(offset, string);
     }
     /**
      * Appends the given int to the data.
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/FileTransfer.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/FileTransfer.d	Wed Mar 04 22:35:46 2009 +0100
@@ -21,8 +21,6 @@
 import org.eclipse.swt.dnd.DND;
 
 import java.lang.all;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 /**
  * The class <code>FileTransfer</code> provides a platform specific mechanism
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/HTMLTransfer.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/HTMLTransfer.d	Wed Mar 04 22:35:46 2009 +0100
@@ -21,8 +21,6 @@
 import org.eclipse.swt.dnd.DND;
 
 import java.lang.all;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 /**
  * The class <code>HTMLTransfer</code> provides a platform specific mechanism
@@ -104,29 +102,21 @@
     //startHTML
     int start = buffer.toString().indexOf(NUMBER);
     String temp = Integer.toString(startHTML);
-    buffer.select(start + maxLength-temp.length, temp.length);
-    buffer.replace(temp);
-    buffer.select();
+    buffer.replace(start + maxLength-temp.length(), start + maxLength, temp);
 
     //endHTML
     start = buffer.toString().indexOf(NUMBER, start);
     temp = Integer.toString(endHTML);
-    buffer.select(start + maxLength-temp.length, temp.length);
-    buffer.replace( temp);
-    buffer.select();
+    buffer.replace(start + maxLength-temp.length(), start + maxLength, temp);
 
     //startFragment
     start = buffer.toString().indexOf(NUMBER, start);
     temp = Integer.toString(startFragment);
-    buffer.select(start + maxLength-temp.length, temp.length);
-    buffer.replace(temp);
-    buffer.select();
+    buffer.replace(start + maxLength-temp.length(), start + maxLength, temp);
     //endFragment
     start = buffer.toString().indexOf(NUMBER, start);
     temp = Integer.toString(endFragment);
-    buffer.select(start + maxLength-temp.length, temp.length);
-    buffer.replace(temp);
-    buffer.select();
+    buffer.replace(start + maxLength-temp.length(), start + maxLength, temp);
 
     buffer.append(PREFIX);
     buffer.append(string);
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/RTFTransfer.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/RTFTransfer.d	Wed Mar 04 22:35:46 2009 +0100
@@ -21,8 +21,6 @@
 import org.eclipse.swt.dnd.DND;
 
 import java.lang.all;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 
 /**
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/TextTransfer.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/TextTransfer.d	Wed Mar 04 22:35:46 2009 +0100
@@ -21,8 +21,6 @@
 import org.eclipse.swt.dnd.DND;
 
 import java.lang.all;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 /**
  * The class <code>TextTransfer</code> provides a platform specific mechanism
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/URLTransfer.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/dnd/URLTransfer.d	Wed Mar 04 22:35:46 2009 +0100
@@ -21,8 +21,6 @@
 import org.eclipse.swt.dnd.DND;
 
 import java.lang.all;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 /**
  * The class <code>URLTransfer</code> provides a platform specific mechanism
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/graphics/FontData.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/graphics/FontData.d	Wed Mar 04 22:35:46 2009 +0100
@@ -17,9 +17,7 @@
 import org.eclipse.swt.internal.win32.OS;
 
 import java.lang.all;
-static import tango.text.Text;
 import tango.util.Convert;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 /**
  * Instances of this class describe operating system fonts.
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Compatibility.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/Compatibility.d	Wed Mar 04 22:35:46 2009 +0100
@@ -12,20 +12,17 @@
  *******************************************************************************/
 module org.eclipse.swt.internal.Compatibility;
 
-/+
-import java.io.*;
 import java.io.File;
-import java.text.MessageFormat;
+//import java.text.MessageFormat;
 import java.util.MissingResourceException;
 import java.util.ResourceBundle;
-import java.util.zip.DeflaterOutputStream;
+//import java.util.zip.DeflaterOutputStream;
 import java.util.zip.InflaterInputStream;
-+/
+
 
 import org.eclipse.swt.SWT;
 public import java.io.FileInputStream;
 public import java.io.FileOutputStream;
-public import java.util.zip.InflaterInputStream;
 
 import Math = tango.math.Math;
 import Unicode = tango.text.Unicode;
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/SWTEventListener.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/SWTEventListener.d	Wed Mar 04 22:35:46 2009 +0100
@@ -13,6 +13,7 @@
 module org.eclipse.swt.internal.SWTEventListener;
 
 import java.lang.all;
+import java.util.EventListener;
 
 /**
  * This interface is the cross-platform version of the
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/SWTEventObject.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/SWTEventObject.d	Wed Mar 04 22:35:46 2009 +0100
@@ -13,9 +13,9 @@
 module org.eclipse.swt.internal.SWTEventObject;
 
 
-//import java.util.EventObject;
 import tango.core.Exception;
 import java.lang.all;
+import java.util.EventObject;
 
 /**
  * This class is the cross-platform version of the
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsID.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/internal/mozilla/nsID.d	Wed Mar 04 22:35:46 2009 +0100
@@ -2,6 +2,7 @@
 
 import org.eclipse.swt.internal.mozilla.Common;
 import java.lang.all;
+import java.text.ParseException;
 
 align(1)
 struct nsID
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Display.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Display.d	Wed Mar 04 22:35:46 2009 +0100
@@ -54,8 +54,6 @@
 import tango.stdc.stringz;
 import tango.util.Convert;
 static import tango.text.convert.Utf;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 
 /**
  * Instances of this class are responsible for managing the
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Link.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Link.d	Wed Mar 04 22:35:46 2009 +0100
@@ -40,9 +40,6 @@
 
 import java.lang.all;
 
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
-
 /**
  * Instances of this class represent a selectable
  * user interface object that displays a text with
--- a/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Spinner.d	Wed Mar 04 21:41:18 2009 +0100
+++ b/org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/widgets/Spinner.d	Wed Mar 04 22:35:46 2009 +0100
@@ -30,8 +30,6 @@
 
 import java.lang.all;
 import tango.text.convert.Integer : toString;
-static import tango.text.Text;
-alias tango.text.Text.Text!(char) StringBuffer;
 import tango.util.Convert;
 
 /**
--- a/rakefile	Wed Mar 04 21:41:18 2009 +0100
+++ b/rakefile	Wed Mar 04 22:35:46 2009 +0100
@@ -11,6 +11,7 @@
 OBJDIR="obj"
 DIMPDIR="imp"
 RSPNAME="rsp"
+ALL_RESDIRS= [ "java/res", "org.eclipse.swt.win32.win32.x86/res" ]
 
 class String
     def to_path
@@ -35,6 +36,9 @@
     rsp.puts "-I#{srcdir_abs.to_path}"
     rsp.puts "-I#{dimpdir_abs.to_path}"
     rsp.puts "-J#{resdir_abs.to_path}"
+    ALL_RESDIRS.each do | dir |
+        rsp.puts "-J#{File.expand_path(dir).to_path}"
+    end
     rsp.puts "-c"
     rsp.puts "-op"
     rsp.puts "-version=TANGOSVN"
@@ -48,7 +52,16 @@
     Dir.chdir(basedir) do
         puts "Compile"
         sh "#{DMD} @#{rspfile_abs.to_path}" do |ok, res|
-            raise "compile error" unless ok
+
+            if !ok then
+                Find.find( srcdir_abs ) do |path|
+                    if FileTest.file?(path) && path =~ /\.di$/ then
+                        FileUtils.rm path
+                    end
+                end
+
+                raise "compile error"
+            end
         end
     end
 
@@ -72,6 +85,13 @@
 
 end
 
+desc "Clean"
+task :clean do
+    FileUtils.rm_rf DIMPDIR
+    FileUtils.rm_rf OBJDIR
+    FileUtils.rm_rf RSPNAME
+end
+
 desc "Build Java"
 task :java do
     buildTree( "java", "src", "res" )
@@ -82,3 +102,8 @@
     buildTree( "org.eclipse.swt.win32.win32.x86", "src", "res" )
 end
 
+desc "Build jface"
+task :jface do
+    buildTree( "org.eclipse.jface", "src", "res" )
+end
+