private static IVersionFormat parseFormat(String versionRange, int[] position) { int pos = VersionParser.skipWhite(versionRange, position[0]); if (!versionRange.startsWith("format(", pos)) //$NON-NLS-1$ return null; pos += 7; int end = VersionParser.findEndOfFormat(versionRange, pos, versionRange.length()); try { position[0] = end + 1; return VersionFormat.compile(versionRange, pos, end); } catch (VersionFormatException e) { throw new IllegalArgumentException(e.getMessage()); } }
v = parseRawEnum(value, position, maxPos); if (v == null) return null; v = parseRawVector(value, position, maxPos); if (v == null) return null; if (isDigit(c)) { int start = current++; while (current < maxPos && isDigit(value.charAt(current))) ++current; int val = Integer.parseInt(value.substring(start, current)); if (negate) val = -val; v = valueOf(val); break;
int pos = skipWhite(version, start); maxPos = skipTrailingWhite(version, start, maxPos); if (pos == maxPos) return null; VersionFormat fmt = null; char c = version.charAt(pos); if (isDigit(c)) { return OSGiVersion.fromVector(VersionFormat.OSGI_FORMAT.parse(version, pos, maxPos)); if (!isLetter(c)) throw new IllegalArgumentException(); int end = findEndOfFormat(version, pos, maxPos); fmt = VersionFormat.compile(version, pos, end); pos = end + 1;
if (versionRange != null) { top = versionRange.length(); pos = VersionParser.skipWhite(versionRange, 0); top = VersionParser.skipTrailingWhite(versionRange, pos, top); boolean rawPrefix = false; IVersionFormat fmt = null; if (VersionParser.isLetter(c)) { if (versionRange.startsWith("raw:", pos)) { //$NON-NLS-1$ rawPrefix = true; pos = VersionParser.skipWhite(versionRange, pos); if (pos >= top) throw new IllegalArgumentException(NLS.bind(Messages.premature_EOS_0, versionRange)); String origMin = null; String origMax = null; pos = VersionParser.skipWhite(versionRange, pos); if (pos < top && versionRange.charAt(pos) == '/') { if (++pos == top) position[0] = pos; fmt = parseFormat(versionRange, position); pos = VersionParser.skipWhite(versionRange, position[0]); if (pos < top) { boolean origUseIncDelims = false; pos = VersionParser.skipWhite(versionRange, ++pos); if (pos == top)
if (VersionParser.isDigit(c) && isAllowed(c) && (enumInstruction == null || enumInstruction.isOptional())) { while (++pos < maxPos) { c = version.charAt(pos); if (!(VersionParser.isDigit(c) && isAllowed(c))) break; value *= 10; segments.add(VersionParser.valueOf(value)); info.setPosition(pos); return true; if (!(VersionParser.isLetter(c) && isAllowed(c))) return false; if (!(VersionParser.isLetter(c) && isAllowed(c))) break;
Comparable<?> elem = parseRawElement(value, position, maxPos); if (elem == null) return null; return null; pad = removeRedundantTrail(rawList, pad); return new VersionVector(rawList.toArray(new Comparable[rawList.size()]), pad);
boolean isMatch(String version, int pos) { char c = version.charAt(pos); if (delimChars != null) { for (int idx = 0; idx < delimChars.length; ++idx) if (c == delimChars[idx]) return !inverted; return inverted; } else if (VersionParser.isLetterOrDigit(c)) return false; return true; }
private Comparable<?> parseRawElement() throws VersionFormatException { int[] position = new int[] {current}; Comparable<?> v = VersionParser.parseRawElement(format, position, eos); if (v == null) throw new VersionFormatException(NLS.bind(Messages.raw_element_expected_0, format)); current = position[0]; return v; }
List<Comparable<?>> parse(String version, int start, int maxPos) { if (start == maxPos) throw new IllegalArgumentException(NLS.bind(Messages.format_0_unable_to_parse_empty_version, this, version.substring(start, maxPos))); TreeInfo info = new TreeInfo(topFragment, start); ArrayList<Comparable<?>> entries = new ArrayList<Comparable<?>>(5); if (!(topFragment.parse(entries, version, maxPos, info) && info.getPosition() == maxPos)) throw new IllegalArgumentException(NLS.bind(Messages.format_0_unable_to_parse_1, this, version.substring(start, maxPos))); entries.add(VersionParser.removeRedundantTrail(entries, info.getPadValue())); return entries; }
private int parseIntegerLiteral() throws VersionFormatException { if (current == eos) throw formatException(NLS.bind(Messages.premature_end_of_format_expected_0, "<integer>")); //$NON-NLS-1$ char c = format.charAt(current); if (!VersionParser.isDigit(c)) throw formatException(c, "<integer>"); //$NON-NLS-1$ int value = c - '0'; while (++current < eos) { c = format.charAt(current); if (!VersionParser.isDigit(c)) break; value *= 10; value += (c - '0'); } return value; }
EnumSegment getEnumSegment(RangeFragment fragment, String version, int[] posHolder, int maxPos) { int pos = posHolder[0]; int len = maxPos - pos; int minLen = definition.getShortestLength(); if (minLen > len) return null; int maxLen = definition.getLongestLength(); if (maxLen < len) len = maxLen; ++len; while (--len >= minLen) { int last = pos + len; if (!begins && last < maxPos) { char c = version.charAt(last); if (VersionParser.isLetter(c) && fragment.isAllowed(c)) { // We are not allowed to truncate at this point continue; } } String identifier = version.substring(pos, last); if (!caseSensitive) identifier = identifier.toLowerCase(); int ordinal = definition.getOrdinal(identifier); if (ordinal >= 0) { posHolder[0] = pos + len; return definition.getSegment(ordinal); } } return null; }
/** * Parses a version identifier from the specified string. * * @param version String representation of the version identifier. Leading * and trailing whitespace will be ignored. * @return A <code>Version</code> object representing the version identifier * or <code>null</code> if <code>version</code> is <code>null</code> or * an empty string. * @throws IllegalArgumentException If <code>version</code> is improperly * formatted. */ public static Version create(String version) { return version == null ? null : VersionParser.parse(version, 0, version.length()); }
break; default : if (VersionParser.isLetterOrDigit(c)) { sb.append('\\'); sb.append(c);
boolean parseOne(List<Comparable<?>> segments, String version, int maxPos, TreeInfo info) { int[] position = new int[] {info.getPosition()}; Comparable<?> v = VersionParser.parseRawElement(version, position, maxPos); if (v == null) return false; if (!isIgnored()) segments.add(v); info.setPosition(position[0]); return true; }
boolean parseOne(List<Comparable<?>> segments, String version, int maxPos, TreeInfo info) { if (array) { ArrayList<Comparable<?>> subSegs = new ArrayList<Comparable<?>>(); boolean success = fragments[0].getQualifier().parse(fragments, 0, subSegs, version, maxPos, info); if (!success || subSegs.isEmpty()) return false; Comparable<?> padValue = info.getPadValue(); if (padValue != null) info.setPadValue(null); // Prevent outer group from getting this. else padValue = getPadValue(); padValue = VersionParser.removeRedundantTrail(segments, padValue); segments.add(new VersionVector(subSegs.toArray(new Comparable[subSegs.size()]), padValue)); return true; } if (fragments[0].getQualifier().parse(fragments, 0, segments, version, maxPos, info)) { Comparable<?> padValue = getPadValue(); if (padValue != null) info.setPadValue(padValue); return true; } return false; }
throw formatException(Messages.premature_end_of_format); if (VersionParser.isDigit(format.charAt(current + 1))) {
break; default : if (VersionParser.isLetterOrDigit(quote)) return false; endQuote = quote;
boolean parseOne(List<Comparable<?>> segments, String version, int maxPos, TreeInfo info) { int pos = info.getPosition(); if (pos >= maxPos || version.charAt(pos) != 'p') return false; int[] position = new int[] {++pos}; Comparable<?> v = VersionParser.parseRawElement(version, position, maxPos); if (v == null) return false; if (!isIgnored()) info.setPadValue(v); info.setPosition(position[0]); return true; }