List of usage examples for com.google.gwt.regexp.shared SplitResult get
public final String get(int index)
From source file:cc.kune.common.client.utils.ClientFormattedString.java
License:GNU Affero Public License
/** * String format based in//from w w w . ja v a 2s .com * http://stackoverflow.com/questions/3126232/string-formatter-in-gwt * * @param format * the format * @param args * the args * @return the string */ @Override public String format(final String format, final Object... args) { final RegExp regex = RegExp.compile("%[a-z]"); final SplitResult split = regex.split(format); final StringBuffer msg = new StringBuffer(); for (int pos = 0; pos < split.length() - 1; pos += 1) { msg.append(split.get(pos)); msg.append(args[pos].toString()); } msg.append(split.get(split.length() - 1)); GWT.log("FORMATTER: " + msg.toString()); return msg.toString(); }
From source file:com.cgxlib.core.component.tooltip.SingleTooltip.java
License:Apache License
protected void initTooltip(String type, TooltipOptions pOptions) { this.enabled = true; this.type = type; final SingleTooltip $this = this; options = pOptions;/* w w w. java 2 s .c om*/ this.$viewport = options.viewPortSelector() != null ? $(options.viewPortSelector()) : null; this.inState = new InState(); if (Document.get().getDocumentElement().equals($this.get(0)) && this.options.selector() == null) { throw new Error("`selector` option must be specified when initializing " + this.type + " on the window.document object!"); } SplitResult triggers = RegExp.compile(" ").split(options.trigger()); for (int i = triggers.length() - 1; i >= 0; i--) { String trigger = triggers.get(i); if ("click".equals(trigger)) { $this.on("click." + this.type, this.options.selector(), new Function() { @Override public void f() { $this.tooltipToggle(null, $this); } }); } else if (trigger != "manual") { String eventIn = trigger == "hover" ? "mouseenter" : "focusin"; String eventOut = trigger == "hover" ? "mouseleave" : "focusout"; $this.on(eventIn + '.' + this.type, options.selector(), new Function() { @Override public void f() { $this.enter($this, true); } }); $this.on(eventOut + '.' + this.type, options.selector(), new Function() { @Override public void f() { $this.leave($this, true); } }); } } if (options.selector() != null) { options.trigger("manual"); options.selector(null); } else { viewHandler.fixTitle(); } }
From source file:com.codenvy.ide.ext.web.css.editor.CssCompletionQuery.java
License:Open Source License
private void parseCurrentPropertyAndValues(String incompletePropertyAndValues) { incompletePropertyAndValues = incompletePropertyAndValues .substring(incompletePropertyAndValues.indexOf('{') + 1); SplitResult subParts = REGEXP_COLON.split(incompletePropertyAndValues); // subParts must have at least one element property = subParts.get(0).trim(); if (subParts.length() > 1) { SplitResult valueParts = REGEXP_SPACES.split(subParts.get(1)); if (subParts.get(1).endsWith(" ")) { for (int i = 0; i < valueParts.length(); i++) { String trimmed = valueParts.get(i).trim(); if (!trimmed.isEmpty()) { valuesBefore.push(trimmed); }// ww w . j a v a 2s . c om } } else { if (valueParts.length() == 1) { value = subParts.get(1).trim(); } else { value = valueParts.get(valueParts.length() - 1).trim(); for (int i = 0; i < valueParts.length() - 1; i++) { String trimmed = valueParts.get(i).trim(); if (!trimmed.isEmpty()) { valuesBefore.push(trimmed); } } } } } else if (incompletePropertyAndValues.endsWith(":")) { value = ""; } }
From source file:com.codenvy.ide.ext.web.css.editor.CssCompletionQuery.java
License:Open Source License
private void parseContext(String textBefore, String textAfter) { if (textBefore.isEmpty()) { completionType = CompletionType.PROPERTY; return;// w w w.j a v a2 s . c o m } else if (textBefore.endsWith("{")) { completionType = CompletionType.PROPERTY; return; } textBefore = textBefore.replaceAll("^\\s+", ""); // Split first on ';'. The last one is the incomplete one. SplitResult parts = REGEXP_SEMICOLON.split(textBefore); if ((textBefore.endsWith(";")) || (!parts.get(parts.length() - 1).contains(":"))) { completionType = CompletionType.PROPERTY; } else { completionType = CompletionType.VALUE; } int highestCompleteIndex = parts.length() - 2; if (textBefore.endsWith(";")) { highestCompleteIndex = parts.length() - 1; } else { parseCurrentPropertyAndValues(parts.get(parts.length() - 1)); } if (parts.length() > 1) { // Parse the completed properties, which we use for filtering. for (int i = 0; i <= highestCompleteIndex; i++) { String completePropertyAndValues = parts.get(i); SplitResult subParts = REGEXP_COLON.split(completePropertyAndValues); completedProperties.add(subParts.get(0).trim().toLowerCase()); } } // Interpret textAfter // Everything up to the first ; will be interpreted as being part of the // current property, so it'll be complete values parts = REGEXP_SEMICOLON.split(textAfter); if (parts.length() > 0) { // We assume that the property+values we are currently working on is not // completed but can be assumed to end with a newline. int newlineIndex = parts.get(0).indexOf('\n'); if (newlineIndex != -1) { String currentValues = parts.get(0).substring(0, newlineIndex); addToValuesAfter(currentValues); addToCompletedProperties(parts.get(0).substring(newlineIndex + 1)); } else { addToValuesAfter(parts.get(0)); } for (int i = 1; i < parts.length(); i++) { addToCompletedProperties(parts.get(i)); } } }
From source file:com.codenvy.ide.ext.web.css.editor.CssCompletionQuery.java
License:Open Source License
private void addToCompletedProperties(String completedProps) { SplitResult completed = REGEXP_SEMICOLON.split(completedProps); for (int i = 0; i < completed.length(); i++) { int colonIndex = completed.get(i).indexOf(":"); String trimmed;//from w ww.ja v a2 s . c o m if (colonIndex != -1) { trimmed = completed.get(i).substring(0, colonIndex).trim(); } else { trimmed = completed.get(i).trim(); } if (!trimmed.isEmpty()) { completedProperties.add(trimmed.toLowerCase()); } } }
From source file:com.codenvy.ide.ext.web.css.editor.CssCompletionQuery.java
License:Open Source License
private void addToValuesAfter(String completedVals) { SplitResult completed = REGEXP_SPACES.split(completedVals); for (int i = 0; i < completed.length(); i++) { String trimmed = completed.get(i).trim(); if (!trimmed.isEmpty()) { valuesAfter.push(trimmed);/* www. j a v a 2 s . c o m*/ } } }
From source file:com.codenvy.plugin.angularjs.core.client.editor.AngularJSHtmlCodeAssistProcessor.java
License:Open Source License
/** * Gets a list of angularjs attributes from the given text * //from w ww . ja va 2s . c o m * @param text the text * @param skipLast if the last attribute needs to be skipped (for example if it's the current attribute) * @return the list of attributes */ protected List<String> getAngularAttributes(String text, boolean skipLast) { // Text that needs to be analyzed // First, split on space in order to get attributes SplitResult fullAttributes = REGEXP_SPACES.split(text); // init list List<String> attributesName = new ArrayList<>(); // now, for each attribute, gets only the name of the attribute if (fullAttributes.length() > 0) { for (int i = 0; i < fullAttributes.length(); i++) { if (i == fullAttributes.length() - 1 && skipLast) { continue; } String attribute = fullAttributes.get(i); // Get only the attribute name SplitResult attributeNameSplit = REGEXP_PROPERTY.split(attribute); // first part is the attribute name attributesName.add(attributeNameSplit.get(0)); } } return attributesName; }
From source file:com.codenvy.plugin.angularjs.core.client.editor.AngularJSHtmlCodeAssistProcessor.java
License:Open Source License
/** * Gets query with the given text./*from w w w.j ava 2 s. co m*/ * * @param textBefore which is text before cursor * @param textAfter which is text after cursor * @return a new query */ protected AngularJSQuery getQuery(String textBefore, String textAfter) { AngularJSQuery query = new AngularJSQuery(); List<String> attributes = new ArrayList<>(); List<String> attributesBefore = getAngularAttributes(textBefore, true); attributes.addAll(attributesBefore); attributes.addAll(getAngularAttributes(textAfter, false)); for (String attributeName : attributes) { if (!"".equals(attributeName)) { query.getExistingAttributes().add(attributeName); } } // needs to find the prefix. // The prefix is the last text entered after a space if (textBefore.length() > 0) { SplitResult splitBefore = REGEXP_SPACES.split(textBefore); if (splitBefore.length() > 0) { query.setPrefix(splitBefore.get(splitBefore.length() - 1)); } } else { // no prefix query.setPrefix(""); } return query; }
From source file:com.cristal.storm.prototype.client.mvp.view.MainPageView.java
License:Apache License
/** * The function adds an MCE to the MCE Collection. Tags are tokenized: we * assume a tag is succession of alphanum chars, a dash or an underscore * /*from w w w . jav a 2s . c om*/ * @param uriText * @param tagsText */ @Override public void addToMCECollection(String uriText, String tagsText) { RegExp regExp = RegExp.compile("([A-Za-z0-9_\\-]+)"); SplitResult split = regExp.split(tagsText.toLowerCase()); Set<String> tags = new TreeSet<String>(); for (int i = 0; i < split.length(); i++) { if (!split.get(i).isEmpty()) { tags.add(split.get(i)); } } MCE mce = new MCE(uriText, tags); int mceIndex = ((Vector<MCE>) mceListVisible).indexOf(mce); // On verifie si le MCE (identifie par son URI) est deja present if (mceIndex >= 0) { MCE existingMCE = mceListVisible.get(mceIndex); if (!existingMCE.getTags().equals(mce.getTags())) { existingMCE.setTags(tags); } } else { mceListVisible.add(mce); } mceCollectionDraggable.setRowData(mceListVisible); mceSelectionModel.setSelected(mce, true); }
From source file:com.dotweblabs.timeago.client.TimeAgo.java
License:Open Source License
public static String format(final String format, final Object arg) { final RegExp regex = RegExp.compile("{(.*?)}"); final SplitResult split = regex.split(format); final StringBuffer msg = new StringBuffer(); // for (int pos = 0; pos < split.length() - 1; ++pos) { // msg.append(split.get(pos)); // msg.append(String.valueOf(arg)); // }//from ww w .java 2 s . c o m msg.append(split.get(0)); msg.append(String.valueOf(arg).split("\\.")[0]); msg.append(split.get(split.length() - 1)); return msg.toString(); }