Example usage for java.util.regex Matcher appendReplacement

List of usage examples for java.util.regex Matcher appendReplacement

Introduction

In this page you can find the example usage for java.util.regex Matcher appendReplacement.

Prototype

public Matcher appendReplacement(StringBuilder sb, String replacement) 

Source Link

Document

Implements a non-terminal append-and-replace step.

Usage

From source file:iox.refused.jhp.JHP_Parser.java

private static String compileImports(StringBuffer buffer, String src) {
    Matcher m = IMPORTS.matcher(src);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String imp = m.group(1);//from  ww  w .j  av  a  2s.c  o m
        buffer.append("import ").append(imp).append(";\n");
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.SqlHelper.java

public static String removeXsqlBuilderOrders(String string) {
    Preconditions.checkNotNull(string);//from   w  ww.  jav a 2  s  . c  om
    Pattern p = Pattern.compile(XSQL_ORDER_BY_REGEX, Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(string);
    StringBuffer sb = new StringBuffer(string.length());
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return removeOrders(sb.toString());
}

From source file:team.curise.dao.BaseDao.java

/**
 * orderby??/*from  w w  w.ja va 2  s  .  co m*/
 * @param hql
 * @return
 */
public static String removeOrders(String hql) {
    Assert.hasText(hql);
    Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(hql);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.pactera.edg.am.metamanager.extractor.util.Utils.java

public static String transformName(String name) {
    try {/*from   w  w w.  jav  a 2 s .  com*/
        Properties properties = TransformConfLoader.getProperties();
        StringBuffer sb = new StringBuffer();
        for (Enumeration<Object> enumer = properties.keys(); enumer.hasMoreElements();) {
            // ?????
            Object expression = enumer.nextElement();

            Pattern regex = Pattern.compile((String) expression);
            Matcher regexMatcher = regex.matcher(name);

            // ?????
            String targetExpression = (String) properties.get(expression);

            if (regexMatcher.find()) {
                // ????
                regexMatcher.appendReplacement(sb, targetExpression);
                // ?
                if (log.isDebugEnabled()) {
                    log.debug(new StringBuilder("????:").append(name).append(" ????:")
                            .append(sb).toString());
                }
                return sb.toString();
            }
        }

    } catch (Exception e) {
        log.warn("????!????:" + name, e);

    }

    return name;
}

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);
    }//from w  ww .jav  a  2s .c o  m
    matcher.appendTail(buffer);
    return buffer.toString();
}

From source file:com.hexidec.ekit.component.HTMLTableUtilities.java

private static String adicionaBRnoFimDosTD(String str) {

    Matcher m = pFimDeTDnaoPrecedidoDeBR.matcher(str);
    if (!m.find()) {
        return str;
    }/* w ww  .java 2s  .  co  m*/

    StringBuffer sb = new StringBuffer();
    do {
        m.appendReplacement(sb, "<br/>" + Matcher.quoteReplacement(m.group()));
    } while (m.find());

    m.appendTail(sb);

    return sb.toString();
}

From source file:nl.strohalm.cyclos.controls.BaseReceiptPrintAjaxAction.java

private static String replaceASCII(final String string) {
    if (StringUtils.isEmpty(string)) {
        return StringUtils.EMPTY;
    }//from 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.apache.ode.axis2.httpbinding.HttpClientHelper.java

/**
 * This method ensures that a header value containing CRLF does not mess up the HTTP request.
 * Actually CRLF is the end-of-line marker for headers.
 * <p/>/*from   w  w w.  ja v a  2  s  . c o  m*/
 * To do so, all CRLF followed by a non-whitespace character are replaced by CRLF HT.
 * <p/>
 * This is possible because the
 * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2">Section 2.2</a> of HTTP standard (RFC2626) states that:
 * <p/>
 * <quote>
 * HTTP/1.1 header field values can be folded onto multiple lines if the
 * continuation line begins with a space or horizontal tab. All linear
 * white space, including folding, has the same semantics as SP. A
 * recipient MAY replace any linear white space with a single SP before
 * interpreting the field value or forwarding the message downstream.
 * <p/>
 * LWS            = [CRLF] 1*( SP | HT )
 * <p/>
 * </quote>
 * <p/>
 * FYI, HttpClient 3.x.x does not check this.
 *
 * @param header
 * @return the string properly ready to be used as an HTTP header field-content
 */
public static String replaceCRLFwithLWS(String header) {
    Matcher m = NON_LWS_PATTERN.matcher(header);
    StringBuffer sb = new StringBuffer(header.length());
    while (m.find()) {
        m.appendReplacement(sb, "\r\n\t");
        sb.append(m.group(1));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.o19s.solr.swan.nodes.SwanTermNode.java

private static String translateWildcard(String in) {
    Matcher m = WILDCARD_PATTERN.matcher(in);
    StringBuffer sb = new StringBuffer(in.length());

    while (m.find()) {
        if (m.group(0).equals("?")) {
            m.appendReplacement(sb, ".");
        } else if (m.group(0).equals("*")) {
            m.appendReplacement(sb, ".*");
        } else {//  w  w w .j a  v  a 2  s .co  m
            if (!m.group(1).isEmpty())
                m.appendReplacement(sb, ".{0," + m.group(1) + "}");
            else
                m.appendReplacement(sb, ".*");
        }
    }
    m.appendTail(sb);

    return sb.toString();
}

From source file:org.openmrs.module.databasebackup.util.DbDump.java

private static String escape(String s) {
    Matcher matcher = sqlTokenPattern.matcher(s);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(sb, sqlTokens.get(matcher.group(1)));
    }/*w ww. j av  a2 s  .c o m*/
    matcher.appendTail(sb);
    return sb.toString();
}