/** * 实现<code>MatchResult</code>接口, 取得指定group相对于整个字符串的位移量. * * @param group group号, 0代表整个匹配 * @return 指定group相对于整个字符串的位移量, 如果指定group不存在或未匹配, 则返回-1 */ public int beginOffset(int group) { return result == null ? -1 : result.beginOffset(group); }
public int beginOffset(int arg0) { int oo=mr.beginOffset(arg0); if(oo!=-1) { return oo-ld; } else { return oo; } }
private static void split(Collection results, PatternMatcher matcher, Pattern pattern, String input, int limit) { int beginOffset; MatchResult currentResult; PatternMatcherInput pinput; pinput = new PatternMatcherInput(input); beginOffset = 0; while (--limit != 0 && matcher.contains(pinput, pattern)) { currentResult = matcher.getMatch(); results.add(input.substring(beginOffset, currentResult .beginOffset(0))); beginOffset = currentResult.endOffset(0); } results.add(input.substring(beginOffset, input.length())); }
while(matcher.contains(pinput, templatePattern)) { currentResult = matcher.getMatch(); final int beginMatch = currentResult.beginOffset(0); if (beginMatch > beginOffset) { // string is not empty combined.add(rawTemplate.substring(beginOffset, beginMatch));
final int keyStart = match.beginOffset(2); if (isPartOfUrl(body, keyStart)) boolean isInsideAnchor = util.match("/<a[^>]*>(.*?" + key + ".*?)</a>/", body) && (util.getMatch().beginOffset(0) < keyStart); if (isInsideAnchor) endIndex = getUrlEnd(body, match.beginOffset(2)); buff.append(body.substring(0, match.beginOffset(2)));
buff.append(body.substring(0, match.beginOffset(2))); if (JiraKeyUtils.isPartOfUrl(body, match.beginOffset(2)))
public void processMatch(MatchResult match) { PortletWindowId windowId=new PortletWindowId(match.group(1)); // obtain portlet content IPortletWindowManager windowManager=getPortletWindowManager(); IPortletRenderContent content=windowManager.getPortletRenderContent(windowId); String titleString = content.getTitle(); if (logger.isDebugEnabled()) { logger.debug("processMatch() - matched portletWindowId \""+match.group(1)+"\", title=\""+titleString+"\""); } // perform substitution StringBuffer b=this.getContentBuffer(); if(titleString==null) { titleString=DEFAULT_TITLE_PATTERN; } if(b!=null) { b.replace(match.beginOffset(0),match.endOffset(0),titleString); } }
public void processMatch(MatchResult match) { if (logger.isDebugEnabled()) { logger.debug("processMatch() - matched portletWindowId \""+match.group(1)+"\""); } // obtain id in an object form // TODO: define an interface for id factory, otherwise what's the point of having an interface id, if one can only create a specific implementation? PortletWindowId windowId=new PortletWindowId(match.group(1)); // obtain portlet content IPortletWindowManager windowManager=getPortletWindowManager(); IPortletRenderContent content=windowManager.getPortletRenderContent(windowId); String contentString=""; try { contentString = content.getCharacterOutput(); } catch (UnsupportedEncodingException e) { //TODO: replace by error portlet logger.error("processMatch() - can not translate portlet content to string : windowId = " + windowId, e); } // perform substitution StringBuffer b=this.getContentBuffer(); b.replace(match.beginOffset(0),match.endOffset(0),contentString); }
public static List<String> getIssueKeysFromString(String body) { if (isBlank(body)) { return Collections.emptyList(); } final Perl5Util util = new Perl5Util(); //note that we have to create a new match, as MatchResult is not Threadsafe final List<String> result = new ArrayList<String>(); while (util.match(getKeyMatcher().getIssueKeyRegex(), body)) { final MatchResult match = util.getMatch(); // The issue key is composed of the all sub-pattern match // groups after the initial sub pattern match group final int matchGroups = match.groups(); // Check backs from the key to see if it part of the url & URL is ignored if (!getKeyMatcher().isIgnoreUrlWithKey() || !isPartOfUrl(body, match.beginOffset(2))) { result.add(createKeyFromMatchingGroups(matchGroups, match)); } body = body.substring(match.endOffset(matchGroups - 1)); } return Collections.unmodifiableList(result); }
if (firstResult == null || result.beginOffset(0) < firstResult.beginOffset(0)) { firstResult = result; firstPair = pair;
private static int getPositionOfBody(String stringToCheck) { Perl5Matcher localMatcher = JMeterUtils.getMatcher(); // The headers and body are divided by a blank line (the \r is to allow for the CR before LF) String regularExpression = "^\\r$"; // $NON-NLS-1$ Pattern pattern = JMeterUtils.getPattern(regularExpression, Perl5Compiler.READ_ONLY_MASK | Perl5Compiler.CASE_INSENSITIVE_MASK | Perl5Compiler.MULTILINE_MASK); PatternMatcherInput input = new PatternMatcherInput(stringToCheck); if(localMatcher.contains(input, pattern)) { MatchResult match = localMatcher.getMatch(); return match.beginOffset(0); } // No divider was found return -1; } }
MatchResult result = matcher.getMatch(); buffer = new StringBuffer(); buffer.append(input.substring(result.beginOffset(0) + result.end(0))); logger.debug("Matched! Invoking match closure..."); expectContext = invokeClosure(regExpMatch, input, result);
private static boolean isKeyInStringMatchingRegex(final String issueKey, String body) { final Perl5Util util = new Perl5Util(); //note that we have to create a new match, as MatchResult is not Threadsafe while (util.match(getKeyMatcher().getIssueKeyRegex(), body)) { final MatchResult match = util.getMatch(); // The issue key is composed of the all sub-pattern match // groups after the initial sub pattern match group final int matchGroups = match.groups(); final String key = createKeyFromMatchingGroups(matchGroups, match); if (issueKey.equals(key)) { // Check backs from the key to see if it part of the url & URL is ignored if (!getKeyMatcher().isIgnoreUrlWithKey() || !isPartOfUrl(body, match.beginOffset(2))) { return true; } } body = body.substring(match.endOffset(matchGroups - 1)); } return false; }
String firstPart = buf.substring(0,result.beginOffset(0)); String prefix = result.group(1);
prevMap = g_state.getVars(); int matchedWhere = result.beginOffset(0);