List of usage examples for java.util.regex Matcher appendTail
public StringBuilder appendTail(StringBuilder sb)
From source file:org.nuxeo.ecm.activity.ActivityMessageHelper.java
public static String replaceURLsByLinks(String message) { String escapedMessage = StringEscapeUtils.escapeHtml(message); Matcher m = HTTP_URL_PATTERN.matcher(escapedMessage); StringBuffer sb = new StringBuffer(escapedMessage.length()); while (m.find()) { String url = m.group(1);/*from w w w . ja va 2 s . com*/ m.appendReplacement(sb, computeLinkFor(url)); } m.appendTail(sb); return sb.toString(); }
From source file:Main.java
private static String makeUrlHerf(String content) { if (content.trim().length() == 0) { return content; }// w w w. j a v a 2s . co m StringBuffer urlStringBuffer = new StringBuffer(); Matcher matcherUrl = patternURL.matcher(content); while (matcherUrl.find()) { String url = matcherUrl.group(); // System.out.println("URL:" + url); String urlToHref = "<a href=\"" + url + "\">" + url + "</a>"; matcherUrl.appendReplacement(urlStringBuffer, urlToHref); } matcherUrl.appendTail(urlStringBuffer); return urlStringBuffer.toString(); }
From source file:com.amazon.android.utils.JsonHelper.java
/** * This method removes comments from JSON string. * * @param jsonString JSON string with comments. * @return JSON string without comments. *//*from ww w.j a va 2 s . co m*/ public static String escapeComments(String jsonString) { if (jsonString == null) { return null; } String regex = COMMENT_START_SEQUENCE_ESCAPED + "(.*?|\n)" + // Match all type of cases including new line. COMMENT_STOP_SEQUENCE_ESCAPED; StringBuffer stringBuffer = new StringBuffer(jsonString.length()); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(jsonString); while (matcher.find()) { matcher.appendReplacement(stringBuffer, ""); } matcher.appendTail(stringBuffer); return stringBuffer.toString(); }
From source file:com.mmj.app.web.controller.search.SearchController.java
public static String ignoreCaseReplace(String source, String pattern) { Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE); Matcher mc = p.matcher(source); StringBuffer sb = new StringBuffer(); while (mc.find()) { mc.appendReplacement(sb, "<em class='highlight'>" + mc.group() + "</em>"); }//from w w w. j a va2 s. c o m mc.appendTail(sb); return sb.toString(); }
From source file:Main.java
private static String makeTelNoHerf(String telContent) { if (telContent.trim().length() == 0) { return telContent; }/*w ww .j a va2 s . c om*/ StringBuffer telNoStringBuffer = new StringBuffer(); Matcher matcherTelNo = patternTelNo.matcher(telContent); while (matcherTelNo.find()) { String telNo = matcherTelNo.group(); String telNoToHerf = "<a href=\"" + ProtocolKey_ACTION_DIAL + telNo + "\">" + telNo + "</a>"; matcherTelNo.appendReplacement(telNoStringBuffer, telNoToHerf); } matcherTelNo.appendTail(telNoStringBuffer); return telNoStringBuffer.toString(); }
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./* ww w . java 2 s .c o m*/ * @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:org.jutge.joc.porra.utils.PlayerUtils.java
public final static String readableName(final String playerName) { if (playerName == null) return null; final String cleanPlayerName = playerName.trim().replace(".", " "); final Matcher matcher = PATTERN.matcher(cleanPlayerName); final StringBuffer buffer = new StringBuffer(); while (matcher.find()) { final String replacement = StringUtils.capitalize(matcher.group()); matcher.appendReplacement(buffer, replacement); }// ww w.jav a 2 s . com matcher.appendTail(buffer); return buffer.toString(); }
From source file:nl.strohalm.cyclos.controls.BaseReceiptPrintAjaxAction.java
private static String replaceASCII(final String string) { if (StringUtils.isEmpty(string)) { return StringUtils.EMPTY; }// w w w .j a v a 2s . co m final Matcher matcher = ASCII.matcher(string); final StringBuffer sb = new StringBuffer(); while (matcher.find()) { final char c = (char) Integer.parseInt(matcher.group(1).substring(1)); matcher.appendReplacement(sb, String.valueOf(c)); } matcher.appendTail(sb); return StringUtils.replace(sb.toString(), "\\n", "\n"); }
From source file:org.ops4j.ramler.generator.Names.java
/** * Builds a name for a constant, converting camel case to upper snake case. Example: * {@code httpMethod -> HTTP_METHOD}. * * @param source/* w w w . j av a2 s. c o m*/ * any name * @return upper case string with underscores as word separators */ public static String buildConstantName(String source) { Matcher m = CAMEL_CASE_PATTERN.matcher(source); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, "_" + m.group()); } m.appendTail(sb); String friendlyName = sb.toString().toUpperCase(); if (isDigits(left(friendlyName, 1))) { friendlyName = "_" + friendlyName; } return friendlyName; }
From source file:org.ops4j.ramler.generator.Names.java
/** * Converts a camel case name to lower-case kebab case, using hyphens as separators. * E.g. {@code UserGroup -> user-group}. * * @param source camel case string//ww w . j a v a 2s . co m * @return hyphen-separated lower-case string */ public static String buildLowerKebabCaseName(String source) { Matcher m = CAMEL_CASE_PATTERN.matcher(source); StringBuffer sb = new StringBuffer(); while (m.find()) { m.appendReplacement(sb, "-" + m.group()); } m.appendTail(sb); String friendlyName = sb.toString().toLowerCase(); if (isDigits(left(friendlyName, 1))) { friendlyName = "-" + friendlyName; } return friendlyName; }