Example usage for java.lang CharSequence subSequence

List of usage examples for java.lang CharSequence subSequence

Introduction

In this page you can find the example usage for java.lang CharSequence subSequence.

Prototype

CharSequence subSequence(int start, int end);

Source Link

Document

Returns a CharSequence that is a subsequence of this sequence.

Usage

From source file:StringUtils.java

/**
 * @param stripChars if null, remove leading unicode whitespaces.
 *///from   ww w  .  j  a v  a2s .c om
public static CharSequence stripEnd(CharSequence src, String stripChars) {
    int end;
    if (src == null || (end = src.length()) == 0) {
        return src;
    }
    if (stripChars == null) {
        while ((end != 0) && Character.isWhitespace(src.charAt(end - 1))) {
            end--;
        }
    } else if (stripChars.length() == 0) {
        return src;
    } else {
        while ((end != 0) && (stripChars.indexOf(src.charAt(end - 1)) != -1)) {
            end--;
        }
    }
    return src.subSequence(0, end);
}

From source file:com.sillelien.dollar.script.DollarLexer.java

public static Parser<?> builtin() {
    return Scanners.pattern(new Pattern() {
        @Override//from   w  ww.j  a  v  a2s.com
        public int match(@NotNull CharSequence src, int begin, int end) {
            int i = begin;
            //noinspection StatementWithEmptyBody
            for (; i < end && Character.isAlphabetic(src.charAt(i)); i++) {
                //
            }
            final String name = src.subSequence(begin, i).toString();
            if (Builtins.exists(name)) {
                return i - begin;
            } else {
                return Pattern.MISMATCH;
            }
        }
    }, "builtin").source().map(new Map<String, Tokens.Fragment>() {
        public Tokens.Fragment map(String text) {
            return Tokens.fragment(text, "builtin");
        }

        @NotNull
        @Override
        public String toString() {
            return "builtin";
        }
    });
}

From source file:com.googlecode.eyesfree.brailleback.DisplaySpans.java

/**
 * Utility function to log what accessibiility nodes are attached
 * to what parts of the character sequence.
 *//*from  w ww.  j  ava  2s .  c o m*/
public static void logNodes(CharSequence chars) {
    if (!(chars instanceof Spanned)) {
        LogUtils.log(DisplaySpans.class, Log.VERBOSE, "Not a Spanned");
        return;
    }
    Spanned spanned = (Spanned) chars;
    AccessibilityNodeInfoCompat spans[] = spanned.getSpans(0, spanned.length(),
            AccessibilityNodeInfoCompat.class);
    for (AccessibilityNodeInfoCompat node : spans) {
        LogUtils.log(DisplaySpans.class, Log.VERBOSE,
                chars.subSequence(spanned.getSpanStart(node), spanned.getSpanEnd(node)).toString());
        LogUtils.log(DisplaySpans.class, Log.VERBOSE, node.getInfo().toString());
    }
}

From source file:dollar.internal.runtime.script.parser.DollarLexer.java

private static Parser<?> builtin() {
    //noinspection OverlyComplexAnonymousInnerClass
    return new Pattern() {
        @Override/*from   w  ww  . jav a 2 s .  c om*/
        public int match(@NotNull CharSequence src, int begin, int end) {
            int i = begin;
            //noinspection StatementWithEmptyBody
            while ((i < end) && isAlphabetic(src.charAt(i)))
                i++;
            final String name = src.subSequence(begin, i).toString();
            return exists(name) ? (i - begin) : Pattern.MISMATCH;
        }
    }.toScanner("builtin").source().map(new Function<String, Tokens.Fragment>() {
        @Override
        @NotNull
        public Tokens.Fragment apply(@NotNull String text) {
            return fragment(text, "builtin");
        }

        @NotNull
        @Override
        public String toString() {
            return "builtin";
        }
    });
}

From source file:org.minig.imap.EncodedWord.java

/**
 * Decodes a string that contains EncodedWords.
 * /*w  w w.  ja  v  a 2s .c  om*/
 * @param input
 *            a string containing EncodedWords
 * @return the decoded string
 */
