示例#1
0
 protected internal void replace0(int start, int end, String s)
 {
     if (start >= 0)
     {
         if (end > count)
         {
             end = count;
         }
         if (end > start)
         {
             int stringLength = s.length();
             int diff         = end - start - stringLength;
             if (diff > 0)   // replacing with fewer characters
             {
                 if (!shared)
                 {
                     // index == count case is no-op
                     java.lang.SystemJ.arraycopy(value, end, value, start
                                                 + stringLength, count - end);
                 }
                 else
                 {
                     char[] newData = new char[value.Length];
                     java.lang.SystemJ.arraycopy(value, 0, newData, 0, start);
                     // index == count case is no-op
                     java.lang.SystemJ.arraycopy(value, end, newData, start
                                                 + stringLength, count - end);
                     value  = newData;
                     shared = false;
                 }
             }
             else if (diff < 0)
             {
                 // replacing with more characters...need some room
                 move(-diff, end);
             }
             else if (shared)
             {
                 char[] clone = new char[value.Length];
                 SystemJ.arraycopy(value, 0, clone, 0, value.Length);
                 value  = clone;
                 shared = false;
             }
             s.getChars(0, stringLength, value, start);
             count -= diff;
             return;
         }
         if (start == end)
         {
             if (s == null)
             {
                 throw new java.lang.NullPointerException();
             }
             insert0(start, s);
             return;
         }
     }
     throw new StringIndexOutOfBoundsException();
 }
示例#2
0
 /**
  * Sets the character at the {@code index}.
  *
  * @param index
  *            the zero-based index of the character to replace.
  * @param ch
  *            the character to set.
  * @throws IndexOutOfBoundsException
  *             if {@code index} is negative or greater than or equal to the
  *             current {@link #length()}.
  */
 public virtual void setCharAt(int index, char ch)
 {
     if (0 > index || index >= count)
     {
         throw new StringIndexOutOfBoundsException(index);
     }
     if (shared)
     {
         char[] clone = new char[value.Length];
         SystemJ.arraycopy(value, 0, clone, 0, value.Length);
         value  = clone;
         shared = false;
     }
     value[index] = ch;
 }
示例#3
0
 public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
 {
     if (srcBegin < 0)
     {
         throw new StringIndexOutOfBoundsException(srcBegin);
     }
     if (srcEnd > this.delegateInstance.Length)
     {
         throw new StringIndexOutOfBoundsException(srcEnd);
     }
     if (srcBegin > srcEnd)
     {
         throw new StringIndexOutOfBoundsException(srcEnd - srcBegin);
     }
     SystemJ.arraycopy(this.delegateInstance.ToCharArray(), 0 + srcBegin, dst, dstBegin,
                       srcEnd - srcBegin);
 }