Example usage for java.util.regex Matcher end

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

Introduction

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

Prototype

public int end() 

Source Link

Document

Returns the offset after the last character matched.

Usage

From source file:com.manydesigns.elements.util.Util.java

public static StringBuilder replaceBadUnicodeCharacters(String source, StringBuilder dest) {
    Matcher m = BAD_UNICODE_CHARS_PATTERN.matcher(source);
    int index = 0;
    while (m.find()) {
        String g = m.group();/*from w w w  .  j  a  v a 2  s. co m*/
        dest.append(source.substring(index, m.end() - 1));
        index = m.end();
        if (g.equals("\u2013") || g.equals("\u2014")) {
            dest.append('-');
        } else if (g.equals("\u2018") || g.equals("\u2019") || g.equals("\u0092")) {
            dest.append('\'');
        } else if (g.equals("\u201C") || g.equals("\u201D")) {
            dest.append('"');
        } else if (g.equals("\u2022")) {
            dest.append('*');
        } else if (g.equals("\u2026")) {
            dest.append("...");
        } else if (g.equals("\u0093")) {
            dest.append("<<");
        } else if (g.equals("\u0094")) {
            dest.append(">>");
        }
    }
    dest.append(source.substring(index, source.length()));
    return dest;
}

From source file:Main.java