public static StringBuilder decode(CharSequence input) {
    StringBuilder result = new StringBuilder(input.length());
    int lastMatchEnd = 0;
    Matcher matcher = encodedWordPattern.matcher(input);
    Charset charset;
    char type;
    String encodedPart;

    while (matcher.find()) {
        CharSequence inbetween = input.subSequence(lastMatchEnd, matcher.start());
        if (!spacePattern.matcher(inbetween).matches()) {
            result.append(inbetween);
        }

        try {
            charset = Charset.forName(matcher.group(1));
        } catch (Throwable e) {
            charset = Charset.forName("utf-8");
        }
        type = matcher.group(2).toLowerCase().charAt(0);
        encodedPart = matcher.group(3);

        if (type == 'q') {
            encodedPart = encodedPart.replace('_', ' ');
            // _ are WS and must be converted before normal decoding
            result.append(QuotedPrintable.decode(encodedPart, charset));
        } else {
            result.append(charset.decode(ByteBuffer.wrap(Base64.decodeBase64(encodedPart))));
        }

        lastMatchEnd = matcher.end();
    }

    result.append(input.subSequence(lastMatchEnd, input.length()));

    return result;
}

From source file:org.gradle.util.GUtil.java

/**
 * Converts an arbitrary string to a camel-case string which can be used in a Java identifier. Eg, with_underscores -> withUnderscores
 */// w  ww . j  av  a 2 s .  c om
public static String toCamelCase(CharSequence string) {
    if (string == null) {
        return null;
    }
    StringBuilder builder = new StringBuilder();
    Matcher matcher = WORD_SEPARATOR.matcher(string);
    int pos = 0;
    while (matcher.find()) {
        builder.append(StringUtils.capitalize(string.subSequence(pos, matcher.start()).toString()));
        pos = matcher.end();
    }
    builder.append(StringUtils.capitalize(string.subSequence(pos, string.length()).toString()));
    return builder.toString();
}

From source file:StringUtils.java

/**
 * @param stripChars if null, remove leading unicode whitespaces.
 *///from  www  .j a va 2  s .c om
public static CharSequence stripStart(CharSequence src, String stripChars) {
    int srclen;
    if (src == null || (srclen = src.length()) == 0) {
        return src;
    }
    int start = 0;
    if (stripChars == null) {
        while ((start != srclen) && Character.isWhitespace(src.charAt(start))) {
            start++;
        }
    } else if (stripChars.length() == 0) {
        return src;
    } else {
        while ((start != srclen) && (stripChars.indexOf(src.charAt(start)) != -1)) {
            start++;
        }
    }
    return src.subSequence(start, srclen);
}

From source file:org.artifactory.util.PathUtils.java

public static CharSequence trimTrailingSlashesChars(CharSequence path) {
    if (path == null) {
        return null;
    }//from  www .ja  va  2s  .  co m
    if (path.length() > 0 && path.charAt(path.length() - 1) == '/') {
        path = path.subSequence(0, path.length() - 1);
        return trimTrailingSlashes(path);
    }
    return path;
}

From source file:org.apache.bval.jsr.util.PathNavigation.java

private static String parseProperty(CharSequence path, PathPosition pos) throws Exception {
    int len = path.length();
    int start = pos.getIndex();
    loop: while (pos.getIndex() < len) {
        switch (path.charAt(pos.getIndex())) {
        case '[':
        case ']':
        case '.':
            break loop;
        }//w w w .ja  v a2s  .c om
        pos.next();
    }
    if (pos.getIndex() > start) {
        return path.subSequence(start, pos.getIndex()).toString();
    }
    throw new IllegalStateException(String.format("Position %s: expected property", start));
}

From source file:org.artifactory.util.PathUtils.java

public static CharSequence trimLeadingSlashChars(CharSequence path) {
    if (path == null) {
        return null;
    }//  ww w . j a va  2  s . c om
    //Trim leading '/' (caused by webdav requests)
    if (path.length() > 0 && path.charAt(0) == '/') {
        path = path.subSequence(1, path.length());
        return trimLeadingSlashChars(path);
    }
    return path;
}