use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class PlacePropertyValueList method parse.
public static PlacePropertyValueList parse(String token) {
final String globalFlag = "g";
RegExp regExp = RegExp.compile("([^" + PROPERTY_VALUE_SEPARATOR + "]+)" + PROPERTY_VALUE_SEPARATOR + "([^" + PROPERTY_VALUE_ITEM_SEPARATOR + "]+)" + PROPERTY_VALUE_ITEM_SEPARATOR, globalFlag);
MatchResult matchResult = regExp.exec(token);
Builder resultBuilder = builder();
while (matchResult != null) {
String name = URL.decodeQueryString(matchResult.getGroup(1));
String value = URL.decodeQueryString(matchResult.getGroup(2));
resultBuilder.set(name, value);
final int matchLength = matchResult.getGroup(0).length();
final int matchStart = matchResult.getIndex();
final int nextIndex = matchStart + matchLength;
regExp.setLastIndex(nextIndex);
matchResult = regExp.exec(token);
}
return resultBuilder.build();
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class ProjectSettingsPlaceTokenizer method getPlace.
@Override
public ProjectSettingsPlace getPlace(String token) {
MatchResult matchResult = regExp.exec(token);
if (matchResult == null) {
return null;
}
String projectIdString = matchResult.getGroup(1);
if (ProjectId.isWelFormedProjectId(projectIdString)) {
ProjectId projectId = ProjectId.get(projectIdString);
return new ProjectSettingsPlace(projectId, empty());
} else {
return null;
}
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class LanguageCodeParser method parse.
public List<LanguageCode> parse(String codes) {
String[] lines = codes.split("\n");
List<LanguageCode> result = new ArrayList<>();
for (String line : lines) {
String trimmedLine = line.trim();
if (pattern.test(trimmedLine)) {
MatchResult matchResult = pattern.exec(trimmedLine);
String lang = matchResult.getGroup(1);
String name = matchResult.getGroup(2);
result.add(new LanguageCode(lang, name));
}
}
return result;
}
use of com.google.gwt.regexp.shared.MatchResult in project webprotege by protegeproject.
the class DataFactory method parseDateTimeFormat.
/**
* Parses the specified lexical value into a datetime literal. The parser will parse dateTime according to the
* xsd:dateTime pattern. If the time information is not present, the end of the day will automatically be assumed.
* @param lexicalValue The lexical value to be parsed. Not {@code null}.
* @return The literal representing the specified datetime.
* @throws IllegalArgumentException if the lexical value cannot be parsed into a date-time format.
*/
public static OWLLiteral parseDateTimeFormat(final String lexicalValue) throws IllegalArgumentException {
final String yearFrag = "-?(?:[1-9][0-9]{3,}|0[0-9]{3})";
final String monthFrag = "-(?:0[1-9]|1[0-2])";
final String dayFrag = "-(?:0[1-9]|[12][0-9]|3[01])";
// Group 1
final String yearMonthDayFrag = "(" + yearFrag + monthFrag + dayFrag + ")";
// Slight modification to make input easier
// Group 2
final String timeFrag = "((?:T| )(?:(?:[01][0-9]|2[0-3]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\\.[0-9]+)?|(?:24:00:00(?:\\.0+)?)))?";
// Group 3
final String timeZoneFrag = "(Z|(?:\\+|-)(?:(?:0[0-9]|1[0-3]):[0-5][0-9]|14:00))?";
String pattern = "^" + yearMonthDayFrag + timeFrag + timeZoneFrag + "$";
RegExp regExp = RegExp.compile(pattern);
MatchResult matchResult = regExp.exec(lexicalValue);
if (matchResult == null) {
throw new IllegalArgumentException();
}
String matchedYearMonthDay = matchResult.getGroup(1);
String matchedTime = matchResult.getGroup(2);
String matchedTimeZone = matchResult.getGroup(3);
String properLexicalValue = matchedYearMonthDay;
if (matchedTime != null) {
if (!matchedTime.startsWith("T")) {
properLexicalValue += "T" + matchedTime.trim();
} else {
properLexicalValue += matchedTime;
}
} else {
properLexicalValue += "T00:00:00";
}
if (matchedTimeZone != null) {
properLexicalValue += matchedTimeZone;
}
return dataFactory.getOWLLiteral(properLexicalValue, OWL2Datatype.XSD_DATE_TIME);
}
use of com.google.gwt.regexp.shared.MatchResult in project ovirt-engine by oVirt.
the class MemorySizeParser method parse.
@Override
public Integer parse(CharSequence text) throws ParseException {
// $NON-NLS-1$
MatchResult match = RegExp.compile("^(\\d+)\\s*(\\w*)$").exec(text.toString().trim());
if (match == null) {
return 0;
}
String prefix = match.getGroup(1);
String suffix = match.getGroup(2);
Integer size = null;
try {
size = Integer.parseInt(prefix);
} catch (NumberFormatException e) {
return 0;
}
if (suffix.equalsIgnoreCase("TB") || suffix.equalsIgnoreCase("T")) {
// $NON-NLS-1$ $NON-NLS-2$
return size * 1024 * 1024;
} else if (suffix.equalsIgnoreCase("GB") || suffix.equalsIgnoreCase("G")) {
// $NON-NLS-1$ $NON-NLS-2$
return size * 1024;
} else if (suffix.equalsIgnoreCase("MB") || suffix.equalsIgnoreCase("M")) {
// $NON-NLS-1$ $NON-NLS-2$
return size;
} else if (StringHelper.isNullOrEmpty(suffix)) {
return size;
} else {
// disallow garbled suffixes
return 0;
}
}
Aggregations