public static CharSequence handleAcUrl(CharSequence content) {
    Matcher m = AC_PATTERN.matcher(content);

    Spannable spannable = null;/* w w  w . java 2 s  .  c  o m*/
    while (m.find()) {
        // Ensure spannable
        if (spannable == null) {
            if (content instanceof Spannable) {
                spannable = (Spannable) content;
            } else {
                spannable = new SpannableString(content);
            }
        }

        int start = m.start();
        int end = m.end();

        URLSpan[] links = spannable.getSpans(start, end, URLSpan.class);
        if (links.length > 0) {
            // There has been URLSpan already, leave it alone
            continue;
        }

        URLSpan urlSpan = new URLSpan("http://www.acfun.tv/v/" + m.group(0));
        spannable.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spannable == null ? content : spannable;
}

From source file:Main.java

public static CharSequence replace(Context context, String text) {
    if (TextUtils.isEmpty(text)) {
        return text;
    }/*  w ww  .j  a  v  a  2  s  . c o  m*/
    SpannableString spannableString = new SpannableString(text);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        String factText = matcher.group();
        String key = factText.substring(1, factText.length() - 1);
        if (contain(emojiCodes, factText)) {
            Bitmap bitmap = getEmojiDrawable(context, key);
            ImageSpan image = new ImageSpan(context, bitmap);
            int start = matcher.start();
            int end = matcher.end();
            spannableString.setSpan(image, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    return spannableString;
}

From source file:Main.java

public static CharSequence handleTextUrl(CharSequence content) {
    Matcher m = URL_PATTERN.matcher(content);

    Spannable spannable = null;//from   www.j a v a 2s  .c  o m
    while (m.find()) {
        // Ensure spannable
        if (spannable == null) {
            if (content instanceof Spannable) {
                spannable = (Spannable) content;
            } else {
                spannable = new SpannableString(content);
            }
        }

        int start = m.start();
        int end = m.end();

        URLSpan[] links = spannable.getSpans(start, end, URLSpan.class);
        if (links.length > 0) {
            // There has been URLSpan already, leave it alone
            continue;
        }

        URLSpan urlSpan = new URLSpan(m.group(0));
        spannable.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spannable == null ? content : spannable;
}

From source file:wuit.common.crawler.WebSit.Crawler.java

public static void matchValues(String content, String filter, List<KeyValue> list) {
    if (list == null)
        list = new ArrayList<KeyValue>();
    try {//from   w  w w .  ja  v  a  2  s  . co  m
        Matcher m = Pattern.compile(filter, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE).matcher(content);
        while (m.find()) {
            if (m.group().isEmpty())
                continue;
            KeyValue value = new KeyValue();
            value.value = m.group();
            value.start = m.start();
            value.end = m.end();
            list.add(value);
        }
    } catch (Exception e) {
        System.out.println("Crawler Utitles  matchValues :" + e.getMessage());
    }
}

From source file:com.manydesigns.elements.util.Util.java

public static StringBuilder replaceBadUnicodeCharactersWithHtmlEntities(String source, StringBuilder dest) {
    Matcher m = BAD_UNICODE_CHARS_PATTERN.matcher(source);
    int index = 0;
    while (m.find()) {
        String g = m.group();//  w  w  w.j  a va  2  s.  c  om
        dest.append(source.substring(index, m.end() - 1));
        index = m.end();
        if (g.equals("\u2013")) {
            dest.append("&ndash;");
        } else if (g.equals("\u2014")) {
            dest.append("&mdash;");
        } else if (g.equals("\u2018")) {
            dest.append("&lsquo;");
        } else if (g.equals("\u2019")) {
            dest.append("&rsquo;");
        } else if (g.equals("\u0092")) {
            dest.append("'");
        } else if (g.equals("\u201C")) {
            dest.append("&ldquo;");
        } else if (g.equals("\u201D")) {
            dest.append("&rdquo;");
        } else if (g.equals("\u2022")) {
            dest.append("&bull;");
        } else if (g.equals("\u2026")) {
            dest.append("&hellip;");
        } else if (g.equals("\u0093")) {
            dest.append("&lt;&lt;");
        } else if (g.equals("\u0094")) {
            dest.append("&gt;&gt;");
        }
    }
    dest.append(source.substring(index, source.length()));
    return dest;
}

From source file:com.ms.commons.utilities.CharTools.java

/**
 *  T&#24676;  T??  unicode ? 10?// w  w  w . j a v  a 2  s .  co  m
 * 
 * @param str
 * @return
 */
public static String unicodeUrlDecode(String str) {
    if (StringUtils.isBlank(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder();
    Matcher matcher = unicode_url_pattern.matcher(str);
    int preEnd = 0;
    while (matcher.find()) {
        String group = matcher.group(1);
        int start = matcher.start();
        sb.append(str.substring(preEnd, start));
        sb.append(fromCharCode(Integer.parseInt(group)));
        preEnd = matcher.end();
    }
    sb.append(str.substring(preEnd, str.length()));
    return sb.toString();
}

From source file:GrepSun.java

private static void grep(File f, CharBuffer cb) {
    Matcher lm = linePattern.matcher(cb); // Line matcher
    Matcher pm = null; // Pattern matcher
    int lines = 0;
    while (lm.find()) {
        lines++;/*from  w ww .j ava  2 s . c  o m*/
        CharSequence cs = lm.group(); // The current line
        if (pm == null)
            pm = pattern.matcher(cs);
        else
            pm.reset(cs);
        if (pm.find())
            System.out.print(f + ":" + lines + ":" + cs);
        if (lm.end() == cb.limit())
            break;
    }
}

From source file:de.bayern.gdi.utils.StringUtils.java

/**
 * Splits a string by a pattern.//from   w w  w.ja  v  a 2s.  c  o  m
 * @param s The string to split.
 * @param delim The delimeter.
 * @param keep Indicates if the delimeters should be kept.
 * @return The splitted string.
 */
public static String[] split(String s, Pattern delim, boolean keep) {
    if (s == null) {
        s = "";
    }
    int lastMatch = 0;
    ArrayList<String> parts = new ArrayList<>();
    Matcher m = delim.matcher(s);
    while (m.find()) {
        String x = s.substring(lastMatch, m.start());
        if (!x.isEmpty()) {
            parts.add(x);
        }
        if (keep) {
            parts.add(m.group(0));
        }
        lastMatch = m.end();
    }
    String x = s.substring(lastMatch);
    if (!x.isEmpty()) {
        parts.add(x);
    }
    return parts.toArray(new String[parts.size()]);
}

From source file:com.civprod.writerstoolbox.NaturalLanguage.util.RegexStringTokenizer.java

private static List<String> Tokenize(List<String> ReturnList, Pattern possivePattern,
        List<Pattern> ignorePatterns, int sizeGuess) {
    List<String> TempList = new java.util.ArrayList<>(sizeGuess);
    for (String curWord : ReturnList) {
        if (ignorePatterns.parallelStream()
                .noneMatch((Pattern curPattern) -> curPattern.matcher(curWord).matches())) {
            Matcher matcher = possivePattern.matcher(curWord);
            int lastEnd = 0;
            while (matcher.find()) {
                String pre = curWord.substring(lastEnd, matcher.start());
                if (!pre.isEmpty()) {
                    TempList.add(pre);//ww  w.  j  av  a 2s.c o m
                }
                String match = curWord.substring(matcher.start(), matcher.end());
                if (!match.isEmpty()) {
                    TempList.add(match);
                }
                lastEnd = matcher.end();
            }
            String end = curWord.substring(lastEnd);
            if (!end.isEmpty()) {
                TempList.add(end);
            }
        } else {
            TempList.add(curWord);
        }
    }
    return TempList;
}