1 57 58 package com.sun.org.apache.xerces.internal.util; 59 60 import com.sun.org.apache.xerces.internal.xni.XMLString; 61 62 83 public class XMLStringBuffer 84 extends XMLString { 85 86 90 91 public static final int DEFAULT_SIZE = 32; 92 93 97 100 public XMLStringBuffer() { 101 this(DEFAULT_SIZE); 102 } 104 109 public XMLStringBuffer(int size) { 110 ch = new char[size]; 111 } 113 114 public XMLStringBuffer(char c) { 115 this(1); 116 append(c); 117 } 119 120 public XMLStringBuffer(String s) { 121 this(s.length()); 122 append(s); 123 } 125 126 public XMLStringBuffer(char[] ch, int offset, int length) { 127 this(length); 128 append(ch, offset, length); 129 } 131 132 public XMLStringBuffer(XMLString s) { 133 this(s.length); 134 append(s); 135 } 137 141 142 public void clear() { 143 offset = 0; 144 length = 0; 145 } 146 147 152 public void append(char c) { 153 if (this.length + 1 > this.ch.length) { 154 int newLength = this.ch.length*2; 155 if (newLength < this.ch.length + DEFAULT_SIZE) 156 newLength = this.ch.length + DEFAULT_SIZE; 157 char[] newch = new char[newLength]; 158 System.arraycopy(this.ch, 0, newch, 0, this.length); 159 this.ch = newch; 160 } 161 this.ch[this.length] = c; 162 this.length++; 163 } 165 170 public void append(String s) { 171 int length = s.length(); 172 if (this.length + length > this.ch.length) { 173 int newLength = this.ch.length*2; 174 if (newLength < this.length + length + DEFAULT_SIZE) 175 newLength = this.ch.length + length + DEFAULT_SIZE; 176 char[] newch = new char[newLength]; 177 System.arraycopy(this.ch, 0, newch, 0, this.length); 178 this.ch = newch; 179 } 180 s.getChars(0, length, this.ch, this.length); 181 this.length += length; 182 } 184 191 public void append(char[] ch, int offset, int length) { 192 if (this.length + length > this.ch.length) { 193 char[] newch = new char[this.ch.length + length + DEFAULT_SIZE]; 194 System.arraycopy(this.ch, 0, newch, 0, this.length); 195 this.ch = newch; 196 } 197 System.arraycopy(ch, offset, this.ch, this.length, length); 198 this.length += length; 199 } 201 206 public void append(XMLString s) { 207 append(s.ch, s.offset, s.length); 208 } 210 } | Popular Tags |