List of usage examples for java.util.regex Matcher reset
public Matcher reset()
From source file:org.cesecore.config.ConfigurationHolder.java
private static String interpolate(final String orderString) { final Pattern PATTERN = Pattern.compile("\\$\\{(.+?)\\}"); final Matcher m = PATTERN.matcher(orderString); final StringBuffer sb = new StringBuffer(orderString.length()); m.reset(); while (m.find()) { // when the pattern is ${identifier}, group 0 is 'identifier' final String key = m.group(1); final String value = getExpandedString(key); // if the pattern does exists, replace it by its value // otherwise keep the pattern ( it is group(0) ) if (value != null) { m.appendReplacement(sb, value); } else {//w w w . jav a 2s . c o m // I'm doing this to avoid the backreference problem as there will be a $ // if I replace directly with the group 0 (which is also a pattern) m.appendReplacement(sb, ""); final String unknown = m.group(0); sb.append(unknown); } } m.appendTail(sb); return sb.toString(); }
From source file:com.android.email.core.internet.MimeUtility.java
/** * Replace sequences of CRLF+WSP with WSP. Tries to preserve original string * object whenever possible./*from ww w . j a va 2s . com*/ */ public static String unfold(String s) { if (s == null) { return null; } Matcher patternMatcher = PATTERN_CR_OR_LF.matcher(s); if (patternMatcher.find()) { patternMatcher.reset(); s = patternMatcher.replaceAll(""); } return s; }
From source file:org.perfcake.util.Utils.java
/** * Filters properties in the given string. Consider using {@link org.perfcake.util.StringTemplate} instead. * * @param text/*from ww w . j a va 2 s . co m*/ * The string to be filtered. * @param matcher * The matcher to find the properties, any user specified matcher can be provided. * @param pg * The {@link org.perfcake.util.properties.PropertyGetter} to provide values of the properties. * @return The filtered text. */ public static String filterProperties(final String text, final Matcher matcher, final PropertyGetter pg) { String filteredString = text; matcher.reset(); while (matcher.find()) { String pValue = null; final String pName = matcher.group(2); String defaultValue = null; if (matcher.groupCount() == 3 && matcher.group(3) != null) { defaultValue = (matcher.group(3)).substring(1); } pValue = pg.getProperty(pName, defaultValue); if (pValue != null) { filteredString = filteredString.replaceAll(Pattern.quote(matcher.group(1)), Matcher.quoteReplacement(pValue)); } } return filteredString; }
From source file:org.wso2.developerstudio.eclipse.platform.ui.validator.CommonFieldValidator.java
private static boolean isParameter(String field, boolean partial) { Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}"); Matcher matcher = pattern.matcher(field); boolean find = false; if (partial) { while (matcher.find()) { find = true;/*ww w . ja va2s. c om*/ if (!isValidArtifactName(matcher.group(1).trim())) { return false; } } } else { if (matcher.matches()) { find = !matcher.group(1).trim().isEmpty(); } else { int seq = 0; matcher.reset(); while (matcher.find()) { find = true; String parameter = matcher.group(1).trim(); if (!isValidArtifactName(parameter)) { return false; } if (++seq == 1) { if (!field.startsWith("${" + parameter + "}")) { return false; } } } } } return find; }
From source file:org.openpplsoft.sql.StmtLibrary.java
public static OPSStmt convertForJDBCAndGetOPSStmt(final String query, final String[] bindVals, final OPSStmt.EmissionType eType) { final List<String> expandedBindVals = new ArrayList<String>(); final Matcher bindIdxMatcher = bindIdxPattern.matcher(query); while (bindIdxMatcher.find()) { final int bindIdx = Integer.parseInt(bindIdxMatcher.group(1)); // PS bind indices are 1-based, must subtract 1 here. expandedBindVals.add(bindVals[bindIdx - 1]); }// w ww.j av a 2s . co m bindIdxMatcher.reset(); final String newSql = bindIdxMatcher.replaceAll("?"); return new OPSStmt(newSql, expandedBindVals.toArray(new String[expandedBindVals.size()]), eType); }
From source file:org.cesecore.configuration.ConfigurationTestHolder.java
private String interpolate(final String orderString) { final Pattern PATTERN = Pattern.compile("\\$\\{(.+?)\\}"); final Matcher m = PATTERN.matcher(orderString); final StringBuffer sb = new StringBuffer(orderString.length()); m.reset(); while (m.find()) { // when the pattern is ${identifier}, group 0 is 'identifier' final String key = m.group(1); final String value = getExpandedString(key, ""); // if the pattern does exists, replace it by its value // otherwise keep the pattern ( it is group(0) ) if (value != null) { m.appendReplacement(sb, value); } else {// w ww. j a v a2s .co m // I'm doing this to avoid the backreference problem as there will be a $ // if I replace directly with the group 0 (which is also a pattern) m.appendReplacement(sb, ""); final String unknown = m.group(0); sb.append(unknown); } } m.appendTail(sb); return sb.toString(); }
From source file:org.cesecore.certificates.ocsp.logging.PatternLogger.java
/** * //w w w . ja v a2 s. c o m * @return output to be logged */ private String interpolate() { final StringBuffer sb = new StringBuffer(this.orderString.length()); final Matcher matcher = getMatcher(); matcher.reset(); while (matcher.find()) { // when the pattern is ${identifier}, group 0 is 'identifier' final String key = matcher.group(1); final String value = this.valuepairs.get(key); // if the pattern does exists, replace it by its value // otherwise keep the pattern ( it is group(0) ) if (value != null) { matcher.appendReplacement(sb, value); } else { // I'm doing this to avoid the backreference problem as there will be a $ // if I replace directly with the group 0 (which is also a pattern) matcher.appendReplacement(sb, ""); final String unknown = matcher.group(0); sb.append(unknown); } } matcher.appendTail(sb); return sb.toString(); }
From source file:org.freeplane.features.export.mindmapmode.ExportWithXSLT.java
String getProperty(final String key) { final String property = getProperty(key, null); if (property == null) return property; Matcher r = propertyReferenceEpression.matcher(property); r.reset(); boolean result = r.find(); if (result) { StringBuffer sb = new StringBuffer(); do {/* w w w. jav a 2s. com*/ String propertyReference = r.group(); String propertyName = propertyReference.substring(2, propertyReference.length() - 1); r.appendReplacement(sb, System.getProperty(propertyName, propertyReference)); result = r.find(); } while (result); r.appendTail(sb); return sb.toString(); } return property; }
From source file:net.sourceforge.vulcan.core.support.CommitLogParser.java
private void parse(String message, Matcher matcher, boolean recurse) { int lastEnd = 0; while (matcher.find()) { int issueStart = matcher.start(); final String wholeMatch = matcher.group(0); Matcher idMatcher = null; if (recurse && idPattern != null && !isLink(wholeMatch)) { idMatcher = idPattern.matcher(wholeMatch); if (idMatcher.find()) { idMatcher.reset(); } else { idMatcher = null;//from w w w . j a v a2s. c om } } if (lastEnd < issueStart) { appendText(message.substring(lastEnd, issueStart)); } if (idMatcher != null) { parse(wholeMatch, idMatcher, false); } else { appendIssueOrLinkNode(wholeMatch, matcher.group(0)); } lastEnd = matcher.end(); } if (lastEnd < message.length()) { appendText(message.substring(lastEnd)); } }
From source file:org.openhab.binding.modbus.internal.Transformation.java
/** * * @param transformation either FUN(VAL) (standard transformation syntax), default (identity transformation * (output equals input)) or some other value (output is a constant). Futhermore, empty string is * considered the same way as "default". *///from ww w . java 2 s .c om public Transformation(String transformation) { this.transformation = transformation; // // Parse transformation configuration here on construction, but delay the // construction of TransformationService to call-time if (isEmpty(transformation) || transformation.equalsIgnoreCase(TRANSFORM_DEFAULT)) { // no-op (identity) transformation transformationServiceName = null; transformationServiceParam = null; } else { Matcher matcher = EXTRACT_FUNCTION_PATTERN.matcher(transformation); if (matcher.matches()) { matcher.reset(); matcher.find(); transformationServiceName = matcher.group("service"); transformationServiceParam = matcher.group("arg"); } else { logger.debug( "Given transformation configuration '{}' did not match the FUN(VAL) pattern. Transformation output will be constant '{}'", transformation, transformation); transformationServiceName = null; transformationServiceParam = null; } } }