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


Java StringUtils.splitByWholeSeparator方法代码示例

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


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

示例1: split

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
@Override
protected String[] split(String str, String separatorChars, int max, boolean preserveAllTokens) {
    if (preserveAllTokens) {
        return StringUtils.splitByWholeSeparatorPreserveAllTokens(str, separatorChars, max);
    } else {
        return StringUtils.splitByWholeSeparator(str, separatorChars, max);
    }
}
 
开发者ID:virjar,项目名称:vscrawler,代码行数:9,代码来源:SplitByWholeSeparator.java

示例2: handleDate

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private void handleDate(File tempTsvFileForDate) throws IOException, ParserException {

        String date=null;
        try(BufferedReader reader=new BufferedReader(new FileReader(tempTsvFileForDate)))
        {
            for(String line=reader.readLine();line!=null;line=reader.readLine())
            {
                line=line.trim();
                if(!StringUtils.startsWithIgnoreCase(line,"Date"))
                    continue;

                final String[] split = StringUtils.splitByWholeSeparator(line, " ");
                if(split.length!=2)
                    throw new ParserException("Could not parse date field: "+line);

                date=split[1];
                break;
            }
        }

        if(date==null)
            throw new ParserException("Never found date field");

        //start guessing at the date format
        boolean isEuroDate=isEuroDate(date);
        boolean isUSDate=isUSDate(date);

        if(!isEuroDate && !isUSDate)
            throw new ParserException("Could not parse date field: "+date);

        if(isEuroDate && !isUSDate) {
            dateParser = Format.euroDateFormatter;
            return;
        }

        if(!isEuroDate) {
            dateParser = Format.usDateFormatter;
            return;
        }

        //hmmm.... date is valid in both formats. Use the filename instead

        try {
            final String[] array = StringUtils.splitByWholeSeparator(inputPdfFile.getName(), "-");
            int year = Integer.parseInt(array[0]);
            int month = Integer.parseInt(array[1]);
            if (year < 2017 || month <= 6)
                dateParser = Format.euroDateFormatter;
            else
                dateParser = Format.usDateFormatter;

            remittanceDate=dateParser.parse(date);

        }
        catch (Throwable t)
        {
            throw new ParserException("Can not determine date format to use.",t);
        }

    }
 
开发者ID:BigBrassBand,项目名称:remittanceparse,代码行数:61,代码来源:RemittancePdf.java

示例3: splitString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
 * 分割固定格式的字符串
 */
public static String[] splitString(String str, String separator) {
    return StringUtils.splitByWholeSeparator(str, separator);
}
 
开发者ID:envyandgreed,项目名称:SmartFramework,代码行数:7,代码来源:StringUtil.java

示例4: parseString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
private ImmutableList<TextMarkupDocumentSection> parseString(String text, MutableList<String> elementsToCheck, boolean recurse,
        String elementPrefix) {
    MutableList<TextMarkupDocumentSection> sections = Lists.mutable.empty();
    while (true) {
        int earliestIndex = Integer.MAX_VALUE;

        for (String firstLevelElement : elementsToCheck) {
            int index = text.indexOf(elementPrefix + " " + firstLevelElement, 1);
            if (index != -1 && index < earliestIndex) {
                earliestIndex = index;
            }
        }

        if (earliestIndex == Integer.MAX_VALUE) {
            sections.add(new TextMarkupDocumentSection(null, text));
            break;
        } else {
            sections.add(new TextMarkupDocumentSection(null, text.substring(0, earliestIndex)));
            text = text.substring(earliestIndex);
        }
    }
    for (TextMarkupDocumentSection section : sections) {
        MutableMap<String, String> attrs = Maps.mutable.empty();
        MutableSet<String> toggles = Sets.mutable.empty();
        String content = StringUtils.chomp(section.getContent());

        String[] contents = content.split("\\r?\\n", 2);
        String firstLine = contents[0];

        for (String elementToCheck : elementsToCheck) {
            if (firstLine.startsWith(elementPrefix + " " + elementToCheck)) {
                section.setName(elementToCheck);
                String[] args = StringUtils.splitByWholeSeparator(firstLine, " ");
                for (String arg : args) {
                    if (arg.contains("=")) {
                        String[] attr = arg.split("=");
                        if (attr.length > 2) {
                            throw new IllegalArgumentException("Cannot mark = multiple times in a parameter - "
                                    + firstLine);
                        }
                        String attrVal = attr[1];
                        if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
                            attrVal = attrVal.substring(1, attrVal.length() - 1);
                        }
                        attrs.put(attr[0], attrVal);
                    } else {
                        toggles.add(arg);
                    }
                }
                if (contents.length > 1) {
                    content = contents[1];
                } else {
                    content = null;
                }
            }
        }
        section.setAttrs(attrs.toImmutable());
        section.setToggles(toggles.toImmutable());

        if (!recurse) {
            section.setContent(content);
        } else if (content != null) {
            ImmutableList<TextMarkupDocumentSection> subsections = this.parseString(content, this.secondLevelElements, false, "//");
            if (subsections.size() == 1) {
                section.setContent(content);
            } else {
                section.setContent(subsections.get(0).getContent());
                section.setSubsections(subsections.subList(1, subsections.size()));
            }
        } else {
            section.setContent(null);
        }
    }

    return sections.toImmutable();
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:77,代码来源:TextMarkupDocumentReaderOld.java

