Example usage for com.google.common.base CharMatcher indexIn

List of usage examples for com.google.common.base CharMatcher indexIn

Introduction

In this page you can find the example usage for com.google.common.base CharMatcher indexIn.

Prototype

public int indexIn(CharSequence sequence) 

Source Link

Document

Returns the index of the first matching character in a character sequence, or -1 if no matching character is present.

Usage

From source file:org.opendaylight.restconf.parser.builder.YangInstanceIdentifierDeserializer.java

private static String findAndParsePercentEncoded(final String preparedPrefix) {
    if (!preparedPrefix.contains(String.valueOf(ParserBuilderConstants.Deserializer.PERCENT_ENCODING))) {
        return preparedPrefix;
    }/*from   ww w. jav a  2 s.c  om*/

    final StringBuilder parsedPrefix = new StringBuilder(preparedPrefix);
    final CharMatcher matcher = CharMatcher.is(ParserBuilderConstants.Deserializer.PERCENT_ENCODING);

    while (matcher.matchesAnyOf(parsedPrefix)) {
        final int percentCharPosition = matcher.indexIn(parsedPrefix);
        parsedPrefix
                .replace(percentCharPosition,
                        percentCharPosition + ParserBuilderConstants.Deserializer.LAST_ENCODED_CHAR,
                        String.valueOf((char) Integer.parseInt(parsedPrefix.substring(
                                percentCharPosition + ParserBuilderConstants.Deserializer.FIRST_ENCODED_CHAR,
                                percentCharPosition + ParserBuilderConstants.Deserializer.LAST_ENCODED_CHAR),
                                ParserBuilderConstants.Deserializer.PERCENT_ENCODED_RADIX)));
    }

    return parsedPrefix.toString();
}