当前位置: 首页>>代码示例>>Java>>正文


Java Pattern.UNIX_LINES属性代码示例

本文整理汇总了Java中java.util.regex.Pattern.UNIX_LINES属性的典型用法代码示例。如果您正苦于以下问题:Java Pattern.UNIX_LINES属性的具体用法?Java Pattern.UNIX_LINES怎么用?Java Pattern.UNIX_LINES使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.util.regex.Pattern的用法示例。


在下文中一共展示了Pattern.UNIX_LINES属性的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例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)) {
            pFlags |= UNICODE_CHARACTER_CLASS;
        } else {
            throw new IllegalArgumentException("Unknown regex flag [" + s + "]");
        }
    }
    return pFlags;
}
 
开发者ID:baidu,项目名称:Elasticsearch,代码行数:31,代码来源:Regex.java


注:本文中的java.util.regex.Pattern.UNIX_LINES属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。