Exemple #1
0
 /**
  * Copies the character from this text builder into the destination character array.
  *
  * @param srcBegin this text start index.
  * @param srcEnd this text end index (not included).
  * @param dst the destination array to copy the data into.
  * @param dstBegin the offset into the destination array.
  * @throws IndexOutOfBoundsException if <code>(srcBegin < 0) ||
  *  (dstBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this.length())
  *  || ((dstBegin + srcEnd - srcBegin) >  dst.length)</code>
  */
 public final void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) {
   if ((srcBegin < 0) || (srcBegin > srcEnd) || (srcEnd > this._length))
     throw new IndexOutOfBoundsException();
   for (int i = srcBegin, j = dstBegin; i < srcEnd; ) {
     char[] chars0 = _high[i >> B1];
     int i0 = i & M1;
     int length = MathLib.min(C1 - i0, srcEnd - i);
     System.arraycopy(chars0, i0, dst, j, length);
     i += length;
     j += length;
   }
 }
Exemple #2
0
 /**
  * Appends the characters from a subarray of the char array argument.
  *
  * @param chars the character array source.
  * @param offset the index of the first character to append.
  * @param length the number of character to append.
  * @return <code>this</code>
  * @throws IndexOutOfBoundsException if <code>(offset < 0) ||
  *         (length < 0) || ((offset + length) > chars.length)</code>
  */
 public final TextBuilder append(char chars[], int offset, int length) {
   final int end = offset + length;
   if ((offset < 0) || (length < 0) || (end > chars.length)) throw new IndexOutOfBoundsException();
   int newLength = _length + length;
   while (_capacity < newLength) {
     increaseCapacity();
   }
   for (int i = offset, j = _length; i < end; ) {
     char[] dstChars = _high[j >> B1];
     int dstBegin = j & M1;
     int inc = MathLib.min(C1 - dstBegin, end - i);
     System.arraycopy(chars, i, dstChars, dstBegin, inc);
     i += inc;
     j += inc;
   }
   _length = newLength;
   return this;
 }
Exemple #3
0
 /**
  * Appends a subsequence of the specified text. If the specified character sequence is <code>null
  * </code> this method is equivalent to <code>append("null")</code>.
  *
  * @param txt the text to append or <code>null</code>.
  * @param start the index of the first character to append.
  * @param end the index after the last character to append.
  * @return <code>this</code>
  * @throws IndexOutOfBoundsException if <code>(start < 0) || (end < 0)
  *         || (start > end) || (end > txt.length())</code>
  */
 public final TextBuilder append(Text txt, int start, int end) {
   if (txt == null) return append("null");
   if ((start < 0) || (end < 0) || (start > end) || (end > txt.length()))
     throw new IndexOutOfBoundsException();
   int newLength = _length + end - start;
   while (_capacity < newLength) {
     increaseCapacity();
   }
   for (int i = start, j = _length; i < end; ) {
     char[] chars = _high[j >> B1];
     int dstBegin = j & M1;
     int inc = MathLib.min(C1 - dstBegin, end - i);
     txt.getChars(i, (i += inc), chars, dstBegin);
     j += inc;
   }
   _length = newLength;
   return this;
 }
Exemple #4
0
 /**
  * Prints out this text builder to the specified writer.
  *
  * @param writer the destination writer.
  */
 public void print(Writer writer) throws IOException {
   for (int i = 0; i < _length; i += C1) {
     char[] chars = _high[i >> B1];
     writer.write(chars, 0, MathLib.min(C1, _length - i));
   }
 }