1 56 57 package org.jdom.input; 58 59 import org.jdom.*; 60 61 78 class TextBuffer { 79 80 private static final String CVS_ID = 81 "@(#) $RCSfile: TextBuffer.java,v $ $Revision: 1.9 $ $Date: 2004/12/11 01:31:50 $ $Name: $"; 82 83 85 private String prefixString; 86 87 89 private char[] array; 90 91 93 private int arraySize; 94 95 96 TextBuffer() { 97 array = new char[4096]; arraySize = 0; 99 } 100 101 102 void append(char[] source, int start, int count) { 103 if (prefixString == null) { 104 prefixString = new String (source, start, count); 106 } 107 else { 108 ensureCapacity(arraySize + count); 110 System.arraycopy(source, start, array, arraySize, count); 111 arraySize += count; 112 } 113 } 114 115 116 int size() { 117 if (prefixString == null) { 118 return 0; 119 } 120 else { 121 return prefixString.length() + arraySize; 122 } 123 } 124 125 126 void clear() { 127 arraySize = 0; 128 prefixString = null; 129 } 130 131 boolean isAllWhitespace() { 132 if ((prefixString == null) || (prefixString.length() == 0)) { 133 return true; 134 } 135 136 int size = prefixString.length(); 137 for(int i = 0; i < size; i++) { 138 if ( !Verifier.isXMLWhitespace(prefixString.charAt(i))) { 139 return false; 140 } 141 } 142 143 for(int i = 0; i < arraySize; i++) { 144 if ( !Verifier.isXMLWhitespace(array[i])) { 145 return false; 146 } 147 } 148 return true; 149 } 150 151 152 public String toString() { 153 if (prefixString == null) { 154 return ""; 155 } 156 157 String str = ""; 158 if (arraySize == 0) { 159 str = prefixString; 161 } 162 else { 163 str = new StringBuffer (prefixString.length() + arraySize) 166 .append(prefixString) 167 .append(array, 0, arraySize) 168 .toString(); 169 } 170 return str; 171 } 172 173 private void ensureCapacity(int csize) { 175 int capacity = array.length; 176 if (csize > capacity) { 177 char[] old = array; 178 int nsize = capacity; 179 while (csize > nsize) { 180 nsize += (capacity/2); 181 } 182 array = new char[nsize]; 183 System.arraycopy(old, 0, array, 0, arraySize); 184 } 185 } 186 } 187 | Popular Tags |