This commit is contained in:
fangyidong
2009-01-10 08:21:36 +00:00
parent 5ba11f487d
commit 851d6a4764
2 changed files with 0 additions and 80 deletions

View File

@@ -1,12 +0,0 @@
package org.json.simple.rope;
class Node {
static final int TYPE_STR = 0;
static final int TYPE_CH = 1;
static final int TYPE_UNKNOWN = -1;
int type = TYPE_UNKNOWN;
Node next;
char content_ch;
String content_str;
}

View File

@@ -1,68 +0,0 @@
package org.json.simple.rope;
public class Rope {
private Node first;
private Node current;
private int count = 0;
public void clear(){
count = 0;
first = null;
current = null;
}
public int length(){
return count;
}
public String toString(){
if(count == 0)
return "";
char[] chs = new char[count];
int pos = 0;
Node p = first;
do{
if(p.type == Node.TYPE_CH){
chs[pos] = p.content_ch;
pos++;
}
else{
int len = p.content_str.length();
p.content_str.getChars(0, len, chs, pos);
pos += len;
}
p = p.next;
}while(p != null);
return new String(chs);
}
public void append(char ch){
Node node = new Node();
node.type = Node.TYPE_CH;
node.content_ch = ch;
if(first == null)
first = node;
if(current != null)
current.next = node;
current = node;
count++;
}
public void append(String s){
if(s == null || s.equals(""))
return;
Node node = new Node();
node.type = Node.TYPE_STR;
node.content_str = s;
if(first == null)
first = node;
if(current != null)
current.next = node;
current = node;
count += s.length();
}
}