[Pydev-cvs] org.python.pydev.core/src/org/python/pydev/core/structure FastStringBuffer.java, 1.3,
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-06-15 16:45:14
|
Update of /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/structure In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1941/src/org/python/pydev/core/structure Modified Files: FastStringBuffer.java Log Message: Minors: ParsingUtils accepts null instead of buffer (so, objects that don't need the actual values can just use it to skip comments, parenthesis, etc). Index: FastStringBuffer.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev.core/src/org/python/pydev/core/structure/FastStringBuffer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** FastStringBuffer.java 15 Jun 2008 13:15:04 -0000 1.3 --- FastStringBuffer.java 15 Jun 2008 16:45:20 -0000 1.4 *************** *** 14,18 **** * @author Fabio */ ! public final class FastStringBuffer { /** --- 14,18 ---- * @author Fabio */ ! public final class FastStringBuffer{ /** *************** *** 89,93 **** return this; } ! /** * Appends a char to the buffer. --- 89,93 ---- return this; } ! /** * Appends a char to the buffer. *************** *** 98,102 **** } value[count] = n; ! count ++; return this; } --- 98,102 ---- } value[count] = n; ! count++; return this; } *************** *** 117,121 **** return this; } ! /** * Appends an array of chars to the buffer. --- 117,121 ---- return this; } ! /** * Appends an array of chars to the buffer. *************** *** 152,156 **** } - /** * Reverses the contents on this buffer --- 152,155 ---- *************** *** 166,175 **** } - /** * Clears this buffer. */ ! public void clear() { this.count = 0; } --- 165,174 ---- } /** * Clears this buffer. */ ! public FastStringBuffer clear() { this.count = 0; + return this; } *************** *** 211,223 **** int len = str.length(); int newCount = count + len; ! if (newCount > value.length){ resizeForMinimum(newCount); } System.arraycopy(value, offset, value, offset + len, count - offset); ! str.getChars(0, str.length(), value, offset); count = newCount; return this; } ! /** * Inserts a char at a given position in the buffer. --- 210,222 ---- int len = str.length(); int newCount = count + len; ! if (newCount > value.length) { resizeForMinimum(newCount); } System.arraycopy(value, offset, value, offset + len, count - offset); ! str.getChars(0, len, value, offset); count = newCount; return this; } ! /** * Inserts a char at a given position in the buffer. *************** *** 225,229 **** public FastStringBuffer insert(int offset, char c) { int newCount = count + 1; ! if (newCount > value.length){ resizeForMinimum(newCount); } --- 224,228 ---- public FastStringBuffer insert(int offset, char c) { int newCount = count + 1; ! if (newCount > value.length) { resizeForMinimum(newCount); } *************** *** 238,242 **** */ public FastStringBuffer appendObject(Object object) { ! return append(object != null?object.toString():"null"); } --- 237,241 ---- */ public FastStringBuffer appendObject(Object object) { ! return append(object != null ? object.toString() : "null"); } *************** *** 248,250 **** --- 247,315 ---- } + public FastStringBuffer delete(int start, int end) { + if (start < 0) + throw new StringIndexOutOfBoundsException(start); + if (end > count) + end = count; + if (start > end) + throw new StringIndexOutOfBoundsException(); + int len = end - start; + if (len > 0) { + System.arraycopy(value, start + len, value, start, count - end); + count -= len; + } + return this; + } + + public FastStringBuffer replace(int start, int end, String str) { + if (start < 0) + throw new StringIndexOutOfBoundsException(start); + if (start > count) + throw new StringIndexOutOfBoundsException("start > length()"); + if (start > end) + throw new StringIndexOutOfBoundsException("start > end"); + if (end > count) + end = count; + + if (end > count) + end = count; + int len = str.length(); + int newCount = count + len - (end - start); + if (newCount > value.length) { + resizeForMinimum(newCount); + } + + System.arraycopy(value, end, value, start + len, count - end); + str.getChars(0, len, value, start); + count = newCount; + return this; + } + + public FastStringBuffer deleteCharAt(int index) { + if ((index < 0) || (index >= count)) { + throw new StringIndexOutOfBoundsException(index); + } + System.arraycopy(value, index + 1, value, index, count - index - 1); + count--; + return this; + } + + public int indexOf(char c) { + for(int i=0;i<this.count;i++){ + if(c == this.value[i]){ + return i; + } + } + return -1; + } + + public char firstChar() { + return this.value[0]; + } + + public char lastChar() { + return this.value[this.count-1]; + } + + } |