From d8245adc9c3fe22933fd80a1bcda234aeddb4874 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 25 Oct 2006 00:14:33 +0000 Subject: [PATCH] Adding StringBuffer class and test case. This gives append functionality. --- Robust/src/ClassLibrary/String.java | 52 +++++++++++++------ Robust/src/ClassLibrary/StringBuffer.java | 49 +++++++++++++++++ Robust/src/Main/Main.java | 1 + Robust/src/Runtime/runtime.c | 12 +++-- Robust/src/Tests/DoTests | 1 + Robust/src/Tests/StringBufferTest.java | 8 +++ .../Tests/output/StringBufferTest.output.goal | 1 + 7 files changed, 104 insertions(+), 20 deletions(-) create mode 100644 Robust/src/ClassLibrary/StringBuffer.java create mode 100644 Robust/src/Tests/StringBufferTest.java create mode 100644 Robust/src/Tests/output/StringBufferTest.output.goal diff --git a/Robust/src/ClassLibrary/String.java b/Robust/src/ClassLibrary/String.java index 3285f0fe..b771e4da 100644 --- a/Robust/src/ClassLibrary/String.java +++ b/Robust/src/ClassLibrary/String.java @@ -1,40 +1,60 @@ public class String { - char string[]; + char value[]; + int count; + int offset; public String(char str[]) { char charstr[]=new char[str.length]; for(int i=0;ivalue.length) { + // Need to allocate + char newvalue[]=new char[s.count+count+16]; //16 is DEFAULTSIZE + for(int i=0;i___string___; + struct ArrayObject * chararray=s->___value___; int i; - for(i=0;i___length___;i++) { - short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i]; + int offset=s->___offset___; + for(i=0;i___count___;i++) { + short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset]; putchar(s); } } @@ -452,7 +453,10 @@ struct ___String___ * NewString(const char *str,int length) { struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length); struct ___String___ * strobj=allocate_new(STRINGTYPE); int i; - strobj->___string___=chararray; + strobj->___value___=chararray; + strobj->___count___=length; + strobj->___offset___=0; + for(i=0;i___length___)+sizeof(int)))[i]=(short)str[i]; } return strobj; diff --git a/Robust/src/Tests/DoTests b/Robust/src/Tests/DoTests index e6de08ba..347206db 100755 --- a/Robust/src/Tests/DoTests +++ b/Robust/src/Tests/DoTests @@ -7,6 +7,7 @@ dotest BoundsFail2 BoundsFail2.java dotest BoundsFail3 BoundsFail3.java dotest BoundsFail4 BoundsFail4.java dotest StringTest StringTest.java +dotest StringBufferTest StringBufferTest.java dotest Test Test.java dotest virtualcalltest virtualcalltest.java dotest IncTest IncTest.java diff --git a/Robust/src/Tests/StringBufferTest.java b/Robust/src/Tests/StringBufferTest.java new file mode 100644 index 00000000..f68ced0b --- /dev/null +++ b/Robust/src/Tests/StringBufferTest.java @@ -0,0 +1,8 @@ +class StringBufferTest { + public static void main(String str[]) { + String a="hello world"; + StringBuffer b=new StringBuffer(a); + b.append(a); + System.printString(b.toString()); + } +} diff --git a/Robust/src/Tests/output/StringBufferTest.output.goal b/Robust/src/Tests/output/StringBufferTest.output.goal new file mode 100644 index 00000000..2df7ebc3 --- /dev/null +++ b/Robust/src/Tests/output/StringBufferTest.output.goal @@ -0,0 +1 @@ +hello worldhello world \ No newline at end of file -- 2.34.1