Refine search
/** * <p>Parsing is not supported.</p> * * @param source the string to parse * @param pos the parsing position * @return <code>null</code> as not supported */ public Object parseObject(String source, ParsePosition pos) { pos.setIndex(0); pos.setErrorIndex(0); return null; }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { final Matcher matcher = pattern.matcher(source.substring(pos.getIndex())); if (!matcher.lookingAt()) { pos.setErrorIndex(pos.getIndex()); return false; } pos.setIndex(pos.getIndex() + matcher.end(1)); setCalendar(parser, calendar, matcher.group(1)); return true; }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { for (int idx = 0; idx < formatField.length(); ++idx) { final int sIdx = idx + pos.getIndex(); if (sIdx == source.length()) { pos.setErrorIndex(sIdx); return false; } if (formatField.charAt(idx) != source.charAt(sIdx)) { pos.setErrorIndex(sIdx); return false; } } pos.setIndex(formatField.length() + pos.getIndex()); return true; } }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { final Matcher matcher = pattern.matcher(source.substring(pos.getIndex())); if (!matcher.lookingAt()) { pos.setErrorIndex(pos.getIndex()); return false; } pos.setIndex(pos.getIndex() + matcher.end(1)); setCalendar(parser, calendar, matcher.group(1)); return true; }
private Date parseDate(String str, String[] parsePatterns, Locale locale) throws ParseException { if ((str == null) || (parsePatterns == null)) { throw new IllegalArgumentException("Date and Patterns must not be null"); } SimpleDateFormat parser = null; ParsePosition pos = new ParsePosition(0); for (int i = 0; i < parsePatterns.length; i++) { if (i == 0) { parser = new SimpleDateFormat(parsePatterns[0], locale); } else { parser.applyPattern(parsePatterns[i]); } pos.setIndex(0); Date date = parser.parse(str, pos); if ((date != null) && (pos.getIndex() == str.length())) { return date; } } throw new ParseException("Unable to parse the date: " + str, -1); } }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { final Matcher matcher = pattern.matcher(source.substring(pos.getIndex())); if (!matcher.lookingAt()) { pos.setErrorIndex(pos.getIndex()); return false; } pos.setIndex(pos.getIndex() + matcher.end(1)); setCalendar(parser, calendar, matcher.group(1)); return true; }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(final String pattern, final ParsePosition pos) { int len = 0; final char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { for (int idx = 0; idx < formatField.length(); ++idx) { final int sIdx = idx + pos.getIndex(); if (sIdx == source.length()) { pos.setErrorIndex(sIdx); return false; } if (formatField.charAt(idx) != source.charAt(sIdx)) { pos.setErrorIndex(sIdx); return false; } } pos.setIndex(formatField.length() + pos.getIndex()); return true; } }
/** * Consume whitespace from the current parse position. * * @param pattern String to read * @param pos current position */ private void seekNonWs(String pattern, ParsePosition pos) { int len = 0; char[] buffer = pattern.toCharArray(); do { len = StrMatcher.splitMatcher().isMatch(buffer, pos.getIndex()); pos.setIndex(pos.getIndex() + len); } while (len > 0 && pos.getIndex() < pattern.length()); }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { for (int idx = 0; idx < formatField.length(); ++idx) { final int sIdx = idx + pos.getIndex(); if (sIdx == source.length()) { pos.setErrorIndex(sIdx); return false; } if (formatField.charAt(idx) != source.charAt(sIdx)) { pos.setErrorIndex(sIdx); return false; } } pos.setIndex(formatField.length() + pos.getIndex()); return true; } }
/** * Parses <code>source</code> until a non-whitespace character is found. * @param source the string to parse * @param pos input/output parsing parameter. On output, <code>pos</code> * holds the index of the next non-whitespace character. */ protected static void parseAndIgnoreWhitespace(final String source, final ParsePosition pos) { parseNextCharacter(source, pos); pos.setIndex(pos.getIndex() - 1); }
@Override boolean parse(final FastDateParser parser, final Calendar calendar, final String source, final ParsePosition pos, final int maxWidth) { int idx = pos.getIndex(); int last = source.length(); pos.setIndex(idx); } else { final int end = idx + maxWidth; if (pos.getIndex() == idx) { pos.setErrorIndex(idx); return false; final int value = Integer.parseInt(source.substring(pos.getIndex(), idx)); pos.setIndex(idx);
static boolean upTo(String string, ParsePosition position, StringBuffer buffer, char stop) { int index = position.getIndex(), length = string.length(); boolean lastQuote = false, quote = false; while (index < length) { char ch = string.charAt(index++); if (ch == '\'') { if (lastQuote) { buffer.append('\''); } quote = !quote; lastQuote = true; } else if (ch == stop && !quote) { position.setIndex(index); return true; } else { lastQuote = false; buffer.append(ch); } } position.setIndex(index); return false; }
/** * Parse <code>source</code> for an expected fixed string. * @param source the string to parse * @param expected expected string * @param pos input/output parsing parameter. * @return true if the expected string was there */ public static boolean parseFixedstring(final String source, final String expected, final ParsePosition pos) { final int startIndex = pos.getIndex(); final int endIndex = startIndex + expected.length(); if ((startIndex >= source.length()) || (endIndex > source.length()) || (source.substring(startIndex, endIndex).compareTo(expected) != 0)) { // set index back to start, error index should be the start index pos.setIndex(startIndex); pos.setErrorIndex(startIndex); return false; } // the string was here pos.setIndex(endIndex); return true; }
/** * Parses a string to produce a <code>BigInteger</code>. * @param source the string to parse * @param pos input/output parsing parameter. * @return a parsed <code>BigInteger</code> or null if string does not * contain a BigInteger at the specified position */ protected BigInteger parseNextBigInteger(final String source, final ParsePosition pos) { final int start = pos.getIndex(); int end = (source.charAt(start) == '-') ? (start + 1) : start; while((end < source.length()) && Character.isDigit(source.charAt(end))) { ++end; } try { BigInteger n = new BigInteger(source.substring(start, end)); pos.setIndex(end); return n; } catch (NumberFormatException nfe) { pos.setErrorIndex(start); return null; } }
/** * Parses <code>source</code> until a non-whitespace character is found. * * @param source the string to parse * @param pos input/output parsing parameter. On output, <code>pos</code> * holds the index of the next non-whitespace character. */ public static void parseAndIgnoreWhitespace(final String source, final ParsePosition pos) { parseNextCharacter(source, pos); pos.setIndex(pos.getIndex() - 1); }