Search in sources :

Example 41 with MatchResult

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();
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 42 with MatchResult

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;
    }
}
Also used : ProjectId(edu.stanford.bmir.protege.web.shared.project.ProjectId) MatchResult(com.google.gwt.regexp.shared.MatchResult) ProjectSettingsPlace(edu.stanford.bmir.protege.web.shared.place.ProjectSettingsPlace)

Example 43 with MatchResult

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;
}
Also used : ArrayList(java.util.ArrayList) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 44 with MatchResult

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);
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 45 with MatchResult

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;
    }
}
Also used : MatchResult(com.google.gwt.regexp.shared.MatchResult)

Aggregations

MatchResult (com.google.gwt.regexp.shared.MatchResult)47 RegExp (com.google.gwt.regexp.shared.RegExp)23 ArrayList (java.util.ArrayList)7 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)3 ProjectId (edu.stanford.bmir.protege.web.shared.project.ProjectId)3 JsArrayString (com.google.gwt.core.client.JsArrayString)1 Node (com.google.gwt.dom.client.Node)1 PreElement (com.google.gwt.dom.client.PreElement)1 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)1 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)1 SafeHtml (com.google.gwt.safehtml.shared.SafeHtml)1 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)1 ItemTexts (cz.metacentrum.perun.webgui.model.ItemTexts)1 AutoCompletionChoice (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionChoice)1 AutoCompletionResult (edu.stanford.bmir.gwtcodemirror.client.AutoCompletionResult)1 EditorPosition (edu.stanford.bmir.gwtcodemirror.client.EditorPosition)1 CollectionId (edu.stanford.bmir.protege.web.shared.collection.CollectionId)1 CollectionItem (edu.stanford.bmir.protege.web.shared.collection.CollectionItem)1 FormId (edu.stanford.bmir.protege.web.shared.form.FormId)1 GetUserIdCompletionsAction (edu.stanford.bmir.protege.web.shared.itemlist.GetUserIdCompletionsAction)1