List of usage examples for java.util.regex Matcher appendReplacement
public Matcher appendReplacement(StringBuilder sb, String replacement)
From source file:Main.java
private static String capitalizeTagNames(String xpath) { Matcher m = TAG_PATTERN.matcher(xpath); StringBuffer sb = new StringBuffer(); while (m.find()) { String text = m.group();/*w w w .j av a 2 s . co m*/ m.appendReplacement(sb, Matcher.quoteReplacement(text.toUpperCase())); } m.appendTail(sb); return sb.toString(); }
From source file:Main.java
/** substitutes the linearDistributions according to the substitution list */ public static String substitute(String currentQIESL, HashMap<Integer, String> substitutionList) { StringBuffer result = new StringBuffer(); int i = 0;//from w w w .j a va2s . c o m Matcher m = LINEAR_DISTRIUBTIONS.matcher(currentQIESL); while (m.find()) { if (substitutionList.containsKey(i)) { m.appendReplacement(result, substitutionList.get(i)); } i++; } m.appendTail(result); return result.toString(); }
From source file:org.pentaho.ui.xul.util.ResourceBundleTranslator.java
public static String translate(String input, ResourceBundle bundle) throws IOException { String template = input;/* w ww . jav a2 s. com*/ Pattern pattern = Pattern.compile("\\$\\{([^\\}]*)\\}"); //$NON-NLS-1$ Matcher m = pattern.matcher(template); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ResourceBundleTranslator.getTranslatedValue(m.group(1), bundle)); } m.appendTail(sb); return sb.toString(); }
From source file:org.pentaho.ui.xul.util.ResourceBundleTranslator.java
public static String translate(InputStream input, ResourceBundle bundle) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(input)); StringBuffer buf = new StringBuffer(); String line;/*from ww w. ja v a 2s .c om*/ while ((line = reader.readLine()) != null) { buf.append(line); } String template = buf.toString(); Pattern pattern = Pattern.compile("\\$\\{([^\\}]*)\\}"); //$NON-NLS-1$ Matcher m = pattern.matcher(template); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ResourceBundleTranslator.getTranslatedValue(m.group(1), bundle)); } m.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static String oldEncodeQrCodeString(String text) { Pattern pattern = Pattern.compile("[A-Z]"); Matcher matcher = pattern.matcher(text); StringBuffer sb = new StringBuffer(); while (matcher.find()) { String letter = matcher.group(0); matcher.appendReplacement(sb, QR_CODE_LETTER + letter); }//w ww.ja v a 2 s . co m matcher.appendTail(sb); return sb.toString().toUpperCase(Locale.US); }
From source file:Main.java
/** * entitize//from ww w .ja v a2 s .c o m * * @param source * @return */ public static String entitize(String source) { String result = null; if (source != null) { Matcher m = SPECIAL_CHARS.matcher(source); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, ENTITIES.get(m.group())); } m.appendTail(sb); result = sb.toString(); } return result; }
From source file:io.wcm.devops.conga.plugins.aem.validator.AnyValidator.java
/** * Replace ticks (') for properties with quotes (") because the old java ANY file parser implementation * does not support them.//w ww . j a va 2 s. c om * @param anyFileContent Any file content * @return Content with ticks replaces */ static String replaceTicks(String anyFileContent) { StringBuffer result = new StringBuffer(); Matcher matcher = TICK_PROPERTY.matcher(anyFileContent); while (matcher.find()) { matcher.appendReplacement(result, "/" + Matcher.quoteReplacement(matcher.group(1)) + " \"" + Matcher.quoteReplacement(matcher.group(2)) + "\""); } matcher.appendTail(result); return result.toString(); }
From source file:com.vaadin.sass.internal.visitor.IfElseNodeHandler.java
private static String replaceStrings(String expression) { expression = expression.replaceAll("\"", ""); Matcher m = pattern.matcher(expression); StringBuffer b = new StringBuffer(); while (m.find()) { String group = m.group(); m.appendReplacement(b, "'" + group + "'"); }/*from w ww . j av a2 s .com*/ m.appendTail(b); if (b.length() != 0) { return b.toString(); } return expression; }
From source file:com.gs.obevo.db.impl.platforms.db2.Db2lookReveng.java
public static String removeQuotes(String input) { Pattern compile = Pattern.compile("\"([A-Z_0-9]+)\"", Pattern.DOTALL); StringBuffer sb = new StringBuffer(input.length()); Matcher matcher = compile.matcher(input); while (matcher.find()) { matcher.appendReplacement(sb, matcher.group(1)); }// w w w. j a v a 2 s . c om matcher.appendTail(sb); return sb.toString(); }
From source file:com.mirth.connect.connectors.jdbc.JdbcUtils.java
/** * Parse the given statement filling the parameter list and return the ready to use statement. * /*from w w w .java 2 s. c om*/ * @param statement * @param params * List that will contain the parameters found in the statement * @return The parsed statement */ public static String extractParameters(String statement, List<String> params) { if (statement == null) { return null; } Pattern p = Pattern.compile("\\$\\{([^\\}]*)\\}"); Matcher m = p.matcher(statement); StringBuffer sb = new StringBuffer(); while (m.find()) { String key = m.group(0); m.appendReplacement(sb, "?"); params.add(key); } m.appendTail(sb); return sb.toString(); }