Example usage for java.util.regex Matcher appendTail

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

Introduction

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

Prototype

public StringBuilder appendTail(StringBuilder sb) 

Source Link

Document

Implements a terminal append-and-replace step.

Usage

From source file:Main.java

public static String filterHtml(String str) {
    Pattern pattern = Pattern.compile(regxpForHtml);
    Matcher matcher = pattern.matcher(str);
    StringBuffer sb = new StringBuffer();
    boolean result1 = matcher.find();
    while (result1) {
        matcher.appendReplacement(sb, "");
        result1 = matcher.find();// w  w  w . jav  a  2s.  c om
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:Main.java

public static String fiterHtmlTag(String str, String tag) {
    String regxp = "<\\s*" + tag + "\\s+([^>]*)\\s*>";
    Pattern pattern = Pattern.compile(regxp);
    Matcher matcher = pattern.matcher(str);
    StringBuffer sb = new StringBuffer();
    boolean result1 = matcher.find();
    while (result1) {
        matcher.appendReplacement(sb, "");
        result1 = matcher.find();// ww w . j  a  v  a  2 s  .  c o  m
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:com.titankingdoms.dev.titanchat.format.Censor.java

/**
 * Filters the text for phrases and censors the phrases with the censor
 * /*w w w  .j  av a  2 s .c  o  m*/
 * @param text The text to filter
 * 
 * @param phrases The phrases to censor
 * 
 * @param censor The censor to use
 * 
 * @return The filtered text
 */
public static String filter(String text, List<String> phrases, String censor) {
    if (text == null)
        return "";

    if (phrases == null)
        return text;

    if (censor == null)
        censor = "";

    StringBuffer filtered = new StringBuffer();

    String regex = "(" + StringUtils.join(phrases.toArray(new String[0])) + ")";

    Pattern phrasePattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
    Matcher match = phrasePattern.matcher(text);

    while (match.find())
        match.appendReplacement(filtered, Pattern.compile(".").matcher(match.group()).replaceAll(censor));

    return match.appendTail(filtered).toString();
}

From source file:Main.java

public static String fixCharCode(String wholeFile) {
    long millis = System.currentTimeMillis();
    Matcher mat = CHAR_CODE_PATTERN.matcher(wholeFile);
    StringBuffer sb = new StringBuffer();
    while (mat.find()) {
        // System.gc();
        mat.appendReplacement(sb, ((char) Integer.parseInt(mat.group(1)) + ""));
    }/* www  . j  av a  2s.c  o m*/
    mat.appendTail(sb);
    Log.d("fix char code time: ", "" + (System.currentTimeMillis() - millis));
    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);
    }//from w w  w  .j ava  2  s .  c o m
    matcher.appendTail(sb);

    return sb.toString().toUpperCase(Locale.US);
}

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 a2 s .  c  om*/
        m.appendReplacement(sb, Matcher.quoteReplacement(text.toUpperCase()));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:Main.java

/**
 * entitize/*from w  ww.  jav  a  2s  .com*/
 * 
 * @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: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  av a 2  s.  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;/*from  w w  w  .  j av  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   w w  w. jav  a 2 s.c o  m
    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();
}