| 178 | } |
| 179 | |
| 180 | public StringBuilder delete(int start, int end) { |
| 181 | if (start >= end) { |
| 182 | return this; |
| 183 | } |
| 184 | |
| 185 | if (start < 0 || end > length) { |
| 186 | throw new IndexOutOfBoundsException(); |
| 187 | } |
| 188 | |
| 189 | flush(); |
| 190 | |
| 191 | int index = length; |
| 192 | Cell p = null; |
| 193 | for (Cell c = chain; c != null; c = c.next) { |
| 194 | int e = index; |
| 195 | int s = index - c.value.length(); |
| 196 | index = s; |
| 197 | |
| 198 | if (end >= e) { |
| 199 | if (start <= s) { |
| 200 | if (p == null) { |
| 201 | chain = c.next; |
| 202 | } else { |
| 203 | p.next = c.next; |
| 204 | } |
| 205 | } else { |
| 206 | c.value = c.value.substring(0, start - s); |
| 207 | break; |
| 208 | } |
| 209 | } else { |
| 210 | if (start <= s) { |
| 211 | c.value = c.value.substring(end - s, e - s); |
| 212 | } else { |
| 213 | String v = c.value; |
| 214 | c.value = v.substring(end - s, e - s); |
| 215 | c.next = new Cell(v.substring(0, start - s), c.next); |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | length -= (end - start); |
| 222 | |
| 223 | return this; |
| 224 | } |
| 225 | |
| 226 | public StringBuilder deleteCharAt(int i) { |
| 227 | return delete(i, i + 1); |