Example usage for org.apache.commons.lang StringUtils splitByCharacterType

List of usage examples for org.apache.commons.lang StringUtils splitByCharacterType

Introduction

In this page you can find the example usage for org.apache.commons.lang StringUtils splitByCharacterType.

Prototype

public static String[] splitByCharacterType(String str) 

Source Link

Document

Splits a String by Character type as returned by java.lang.Character.getType(char).

Usage

From source file:com.intellij.lang.jsgraphql.lexer.JSGraphQLLexer.java

private void fetchTokensFromLanguageService() {

    final String bufferAsString = buffer.toString();
    if (buffer.length() == 0) {
        response = new TokensResponse();
        return;//from  w w  w .  ja  va  2s . c  om
    }

    // get the response using the client
    response = JSGraphQLNodeLanguageServiceClient.getTokens(bufferAsString, project);

    if (response == null) {
        // blank
        response = new TokensResponse();
        Token dummy = new Token();
        dummy.setStart(startOffset);
        dummy.setEnd(endOffset);
        dummy.setText(bufferAsString.substring(startOffset, endOffset));
        dummy.setKind("unknown");
        dummy.setType("unknown");
        response.getTokens().add(dummy);
    }

    for (Token token : response.getTokens()) {
        if (token.getStart() < startOffset) {
            continue;
        } else if (token.getStart() > endOffset) {
            break;
        }
        final String text = token.getText();
        IElementType tokenType = JSGraphQLCodeMirrorTokenMapper.getTokenType(token.getType());
        if (tokenType.equals(JSGraphQLTokenTypes.PUNCTUATION)) {
            final IElementType punctuationTokenType = getPunctuationTokenType(text);
            if (punctuationTokenType != null) {
                tokenType = punctuationTokenType;
            } else if (text.contains(",")) {
                // separate out commas from surrounding whitespace to support indentation on ", field" lines
                int offset = 0;
                final String[] parts = StringUtils.splitByCharacterType(text);
                for (String part : parts) {
                    final Token partSourceToken = token.withTextAndOffset(part, offset);
                    if (part.equals(",")) {
                        tokens.add(new JSGraphQLToken(tokenType, partSourceToken));
                    } else {
                        partSourceToken.setKind(JSGraphQLCodeMirrorTokenMapper.CODEMIRROR_WHITESPACE);
                        tokens.add(new JSGraphQLToken(JSGraphQLTokenTypes.WHITESPACE, partSourceToken));
                    }
                    offset += part.length();
                }
                continue; // already added the required tokens
            } else if (JSGraphQLKeywords.FRAGMENT_DOTS.equals(text)) {
                // consider the "..." spread operator a keyword for highlighting
                tokenType = JSGraphQLTokenTypes.KEYWORD;
            }
        } else if (tokenType.equals(JSGraphQLTokenTypes.INVALIDCHAR)) {
            // make sure we get the right tokenType for structural braces
            // to aid in brace matching and enter after unclosed opening brace
            IElementType punctuationTokenType = getPunctuationTokenType(text);
            if (punctuationTokenType != null) {
                tokenType = punctuationTokenType;
            }
        }
        tokens.add(new JSGraphQLToken(tokenType, token));
    }
    verifyTokens();
    if (tokens.size() > 0) {
        advance();
    }
}

From source file:org.projectforge.web.address.VCardItemElementHandler.java

public VCardItemElementHandler(final FileInputStream fis) {
    final DataInputStream in = new DataInputStream(fis);
    final BufferedReader br = new BufferedReader(new InputStreamReader(in));
    itemList = new ArrayList<Property>();

    //Read File Line By Line
    try {/*from   w  w w.  j a v a 2 s  .  c om*/
        String strLine;
        while ((strLine = br.readLine()) != null) {
            // looking for a item entry
            if (strLine.startsWith("item") && !strLine.contains("X-AB")) {

                // dissect the line by char
                final String str[] = StringUtils.splitByCharacterType(strLine);

                /*
                 * ignore "item" + "number" + "." (example: "item2.") cause is not needed.
                 * at index = 3 is the GroupId
                 */
                final int n = 3;

                // set Property.Id
                final Id id = getItemId(str[n]);

                final ArrayList<Parameter> param = new ArrayList<Parameter>();

                boolean startSignFound = false;

                String valueCache = "";
                for (int i = n; i < str.length; i++) {
                    // looking for parameters
                    if (str[i].equals("WORK") || str[i].equals("HOME")) {
                        param.add(getParameter(str[i]));
                    }

                    /*
                     * looking for start sign.
                     * usually ":" but sometimes addresses starts with ":;;"
                     */
                    if (str[i].equals(":;;") || str[i].equals(":") || str[i].equals(":;") && !startSignFound) {
                        startSignFound = true;
                    } else if (startSignFound) {
                        // terminate unwanted signs.
                        if (str[i].equals(";") || str[i].equals(";;") || str[i].equals(".;"))
                            valueCache = valueCache + ";";
                        else
                            valueCache = valueCache + str[i];
                    }
                }

                final String finalValue = valueCache;
                // set property with group at index = 3
                @SuppressWarnings("serial")
                final Property property = new Property(new Group(str[n]), id, param) {
                    @Override
                    public void validate() throws ValidationException {
                    }

                    @Override
                    public String getValue() {
                        return finalValue;
                    }
                };
                itemList.add(property);

            }
        }
        //      for (final Property p : itemList){
        //        System.out.println("propterty val: " + p.getValue() + " ;;; id: " + p.getId() + " ;;; parameter: " + p.getParameters(Parameter.Id.TYPE));
        //      }

        in.close();
    } catch (final IOException ex) {
        //      log.fatal("Exception encountered " + ex, ex);
    }
}