示例5: parseAttrsAndToggles

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
Pair<ImmutableMap<String, String>, ImmutableSet<String>> parseAttrsAndToggles(String line) {
    MutableMap<String, String> attrs = Maps.mutable.empty();
    MutableSet<String> toggles = Sets.mutable.empty();

    if (!legacyMode) {
        List<Token> tokens = TextMarkupParser.parseTokens(line);
        Token curToken = !tokens.isEmpty() ? tokens.get(0) : null;
        while (curToken != null && curToken.kind != TextMarkupLineSyntaxParserConstants.EOF) {
            switch (curToken.kind) {
            case TextMarkupLineSyntaxParserConstants.WHITESPACE:
                // skip whitespace if encountered
                break;
            case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL:
            case TextMarkupLineSyntaxParserConstants.STRING_LITERAL:
                // let's check if this is a toggle or an attribute
                if (curToken.next.kind == TextMarkupLineSyntaxParserConstants.ASSIGN) {
                    Token keyToken = curToken;
                    curToken = curToken.next;  // to ASSIGN
                    curToken = curToken.next;  // to the following token
                    switch (curToken.kind) {
                    case TextMarkupLineSyntaxParserConstants.QUOTED_LITERAL:
                    case TextMarkupLineSyntaxParserConstants.STRING_LITERAL:
                        // in this case, we have an attribute value
                        String value = curToken.image;
                        if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
                            value = curToken.image.substring(1, curToken.image.length() - 1);
                        }
                        value = value.replaceAll("\\\\\"", "\"");
                        attrs.put(keyToken.image, value);
                        break;
                    case TextMarkupLineSyntaxParserConstants.WHITESPACE:
                    case TextMarkupLineSyntaxParserConstants.EOF:
                        // in this case, we will assume a blank value
                        attrs.put(keyToken.image, "");
                        break;
                    case TextMarkupLineSyntaxParserConstants.ASSIGN:
                    default:
                        throw new IllegalStateException("Not allowed here");
                    }
                } else {
                    toggles.add(curToken.image);
                }
                break;
            case TextMarkupLineSyntaxParserConstants.ASSIGN:
                toggles.add(curToken.image);
                break;
            case TextMarkupLineSyntaxParserConstants.EOF:
            default:
                throw new IllegalStateException("Should not arise");
            }

            curToken = curToken.next;
        }
    } else {
        // keeping this mode for backwards-compatibility until we can guarantee all clients are fine without it
        // This way cannot handle spaces in quotes
        String[] args = StringUtils.splitByWholeSeparator(line, " ");

        for (String arg : args) {
            if (arg.contains("=")) {
                String[] attr = arg.split("=");
                if (attr.length > 2) {
                    throw new IllegalArgumentException("Cannot mark = multiple times in a parameter - " + line);
                }
                String attrVal = attr[1];
                if (attrVal.startsWith("\"") && attrVal.endsWith("\"")) {
                    attrVal = attrVal.substring(1, attrVal.length() - 1);
                }
                attrs.put(attr[0], attrVal);
            } else if (StringUtils.isNotBlank(arg)) {
                toggles.add(arg);
            }
        }
    }

    return Tuples.pair(attrs.toImmutable(), toggles.toImmutable());
}
 
开发者ID:goldmansachs,项目名称:obevo,代码行数:78,代码来源:TextMarkupDocumentReader.java

示例6: splitString

import org.apache.commons.lang3.StringUtils; //导入方法依赖的package包/类
/**
 * 分割固定格式字符串
 *
 * @param str
 * @param separator
 * @return
 */
public static String[] splitString(String str, String separator) {
    return StringUtils.splitByWholeSeparator(str, separator);
}
 
开发者ID:CFshuming,项目名称:bfmvc,代码行数:11,代码来源:StringUtil.java


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