當前位置: 首頁>>代碼示例>>Java>>正文


Java Pattern.UNICODE_CASE屬性代碼示例

本文整理匯總了Java中java.util.regex.Pattern.UNICODE_CASE屬性的典型用法代碼示例。如果您正苦於以下問題:Java Pattern.UNICODE_CASE屬性的具體用法?Java Pattern.UNICODE_CASE怎麽用?Java Pattern.UNICODE_CASE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在java.util.regex.Pattern的用法示例。


在下文中一共展示了Pattern.UNICODE_CASE屬性的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toString

@Override
public String toString() {
    StringBuilder f = new StringBuilder();
    if ((flags & Pattern.CANON_EQ) != 0)                f.append('c');
    if ((flags & Pattern.CASE_INSENSITIVE) != 0)        f.append('i');
    if ((flags & Pattern.LITERAL) != 0)                 f.append('l');
    if ((flags & Pattern.MULTILINE) != 0)               f.append('m');
    if ((flags & Pattern.DOTALL) != 0)                  f.append('s');
    if ((flags & Pattern.UNICODE_CHARACTER_CLASS) != 0) f.append('U');
    if ((flags & Pattern.UNICODE_CASE) != 0)            f.append('u');
    if ((flags & Pattern.COMMENTS) != 0)                f.append('x');

    String p = "/" + pattern + "/";
    if (f.length() == 0) {
        return singleLineToString(p);
    }
    return singleLineToString(p, f);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:18,代碼來源:ERegex.java

示例2: testFlags

public void testFlags() {
    String[] supportedFlags = new String[]{"CASE_INSENSITIVE", "MULTILINE", "DOTALL", "UNICODE_CASE", "CANON_EQ", "UNIX_LINES",
            "LITERAL", "COMMENTS", "UNICODE_CHAR_CLASS", "UNICODE_CHARACTER_CLASS"};
    int[] flags = new int[]{Pattern.CASE_INSENSITIVE, Pattern.MULTILINE, Pattern.DOTALL, Pattern.UNICODE_CASE, Pattern.CANON_EQ,
            Pattern.UNIX_LINES, Pattern.LITERAL, Pattern.COMMENTS, Regex.UNICODE_CHARACTER_CLASS};
    Random random = random();
    int num = 10 + random.nextInt(100);
    for (int i = 0; i < num; i++) {
        int numFlags = random.nextInt(flags.length + 1);
        int current = 0;
        StringBuilder builder = new StringBuilder();
        for (int j = 0; j < numFlags; j++) {
            int index = random.nextInt(flags.length);
            current |= flags[index];
            builder.append(supportedFlags[index]);
            if (j < numFlags - 1) {
                builder.append("|");
            }
        }
        String flagsToString = Regex.flagsToString(current);
        assertThat(Regex.flagsFromString(builder.toString()), equalTo(current));
        assertThat(Regex.flagsFromString(builder.toString()), equalTo(Regex.flagsFromString(flagsToString)));
        Pattern.compile("\\w\\d{1,2}", current); // accepts the flags?
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:RegexTests.java

示例3: Finder

/**
 * Constructor for Finder.
 */
public Finder(
    HTMLEditor theEditor,
    String find,
    boolean wholeWord,
    boolean matchCase,
    boolean regexp,
    String replace) {
    super();
    editor = theEditor;
    dispText = find;
    int flags = Pattern.DOTALL;
    if (!matchCase)
        flags = flags + Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE;
    _find = find;
    if (!regexp)
        _find = "\\Q" + _find + "\\E";
    if (wholeWord)
        _find = "[\\s\\p{Punct}]" + _find + "[\\s\\p{Punct}]";
    try {
        pattern = Pattern.compile(_find, flags);
    }
    catch (Exception ex) {
        ex.printStackTrace();
        pattern = null;
    }
    _replace = replace;
}
 
開發者ID:ser316asu,項目名稱:Neukoelln_SER316,代碼行數:30,代碼來源:Finder.java

示例4: flagForChar

private int flagForChar(char c) {
    switch (c) {
        case 'c': return Pattern.CANON_EQ;
        case 'i': return Pattern.CASE_INSENSITIVE;
        case 'l': return Pattern.LITERAL;
        case 'm': return Pattern.MULTILINE;
        case 's': return Pattern.DOTALL;
        case 'U': return Pattern.UNICODE_CHARACTER_CLASS;
        case 'u': return Pattern.UNICODE_CASE;
        case 'x': return Pattern.COMMENTS;
        default:
            throw new IllegalArgumentException("Unknown flag [" + c + "]");
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:14,代碼來源:ERegex.java

示例5: flagsFromString

public static int flagsFromString(String flags) {
    int pFlags = 0;
    for (String s : Strings.delimitedListToStringArray(flags, "|")) {
        if (s.isEmpty()) {
            continue;
        }
        s = s.toUpperCase(Locale.ROOT);
        if ("CASE_INSENSITIVE".equals(s)) {
            pFlags |= Pattern.CASE_INSENSITIVE;
        } else if ("MULTILINE".equals(s)) {
            pFlags |= Pattern.MULTILINE;
        } else if ("DOTALL".equals(s)) {
            pFlags |= Pattern.DOTALL;
        } else if ("UNICODE_CASE".equals(s)) {
            pFlags |= Pattern.UNICODE_CASE;
        } else if ("CANON_EQ".equals(s)) {
            pFlags |= Pattern.CANON_EQ;
        } else if ("UNIX_LINES".equals(s)) {
            pFlags |= Pattern.UNIX_LINES;
        } else if ("LITERAL".equals(s)) {
            pFlags |= Pattern.LITERAL;
        } else if ("COMMENTS".equals(s)) {
            pFlags |= Pattern.COMMENTS;
        } else if (("UNICODE_CHAR_CLASS".equals(s)) || ("UNICODE_CHARACTER_CLASS".equals(s))) {
            pFlags |= UNICODE_CHARACTER_CLASS;
        } else {
            throw new IllegalArgumentException("Unknown regex flag [" + s + "]");
        }
    }
    return pFlags;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:Regex.java

示例6: flagsToString

public static String flagsToString(int flags) {
    StringBuilder sb = new StringBuilder();
    if ((flags & Pattern.CASE_INSENSITIVE) != 0) {
        sb.append("CASE_INSENSITIVE|");
    }
    if ((flags & Pattern.MULTILINE) != 0) {
        sb.append("MULTILINE|");
    }
    if ((flags & Pattern.DOTALL) != 0) {
        sb.append("DOTALL|");
    }
    if ((flags & Pattern.UNICODE_CASE) != 0) {
        sb.append("UNICODE_CASE|");
    }
    if ((flags & Pattern.CANON_EQ) != 0) {
        sb.append("CANON_EQ|");
    }
    if ((flags & Pattern.UNIX_LINES) != 0) {
        sb.append("UNIX_LINES|");
    }
    if ((flags & Pattern.LITERAL) != 0) {
        sb.append("LITERAL|");
    }
    if ((flags & Pattern.COMMENTS) != 0) {
        sb.append("COMMENTS|");
    }
    if ((flags & UNICODE_CHARACTER_CLASS) != 0) {
        sb.append("UNICODE_CHAR_CLASS|");
    }
    return sb.toString();
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:31,代碼來源:Regex.java

示例7: parseFlags

public static int parseFlags(@Nullable BytesRef flagsString) {
    int flags = 0;
    if (flagsString == null) {
        return flags;
    }
    for (char flag : flagsString.utf8ToString().toCharArray()) {
        switch (flag) {
            case 'i':
                flags = flags | Pattern.CASE_INSENSITIVE;
                break;
            case 'u':
                flags = flags | Pattern.UNICODE_CASE;
                break;
            case 'U':
                flags = flags | Pattern.UNICODE_CHARACTER_CLASS;
                break;
            case 's':
                flags = flags | Pattern.DOTALL;
                break;
            case 'm':
                flags = flags | Pattern.MULTILINE;
                break;
            case 'x':
                flags = flags | Pattern.COMMENTS;
                break;
            case 'd':
                flags = flags | Pattern.UNIX_LINES;
                break;
            default:
                break;
        }
    }

    return flags;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:35,代碼來源:RegexMatcher.java

示例8: flagsFromString

public static int flagsFromString(String flags) {
    int pFlags = 0;
    for (String s : Strings.delimitedListToStringArray(flags, "|")) {
        if (s.isEmpty()) {
            continue;
        }
        s = s.toUpperCase(Locale.ROOT);
        if ("CASE_INSENSITIVE".equals(s)) {
            pFlags |= Pattern.CASE_INSENSITIVE;
        } else if ("MULTILINE".equals(s)) {
            pFlags |= Pattern.MULTILINE;
        } else if ("DOTALL".equals(s)) {
            pFlags |= Pattern.DOTALL;
        } else if ("UNICODE_CASE".equals(s)) {
            pFlags |= Pattern.UNICODE_CASE;
        } else if ("CANON_EQ".equals(s)) {
            pFlags |= Pattern.CANON_EQ;
        } else if ("UNIX_LINES".equals(s)) {
            pFlags |= Pattern.UNIX_LINES;
        } else if ("LITERAL".equals(s)) {
            pFlags |= Pattern.LITERAL;
        } else if ("COMMENTS".equals(s)) {
            pFlags |= Pattern.COMMENTS;
        } else if ("UNICODE_CHAR_CLASS".equals(s)) {
            pFlags |= UNICODE_CHARACTER_CLASS;
        } else {
            throw new IllegalArgumentException("Unknown regex flag [" + s + "]");
        }
    }
    return pFlags;
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:31,代碼來源:Regex.java

示例9: getPatternFlags

/**
 * Returns the flags necessary to create a {@link Pattern}.
 *
 * @param matchCase Whether the pattern should be case sensitive.
 * @param others Any other flags.  This may be <code>0</code>.
 * @return The flags.
 */
public static int getPatternFlags(boolean matchCase, int others) {
	if (!matchCase) {
		others |= Pattern.CASE_INSENSITIVE|Pattern.UNICODE_CASE;
	}
	return others;
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:13,代碼來源:RSyntaxUtilities.java


注:本文中的java.util.regex.Pattern.UNICODE_CASE屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。