| 52 | } |
| 53 | |
| 54 | protected String replace(String replacement, int limit) { |
| 55 | reset(); |
| 56 | |
| 57 | StringBuilder sb = null; |
| 58 | int index = 0; |
| 59 | int count = 0; |
| 60 | while (count < limit && index < input.length()) { |
| 61 | if (find(index)) { |
| 62 | if (sb == null) { |
| 63 | sb = new StringBuilder(); |
| 64 | } |
| 65 | if (start > index) { |
| 66 | sb.append(input.subSequence(index, start)); |
| 67 | } |
| 68 | sb.append(replacement); |
| 69 | index = end; |
| 70 | ++ count; |
| 71 | } else if (index == 0) { |
| 72 | return input.toString(); |
| 73 | } else { |
| 74 | break; |
| 75 | } |
| 76 | } |
| 77 | if (index < input.length()) { |
| 78 | sb.append(input.subSequence(index, input.length())); |
| 79 | } |
| 80 | return sb.toString(); |
| 81 | } |
| 82 | |
| 83 | public int start() { |
| 84 | return start; |