List of usage examples for java.text ParsePosition setIndex
public void setIndex(int index)
From source file:routines.system.BigDataParserUtils.java
public synchronized static java.util.Date parseTo_Date(String s, String pattern) { if (isBlank(s)) { return null; }// w ww .j a v a 2 s. co m String s2 = s.trim(); String pattern2 = pattern; if (isBlank(pattern2)) { pattern2 = Constant.dateDefaultPattern; } java.util.Date date = null; if (pattern2.equals("yyyy-MM-dd'T'HH:mm:ss'000Z'")) { if (!s2.endsWith("000Z")) { throw new RuntimeException("Unparseable date: \"" + s2 + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } pattern2 = "yyyy-MM-dd'T'HH:mm:ss"; s2 = s.substring(0, s.lastIndexOf("000Z")); } DateFormat format = FastDateParser.getInstance(pattern2); ParsePosition pp = new ParsePosition(0); pp.setIndex(0); format.setTimeZone(TimeZone.getTimeZone("UTC")); date = format.parse(s2, pp); if (pp.getIndex() != s2.length() || date == null) { throw new RuntimeException("Unparseable date: \"" + s2 + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } return date; }
From source file:routines.system.BigDataParserUtils.java
public synchronized static java.util.Date parseTo_Date(String s, String pattern, boolean lenient) { if (isBlank(s)) { return null; }/* w ww . j a va 2 s. com*/ String s2 = s.trim(); String pattern2 = pattern; if (isBlank(pattern2)) { pattern2 = Constant.dateDefaultPattern; } java.util.Date date = null; if (pattern2.equals("yyyy-MM-dd'T'HH:mm:ss'000Z'")) { if (!s2.endsWith("000Z")) { throw new RuntimeException("Unparseable date: \"" + s2 + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } pattern2 = "yyyy-MM-dd'T'HH:mm:ss"; s2 = s2.substring(0, s.lastIndexOf("000Z")); } DateFormat format = FastDateParser.getInstance(pattern2, lenient); ParsePosition pp = new ParsePosition(0); pp.setIndex(0); format.setTimeZone(TimeZone.getTimeZone("UTC")); date = format.parse(s2, pp); if (pp.getIndex() != s2.length() || date == null) { throw new RuntimeException("Unparseable date: \"" + s2 + "\""); //$NON-NLS-1$ //$NON-NLS-2$ } return date; }
From source file:org.netxilia.api.impl.value.NumberParser.java
@Override public IGenericValue parse(String text) { String input = preprocess(text); ParsePosition pp = new ParsePosition(0); for (NumberFormat format : this.formats) { pp.setIndex(0); Number number = format.parse(input, pp); if (number != null && input.length() == pp.getIndex()) { return new NumberValue(number.doubleValue()); }//from w w w. ja v a2s . c o m } return null; }
From source file:com.anrisoftware.globalpom.format.locale.LocaleFormat.java
/** * @see #parse(String)//from w w w. ja v a 2s .c o m * * @param pos * the index {@link ParsePosition} position from where to start * parsing. */ public Locale parse(String source, ParsePosition pos) { source = source.substring(pos.getIndex()); try { Locale address = parseValue(source, pos); pos.setErrorIndex(-1); pos.setIndex(source.length() + 1); return address; } catch (ParseException e) { pos.setIndex(0); pos.setErrorIndex(0); return null; } }
From source file:com.anrisoftware.globalpom.version.VersionFormat.java
/** * @see #parseObject(String)//from w ww . jav a 2s . c om * * @param pos * the index {@link ParsePosition} position from where to start * parsing. */ public Version parse(String source, ParsePosition pos) { try { source = source.substring(pos.getIndex()); Version version = decodeVersion(source, pos); pos.setErrorIndex(-1); pos.setIndex(pos.getIndex() + source.length()); return version; } catch (NumberFormatException e) { log.errorParseNumber(e, source); pos.setIndex(0); pos.setErrorIndex(0); return null; } }
From source file:er.extensions.formatters.ERXSimpleHTMLFormatter.java
/** * Converts an HTML string into an ASCII string * starting from a given parse position. * @param string HTML string// www .j av a 2s . com * @param p current parsing position * @return ASCII representation of the string */ @Override public Object parseObject(String string, ParsePosition p) { int index = p.getIndex(); String substring = string.substring(index); String result; try { result = (String) parseObject(substring); p.setIndex(string.length() + 1); } catch (java.text.ParseException e) { result = null; } return result; }
From source file:com.anrisoftware.globalpom.format.enums.EnumFormat.java
/** * @see #parseObject(String, ParsePosition) *//*from www . ja v a 2 s. c o m*/ public EnumType parse(String source, ParsePosition pos) { try { source = source.substring(pos.getIndex()).toUpperCase(); @SuppressWarnings("unchecked") EnumType item = (EnumType) Enum.valueOf(enumType, source); pos.setErrorIndex(-1); pos.setIndex(source.length()); return item; } catch (IllegalArgumentException e) { pos.setIndex(0); pos.setErrorIndex(0); return null; } }
From source file:com.anrisoftware.globalpom.format.measurement.MeasureFormat.java
/** * @see #parse(String)/*w ww .jav a2s .c om*/ * * @param pos * the index {@link ParsePosition} position from where to start * parsing. */ public Measure<?> parse(String source, ParsePosition pos) { source = source.substring(pos.getIndex()); try { Measure<?> address = parseValue(source, pos); pos.setErrorIndex(-1); pos.setIndex(source.length()); return address; } catch (ParseException e) { pos.setIndex(0); pos.setErrorIndex(0); return null; } }
From source file:com.anrisoftware.fractions.format.FractionFormat.java
/** * @see #parseObject(String)/* www . jav a 2s. c om*/ * * @param pos * the index {@link ParsePosition} position from where to start * parsing. * * @throws ParseException * if the string is not in the correct format. */ public ContinuedFraction parse(String source, ParsePosition pos) throws ParseException { try { source = source.substring(pos.getIndex()); ContinuedFraction f = decodeFraction(source, pos); pos.setErrorIndex(-1); pos.setIndex(pos.getIndex() + source.length()); return f; } catch (NumberFormatException e) { log.errorParseNumber(e, source); pos.setIndex(0); pos.setErrorIndex(0); return null; } }
From source file:org.osaf.cosmo.eim.schema.text.DurationFormat.java
public Object parseObject(String source, ParsePosition pos) { if (pos.getIndex() > 0) return null; if (!PATTERN.matcher(source).matches()) { parseException = new ParseException("Invalid duration " + source, 0); pos.setErrorIndex(0);//from ww w . ja v a 2 s . c om return null; } Dur dur = new Dur(source); pos.setIndex(source.length()); return dur; }