(
String period,
int from,
int to,
int typeID,
List<Item<U>> items
)
| 3533 | } |
| 3534 | |
| 3535 | private static <U extends ChronoUnit> boolean parse( |
| 3536 | String period, |
| 3537 | int from, |
| 3538 | int to, |
| 3539 | int typeID, |
| 3540 | List<Item<U>> items |
| 3541 | ) throws ParseException { |
| 3542 | |
| 3543 | // alternative format? |
| 3544 | char ending = period.charAt(to - 1); |
| 3545 | |
| 3546 | if ((ending >= '0') && (ending <= '9') && (typeID != WEEK_BASED_TYPE)) { |
| 3547 | parseAlt(period, from, to, (typeID == CALENDAR_TYPE), items); |
| 3548 | return true; |
| 3549 | } |
| 3550 | |
| 3551 | if (from == to) { |
| 3552 | throw new ParseException(period, from); |
| 3553 | } |
| 3554 | |
| 3555 | StringBuilder num = null; |
| 3556 | boolean endOfItem = false; |
| 3557 | ChronoUnit last = null; |
| 3558 | int index = from; |
| 3559 | boolean decimal = false; |
| 3560 | |
| 3561 | for (int i = from; i < to; i++) { |
| 3562 | char c = period.charAt(i); |
| 3563 | |
| 3564 | if ((c >= '0') && (c <= '9')) { |
| 3565 | if (num == null) { |
| 3566 | num = new StringBuilder(); |
| 3567 | endOfItem = false; |
| 3568 | index = i; |
| 3569 | } |
| 3570 | num.append(c); |
| 3571 | } else if ((c == ',') || (c == '.')) { |
| 3572 | if ((num == null) || (typeID != CLOCK_TYPE)) { |
| 3573 | throw new ParseException( |
| 3574 | "Decimal separator misplaced: " + period, i); |
| 3575 | } else { |
| 3576 | endOfItem = true; |
| 3577 | long amount = parseAmount(period, num.toString(), index); |
| 3578 | last = addParsedItem(SECONDS, last, amount, period, i, items); |
| 3579 | num = null; |
| 3580 | decimal = true; |
| 3581 | } |
| 3582 | } else if (endOfItem) { |
| 3583 | throw new ParseException( |
| 3584 | "Unexpected char \'" + c + "\' found: " + period, i); |
| 3585 | } else if (decimal) { |
| 3586 | if (c != 'S') { |
| 3587 | throw new ParseException("Second symbol expected: " + period, i); |
| 3588 | } else if (num == null) { |
| 3589 | throw new ParseException("Decimal separator misplaced: " + period, i - 1); |
| 3590 | } else if (num.length() > 9) { |
| 3591 | num.delete(9, num.length()); |
| 3592 | } |
no test coverage detected