Search in sources :

Example 6 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project rstudio by rstudio.

the class NewConnectionSnippetHost method updateCodePanel.

private void updateCodePanel() {
    String input = info_.getSnippet();
    RegExp regExp = RegExp.compile(pattern_, "g");
    StringBuilder builder = new StringBuilder();
    int inputIndex = 0;
    for (MatchResult matcher = regExp.exec(input); matcher != null; matcher = regExp.exec(input)) {
        if (matcher.getGroupCount() >= 2) {
            String key = matcher.getGroup(2);
            String value = matcher.getGroupCount() >= 4 ? matcher.getGroup(4) : null;
            String connStringField = matcher.getGroupCount() >= 6 ? matcher.getGroup(6) : null;
            if (value != null) {
                value = value.replaceAll("\\$colon\\$", ":");
                value = value.replaceAll("\\$equal\\$", "=");
            }
            builder.append(input.substring(inputIndex, matcher.getIndex()));
            if (partsKeyValues_.containsKey(key)) {
                value = partsKeyValues_.get(key);
            }
            if (value != null) {
                if (connStringField != null) {
                    builder.append(connStringField);
                    builder.append("=");
                }
                builder.append(value);
                if (connStringField != null) {
                    builder.append(";");
                }
            }
            inputIndex = matcher.getIndex() + matcher.getGroup(0).length();
        }
    }
    builder.append(input.substring(inputIndex, input.length()));
    codePanel_.setCode(builder.toString(), "");
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 7 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project ovirt-engine by oVirt.

the class MainDiskView method searchByDiskViewType.

void searchByDiskViewType(DiskStorageType diskViewType, DiskContentType diskContentType) {
    // $NON-NLS-1$
    final String disksSearchPrefix = "Disks:";
    // $NON-NLS-1$
    final String diskTypeSearchPrefix = "disk_type = ";
    // $NON-NLS-1$
    final String diskContentTypeSearchPrefix = "disk_content_type = ";
    // $NON-NLS-1$
    final String searchConjunctionAnd = "and ";
    // $NON-NLS-1$
    final String searchRegexDisksSearchPrefix = "^\\s*(disk(s)?\\s*(:)+)+\\s*";
    // $NON-NLS-1$
    final String searchRegexFlags = "ig";
    // $NON-NLS-1$
    final String space = " ";
    // $NON-NLS-1$
    final String empty = "";
    RegExp searchPatternDisksSearchPrefix = RegExp.compile(searchRegexDisksSearchPrefix, searchRegexFlags);
    String diskTypePostfix = diskViewType != null ? diskViewType.name().toLowerCase() + space : null;
    String diskTypeClause = diskTypePostfix != null ? diskTypeSearchPrefix + diskTypePostfix : empty;
    String diskContentTypePostfix = diskContentType != null ? diskContentType.name().toLowerCase() + space : null;
    String diskContentTypeClause = diskContentTypePostfix != null ? diskContentTypeSearchPrefix + diskContentTypePostfix : empty;
    String inputSearchString = this.getMainModel().getSearchString().trim();
    String inputSearchStringPrefix = this.getMainModel().getDefaultSearchString();
    String userSearchString = inputSearchString.substring(inputSearchStringPrefix.length());
    String searchStringPrefix;
    if (diskTypeClause.isEmpty() && diskContentTypeClause.isEmpty()) {
        searchStringPrefix = disksSearchPrefix.trim();
        if (userSearchString.trim().toLowerCase().startsWith(searchConjunctionAnd)) {
            userSearchString = userSearchString.trim().substring(searchConjunctionAnd.length());
        }
    } else {
        boolean filteringBoth = !diskTypeClause.isEmpty() && !diskContentTypeClause.isEmpty();
        searchStringPrefix = disksSearchPrefix + space + (searchPatternDisksSearchPrefix.test(inputSearchStringPrefix) ? empty : searchConjunctionAnd) + diskTypeClause + (filteringBoth ? searchConjunctionAnd : empty) + diskContentTypeClause + space;
        if (!userSearchString.isEmpty() && !userSearchString.trim().toLowerCase().startsWith(searchConjunctionAnd)) {
            userSearchString = searchConjunctionAnd + userSearchString.trim();
        }
    }
    String searchString = searchStringPrefix.trim() + space + userSearchString.trim();
    getTable().getSelectionModel().clear();
    getMainModel().setItems(null);
    getMainModel().setDefaultSearchString(searchStringPrefix.trim());
    getMainModel().setSearchString(searchString.trim());
    getMainModel().search();
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp)

Example 8 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project ovirt-engine by oVirt.

the class ErrorTranslator method resolveMessage.

private String resolveMessage(String message, Map<String, LinkedList<String>> variables) {
    String returnValue = message;
    // $NON-NLS-1$ //$NON-NLS-2$
    RegExp regex = RegExp.compile(VARIABLE_PATTERN, "gi");
    MatchResult result;
    while (returnValue.length() > 0) {
        result = regex.exec(returnValue);
        if (result == null) {
            // No more matches
            break;
        }
        String match = result.getGroup(0);
        String key = match.substring(2, match.length() - 1);
        if (variables.containsKey(key)) {
            LinkedList<String> values = variables.get(key);
            String value = values.size() == 1 ? values.getFirst() : // $NON-NLS-1$
            values.size() > 1 ? values.removeFirst() : "";
            returnValue = returnValue.replace(match, value);
        } else {
            // infinite loop
            break;
        }
        // Make the next search start from the beginning
        regex.setLastIndex(0);
    }
    return returnValue;
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Example 9 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project ovirt-engine by oVirt.

the class TimeSpan method parse.

// The format for a timespan is:
// [ws][-]{ d | d.hh:mm[:ss[.ff]] | hh:mm[:ss[.ff]] }[ws]
public static TimeSpan parse(String argvalue) {
    String cleaned = argvalue.trim();
    int multiplier = 1;
    if (cleaned.contains("-")) {
        multiplier = -1;
        cleaned = cleaned.replace("-", "").trim();
    }
    RegExp r = RegExp.compile("^[0-9]+$");
    if (r.test(cleaned)) {
        int days = Integer.parseInt(cleaned);
        return new TimeSpan(days * multiplier, 0, 0, 0);
    }
    String regex = "^[0-9]+.[0-9]{2}:[0-9]{2}(:[0-9]{2}(.[0-9]{2})?)?$";
    r = RegExp.compile(regex);
    if (r.test(cleaned)) {
        String[] items = cleaned.split("[:.]");
        int[] data = new int[5];
        for (int x = 0; x < items.length; x++) {
            data[x] = Integer.parseInt(items[x]) * multiplier;
        }
        return new TimeSpan(data);
    }
    regex = "^[0-9]{2}:[0-9]{2}(:[0-9]{2}(.[0-9]{2})?)?$";
    r = RegExp.compile(regex);
    if (r.test(cleaned)) {
        String[] items = cleaned.split("[:.]");
        int[] data = new int[5];
        for (int x = 0; x < items.length; x++) {
            data[x + 1] = Integer.parseInt(items[x]) * multiplier;
        }
        return new TimeSpan(data);
    }
    // If we get to here, it is invalid
    throw new IllegalArgumentException("Invalid TimeSpan");
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp)

Example 10 with RegExp

use of com.google.gwt.regexp.shared.RegExp in project perun by CESNET.

the class JsonClient method parseResponse.

/**
 * Parses the response to an object.
 *
 * @param resp JSON string
 * @return
 */
protected JavaScriptObject parseResponse(String callbackName, String resp) {
    // trims the whitespace
    resp = resp.trim();
    // short comparing
    if ((callbackName + "(null);").equalsIgnoreCase(resp)) {
        return null;
    }
    // if starts with callbackName( and ends with ) or ); - wrapped, must be unwrapped
    RegExp re = RegExp.compile("^" + callbackName + "\\((.*)\\)|\\);$");
    MatchResult result = re.exec(resp);
    if (result != null) {
        resp = result.getGroup(1);
    }
    // if response = null - return null
    if (resp.equals("null")) {
        return null;
    }
    // normal object
    JavaScriptObject jso = JsonUtils.parseJson(resp);
    return jso;
}
Also used : RegExp(com.google.gwt.regexp.shared.RegExp) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject) MatchResult(com.google.gwt.regexp.shared.MatchResult)

Aggregations

RegExp (com.google.gwt.regexp.shared.RegExp)34 MatchResult (com.google.gwt.regexp.shared.MatchResult)23 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)7 JsonCallbackEvents (cz.metacentrum.perun.webgui.json.JsonCallbackEvents)4 BasicOverlayType (cz.metacentrum.perun.webgui.model.BasicOverlayType)4 IsLoginAvailable (cz.metacentrum.perun.webgui.json.usersManager.IsLoginAvailable)3 SetLogin (cz.metacentrum.perun.webgui.json.usersManager.SetLogin)3 TabItem (cz.metacentrum.perun.webgui.tabs.TabItem)3 CustomButton (cz.metacentrum.perun.webgui.widgets.CustomButton)3 ArrayList (java.util.ArrayList)3 BlurHandler (com.google.gwt.event.dom.client.BlurHandler)2 ClickEvent (com.google.gwt.event.dom.client.ClickEvent)2 ClickHandler (com.google.gwt.event.dom.client.ClickHandler)2 KeyDownHandler (com.google.gwt.event.dom.client.KeyDownHandler)2 GetEntityById (cz.metacentrum.perun.webgui.json.GetEntityById)2 CreatePassword (cz.metacentrum.perun.webgui.json.usersManager.CreatePassword)2 GenerateAccount (cz.metacentrum.perun.webgui.json.usersManager.GenerateAccount)2 PerunError (cz.metacentrum.perun.webgui.model.PerunError)2 ExtendedTextBox (cz.metacentrum.perun.webgui.widgets.ExtendedTextBox)2 TabMenu (cz.metacentrum.perun.webgui.widgets.TabMenu)2