Helper: return substring for [start, end).
(int start, int end)
| 380 | |
| 381 | /** Helper: return substring for [start, end). */ |
| 382 | String substring(int start, int end) { |
| 383 | // UTF_8 is matched in binary mode. So slice the bytes. |
| 384 | if (matcherInput.getEncoding() == Encoding.UTF_8) { |
| 385 | try { |
| 386 | return new String(matcherInput.asBytes(), start, end - start, "UTF-8"); |
| 387 | } catch (UnsupportedEncodingException e) { |
| 388 | throw new RuntimeException(e); // Not possible. |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | // This is fast for both StringBuilder and String. |
| 393 | return matcherInput.asCharSequence().subSequence(start, end).toString(); |
| 394 | } |
| 395 | |
| 396 | /** Helper for Pattern: return input length. */ |
| 397 | int inputLength() { |