| 133 | } |
| 134 | |
| 135 | public StringBuilder insert(int i, String s) { |
| 136 | if (i < 0 || i > length) { |
| 137 | throw new IndexOutOfBoundsException(); |
| 138 | } |
| 139 | |
| 140 | if (i == length) { |
| 141 | append(s); |
| 142 | } else { |
| 143 | flush(); |
| 144 | |
| 145 | int index = length; |
| 146 | for (Cell c = chain; c != null; c = c.next) { |
| 147 | int start = index - c.value.length(); |
| 148 | index = start; |
| 149 | |
| 150 | if (i >= start) { |
| 151 | if (i == start) { |
| 152 | c.next = new Cell(s, c.next); |
| 153 | } else { |
| 154 | String v = c.value; |
| 155 | c.value = v.substring(i - start, v.length()); |
| 156 | c.next = new Cell(s, new Cell(v.substring(0, i - start), c.next)); |
| 157 | } |
| 158 | break; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | length += s.length(); |
| 163 | } |
| 164 | |
| 165 | return this; |
| 166 | } |
| 167 | |
| 168 | public StringBuilder insert(int i, CharSequence s) { |
| 169 | return insert(i, s.toString()); |