本文整理汇总了Java中com.google.gwt.regexp.shared.RegExp类的典型用法代码示例。如果您正苦于以下问题:Java RegExp类的具体用法?Java RegExp怎么用?Java RegExp使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RegExp类属于com.google.gwt.regexp.shared包,在下文中一共展示了RegExp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testInitWidget
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
@Test
public void testInitWidget() {
widget.init();
verify(widget,
times(1)).init();
verify(dataTypeComboBox,
times(1)).init(widget,
true,
dataType,
customDataType,
false,
true,
VariableListItemWidgetView.CUSTOM_PROMPT,
VariableListItemWidgetView.ENTER_TYPE_PROMPT);
verify(name,
times(1)).setRegExp(regExpCaptor.capture(),
anyString(),
anyString());
RegExp regExp = RegExp.compile(regExpCaptor.getValue());
assertEquals(false,
regExp.test("a 1"));
assertEquals(false,
regExp.test("[email protected]"));
assertEquals(true,
regExp.test("a1"));
verify(customDataType,
times(1)).addKeyDownHandler(any(KeyDownHandler.class));
verify(name,
times(1)).addBlurHandler(any(BlurHandler.class));
}
示例2: showPresenter
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void showPresenter(String token) {
Presenter<? extends View<? extends Element>> matchingPresenter = null;
MatchResult matchResult = null;
for (Presenter<? extends View<? extends Element>> presenter : presenters) {
RegExp regExp = presenter.getTokenRegExp();
if (regExp == null) {
continue;
}
matchResult = regExp.exec(token);
if (matchResult != null) {
matchingPresenter = presenter;
break;
}
}
if (matchingPresenter == null) {
LOG.warning("No presenter found for token \"" + token + "\".");
return;
}
final String[] groups = new String[matchResult.getGroupCount()];
for (int i = 0; i < matchResult.getGroupCount(); i++) {
groups[i] = matchResult.getGroup(i);
}
setCurrentPresenter((Presenter<? extends View<Element>>) matchingPresenter, groups);
}
示例3: parseTag
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
public static String[] parseTag(final String tag) {
String[] result = null;
if (tag != null) {
RegExp regExp = RegExp.compile(IMAGE_TAG_PATTERN);
MatchResult matcher = regExp.exec(tag);
boolean matchFound = matcher != null;
if (matchFound) {
result = new String[matcher.getGroupCount()];
// Get all groups for this match
for (int i = 0; i < matcher.getGroupCount(); i++) {
String groupStr = matcher.getGroup(i);
result[i] = groupStr;
}
}
}
return result;
}
示例4: getHash
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
/**
* Gets the true hash value. Cannot use location.hash directly due to bug
* in Firefox where location.hash will always be decoded.
*
* @param iframe
* @return
*/
public String getHash(IFrameElement iframe) {
RegExp re = RegExp.compile("#(.*)$");
String href = location.getHref();
if(iframe != null) {
href = getIFrameUrl(iframe);
}
MatchResult result = re.exec(href);
return result != null && result.getGroupCount() > 1 ? result.getGroup(1) : "";
}
示例5: loadUrl
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
private boolean loadUrl(String fragmentOverride) {
// If the root doesn't match, no routes can match either.
if(!matchRoot()) return false;
String fragment = this.fragment = this.getFragment(fragmentOverride);
for (int i = 0; i < handlers.length(); i++) {
Properties handler = handlers.get(i);
RegExp route = handler.get("route");
Function callback = handler.getFunction("callback");
if (route.test(fragment)) {
callback.f(fragment);
return true;
}
}
return false;
}
示例6: extractParameters
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
/**
* Given a route, and a URL fragment that it matches, return the array of
* extracted decoded parameters. Empty or unmatched parameters will be
* treated as `null` to normalize cross-browser behavior.
*
* @param route
* @param fragment
* @return
*/
public static String[] extractParameters(RegExp route, String fragment) {
MatchResult matchResult = route.exec(fragment);
int groupCount = matchResult.getGroupCount() - 1;
if(groupCount < 0)
groupCount = 0;
List<String> params = new ArrayList<String>();
for (int i = 0; i < groupCount; i++) {
String param = matchResult.getGroup(i + 1);
if (param != null && !param.isEmpty()) {
// Don't decode the search params.
if(i == groupCount - 1) {
params.add(param);
} else {
params.add(decodeURIComponent(param));
}
}
}
return params.toArray(new String[params.size()]);
}
示例7: replace
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
public void replace(String href) {
setAnchorHref(parser, href);
//this.href = getAnchorHref(parser);
this.href = href;
hash = getAnchorHash(parser);
host = getAnchorHost(parser);
search = getAnchorSearch(parser);
fragment = getAnchorFragment(parser);
pathname = getAnchorPathname(parser);
protocol = getAnchorProtocol(parser);
// In IE, anchor.pathname does not contain a leading slash though
// window.location.pathname does.
if(!RegExp.compile("^\\/").test(pathname)) {
pathname = "/" + pathname;
}
}
示例8: replace
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
/**
* Execute a regular expression and invoke a callback for each match
* occurance. The return value of the callback is substituted for the match.
*
* @param expression a compiled regular expression
* @param text a String on which to perform replacement
* @param replacer a callback that maps matched strings into new values
*/
private static String replace(RegExp expression, String text,
RegExpReplacer replacer) {
expression.setLastIndex(0);
MatchResult mresult = expression.exec(text);
StringBuffer toReturn = new StringBuffer();
int lastIndex = 0;
while (mresult != null) {
toReturn.append(text.substring(lastIndex, mresult.getIndex()));
toReturn.append(replacer.replace(mresult.getGroup(0)));
lastIndex = mresult.getIndex() + 1;
mresult = expression.exec(text);
}
toReturn.append(text.substring(lastIndex));
return toReturn.toString();
}
示例9: getWordAtOffset
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
public Position getWordAtOffset(Document document, int offset) {
if (document == null) {
return null;
}
RegExp regExp = RegExp.compile(COMMON_WORD_REGEXP, "g");
int line = document.getLineAtOffset(offset);
String lineContent = document.getLineContent(line);
int lineStart = document.getLineStart(line);
int pos = offset - lineStart;
int start = lineContent.lastIndexOf(' ', pos - 1) + 1;
regExp.setLastIndex(start);
MatchResult matchResult;
while ((matchResult = regExp.exec(lineContent)) != null) {
if (matchResult.getIndex() <= pos && regExp.getLastIndex() >= pos) {
return new Position(matchResult.getIndex() + lineStart, matchResult.getGroup(0).length());
}
}
return null;
}
示例10: processChange
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
@Override
public TextChange processChange(final TextChange change, ReadOnlyDocument document) {
final RegExp regex = RegExp.compile("^\n(\\s*)\\*\\s*$");
final MatchResult matchResult = regex.exec(change.getNewText());
// either must be on the first line or be just after a line break (regexp)
if (matchResult != null) {
final String line = document.getLineContent(change.getFrom().getLine());
// matches a line containing only whitespaces followed by either /** or /* and then optionally
// whitespaces again
if (!line.matches("^\\s*\\/\\*\\*?\\s*$")) {
return null;
}
final String whitespaces = matchResult.getGroup(1);
final String modifiedInsert = "\n" + whitespaces + "* \n" + whitespaces + "*/";
return new TextChange.Builder()
.from(change.getFrom())
.to(change.getFrom())
.insert(modifiedInsert)
.build();
} else {
return null;
}
}
示例11: getNumberOfMatches
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
/**
* Returns the number of matches found in a string by a regexp. If the regexp is not a global
* regexp this will return a maximum of 1. This does not setLastIndex(0) automatically, you must
* do it manually.
*
* @returns number of matches
*/
public static int getNumberOfMatches(RegExp regexp, String input) {
if (regexp == null || input == null || input.isEmpty()) {
return 0;
}
// if we don't check here we will loop forever
if (!regexp.getGlobal()) {
return regexp.test(input) ? 1 : 0;
}
int matches = 0;
for (MatchResult result = regexp.exec(input);
result != null && result.getGroup(0).length() != 0;
result = regexp.exec(input)) {
matches++;
}
return matches;
}
示例12: fuzzyMatch
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
public List<Match> fuzzyMatch(String word, String wordToMatch, boolean substringMatch) {
RegExp regExp = regExpCache.get(word);
if (regExp == null) {
regExp = convertWordToRegExp(word);
regExpCache.put(word, regExp);
}
MatchResult matchResult = regExp.exec(wordToMatch);
if (matchResult != null) {
return Collections.singletonList(
new Match(
matchResult.getIndex(), matchResult.getIndex() + matchResult.getGroup(0).length()));
}
if (substringMatch) {
return FUZZY_SEPARATE.match(word, wordToMatch);
} else {
return FUZZY_CONTIGUOUS.match(word, wordToMatch);
}
}
示例13: transformResponse
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
@Override
protected void transformResponse(DSResponse response, DSRequest request, Object data) {
if (RestConfig.isStatusOk(response)) {
for (Record record : response.getData()) {
String path = record.getAttribute(FIELD_PATH);
RegExp pathRegExp = RegExp.compile("(.*/)?(.*)/$");
MatchResult mr = pathRegExp.exec(path);
String parent = mr.getGroup(1);
String name = mr.getGroup(2);
// System.out.println("## ITRDS.path: " + path);
// System.out.println("## ITRDS.parent: " + parent);
// System.out.println("## ITRDS.name: " + name);
record.setAttribute(FIELD_NAME, name);
record.setAttribute(FIELD_PARENT, parent);
}
}
super.transformResponse(response, request, data);
}
示例14: isLastNumericPathComponentBad
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
/**
* Returns true if:
* - the digitStart to digitEnd of urlStr is the last path component, and
* - the entire path component is numeric, and
* - the previous path component is a bad page param name.
* E.g. "www.foo.com/tag/2" will return true because of the above reasons and "tag" is a bad
* page param.
*/
static boolean isLastNumericPathComponentBad(String urlStr, int pathStart, int digitStart,
int digitEnd) {
if (urlStr.charAt(digitStart - 1) == '/' && // Digit is at start of path component.
pathStart < digitStart - 1) { // Not the first path component.
String postMatch = urlStr.substring(digitEnd).toLowerCase();
// Checks that this is the last path component, and trailing characters, if available,
// are (s)htm(l) extensions.
if (sExtRegExp == null) sExtRegExp = RegExp.compile("(.s?html?)?$", "i");
if (sExtRegExp.test(postMatch)) {
// Entire component is numeric, get previous path component.
if (sLastPathComponentRegExp == null) {
sLastPathComponentRegExp = RegExp.compile("([^/]*)\\/$", "i");
}
MatchResult prevPathComponent = sLastPathComponentRegExp.exec(
urlStr.substring(pathStart + 1, digitStart));
if (prevPathComponent != null && prevPathComponent.getGroupCount() > 1 &&
PageParameterDetector.isPageParamNameBad(prevPathComponent.getGroup(1))) {
return true;
}
} // last numeric path component
}
return false;
}
示例15: TestFilter
import com.google.gwt.regexp.shared.RegExp; //导入依赖的package包/类
TestFilter(String filter) {
pos = new ArrayList<RegExp>();
neg = new ArrayList<RegExp>();
if (filter == null) return;
String[] segments = filter.split("-");
if (segments.length > 2) {
LogUtil.logToConsole("[ERROR] filter \"" + filter + "\" is malformed.");
}
for (int i = 0; i < segments.length; i++) {
String[] filters = segments[i].split(":");
for (int j = 0; j < filters.length; j++) {
if (filters[j].length() == 0) continue;
RegExp r = convert(filters[j]);
if (i == 0) {
pos.add(r);
} else {
neg.add(r);
}
}
}
}