emul/src/main/java/java/lang/AbstractStringBuilder.java
changeset 104 1376481f15e7
parent 94 19497b4312bb
child 116 033d51e026b0
     1.1 --- a/emul/src/main/java/java/lang/AbstractStringBuilder.java	Tue Oct 09 11:11:58 2012 -0700
     1.2 +++ b/emul/src/main/java/java/lang/AbstractStringBuilder.java	Tue Oct 16 11:55:56 2012 +0200
     1.3 @@ -126,7 +126,7 @@
     1.4                  throw new OutOfMemoryError();
     1.5              newCapacity = Integer.MAX_VALUE;
     1.6          }
     1.7 -        value = String.copyOf(value, newCapacity);
     1.8 +        value = copyOf(value, newCapacity);
     1.9      }
    1.10  
    1.11      /**
    1.12 @@ -138,7 +138,7 @@
    1.13       */
    1.14      public void trimToSize() {
    1.15          if (count < value.length) {
    1.16 -            value = String.copyOf(value, count);
    1.17 +            value = copyOf(value, count);
    1.18          }
    1.19      }
    1.20  
    1.21 @@ -352,7 +352,7 @@
    1.22              throw new StringIndexOutOfBoundsException(srcEnd);
    1.23          if (srcBegin > srcEnd)
    1.24              throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
    1.25 -        String.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
    1.26 +        arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
    1.27      }
    1.28  
    1.29      /**
    1.30 @@ -502,7 +502,7 @@
    1.31      public AbstractStringBuilder append(char[] str) {
    1.32          int len = str.length;
    1.33          ensureCapacityInternal(count + len);
    1.34 -        String.arraycopy(str, 0, value, count, len);
    1.35 +        arraycopy(str, 0, value, count, len);
    1.36          count += len;
    1.37          return this;
    1.38      }
    1.39 @@ -532,7 +532,7 @@
    1.40      public AbstractStringBuilder append(char str[], int offset, int len) {
    1.41          if (len > 0)                // let arraycopy report AIOOBE for len < 0
    1.42              ensureCapacityInternal(count + len);
    1.43 -        String.arraycopy(str, offset, value, count, len);
    1.44 +        arraycopy(str, offset, value, count, len);
    1.45          count += len;
    1.46          return this;
    1.47      }
    1.48 @@ -699,7 +699,7 @@
    1.49              throw new StringIndexOutOfBoundsException();
    1.50          int len = end - start;
    1.51          if (len > 0) {
    1.52 -            String.arraycopy(value, start+len, value, start, count-end);
    1.53 +            arraycopy(value, start+len, value, start, count-end);
    1.54              count -= len;
    1.55          }
    1.56          return this;
    1.57 @@ -761,7 +761,7 @@
    1.58      public AbstractStringBuilder deleteCharAt(int index) {
    1.59          if ((index < 0) || (index >= count))
    1.60              throw new StringIndexOutOfBoundsException(index);
    1.61 -        String.arraycopy(value, index+1, value, index, count-index-1);
    1.62 +        arraycopy(value, index+1, value, index, count-index-1);
    1.63          count--;
    1.64          return this;
    1.65      }
    1.66 @@ -799,7 +799,7 @@
    1.67          int newCount = count + len - (end - start);
    1.68          ensureCapacityInternal(newCount);
    1.69  
    1.70 -        String.arraycopy(value, end, value, start + len, count - end);
    1.71 +        arraycopy(value, end, value, start + len, count - end);
    1.72          str.getChars(value, start);
    1.73          count = newCount;
    1.74          return this;
    1.75 @@ -905,8 +905,8 @@
    1.76                  "offset " + offset + ", len " + len + ", str.length "
    1.77                  + str.length);
    1.78          ensureCapacityInternal(count + len);
    1.79 -        String.arraycopy(value, index, value, index + len, count - index);
    1.80 -        String.arraycopy(str, offset, value, index, len);
    1.81 +        arraycopy(value, index, value, index + len, count - index);
    1.82 +        arraycopy(str, offset, value, index, len);
    1.83          count += len;
    1.84          return this;
    1.85      }
    1.86 @@ -972,7 +972,7 @@
    1.87              str = "null";
    1.88          int len = str.length();
    1.89          ensureCapacityInternal(count + len);
    1.90 -        String.arraycopy(value, offset, value, offset + len, count - offset);
    1.91 +        arraycopy(value, offset, value, offset + len, count - offset);
    1.92          str.getChars(value, offset);
    1.93          count += len;
    1.94          return this;
    1.95 @@ -1007,8 +1007,8 @@
    1.96              throw new StringIndexOutOfBoundsException(offset);
    1.97          int len = str.length;
    1.98          ensureCapacityInternal(count + len);
    1.99 -        String.arraycopy(value, offset, value, offset + len, count - offset);
   1.100 -        String.arraycopy(str, 0, value, offset, len);
   1.101 +        arraycopy(value, offset, value, offset + len, count - offset);
   1.102 +        arraycopy(str, 0, value, offset, len);
   1.103          count += len;
   1.104          return this;
   1.105      }
   1.106 @@ -1098,7 +1098,7 @@
   1.107                  + s.length());
   1.108          int len = end - start;
   1.109          ensureCapacityInternal(count + len);
   1.110 -        String.arraycopy(value, dstOffset, value, dstOffset + len,
   1.111 +        arraycopy(value, dstOffset, value, dstOffset + len,
   1.112                           count - dstOffset);
   1.113          for (int i=start; i<end; i++)
   1.114              value[dstOffset++] = s.charAt(i);
   1.115 @@ -1150,7 +1150,7 @@
   1.116       */
   1.117      public AbstractStringBuilder insert(int offset, char c) {
   1.118          ensureCapacityInternal(count + 1);
   1.119 -        String.arraycopy(value, offset, value, offset + 1, count - offset);
   1.120 +        arraycopy(value, offset, value, offset + 1, count - offset);
   1.121          value[offset] = c;
   1.122          count += 1;
   1.123          return this;
   1.124 @@ -1405,4 +1405,31 @@
   1.125          return value;
   1.126      }
   1.127  
   1.128 +    static char[] copyOfRange(char[] original, int from, int to) {
   1.129 +        int newLength = to - from;
   1.130 +        if (newLength < 0) {
   1.131 +            throw new IllegalArgumentException(from + " > " + to);
   1.132 +        }
   1.133 +        char[] copy = new char[newLength];
   1.134 +        arraycopy(original, from, copy, 0, Math.min(original.length - from, newLength));
   1.135 +        return copy;
   1.136 +    }
   1.137 +
   1.138 +    static void arraycopy(char[] value, int srcBegin, char[] dst, int dstBegin, int count) {
   1.139 +        while (count-- > 0) {
   1.140 +            dst[dstBegin++] = value[srcBegin++];
   1.141 +        }
   1.142 +    }
   1.143 +
   1.144 +    // access system property
   1.145 +    static String getProperty(String nm) {
   1.146 +        return null;
   1.147 +    }
   1.148 +
   1.149 +    static char[] copyOf(char[] original, int newLength) {
   1.150 +        char[] copy = new char[newLength];
   1.151 +        arraycopy(original, 0, copy, 0, Math.min(original.length, newLength));
   1.152 +        return copy;
   1.153 +    }
   1.154 +    
   1.155  }