Java String Starts Wtih startsWithIgnoreCase(String s, int offset, int end, String lowerCase)

Here you can find the source of startsWithIgnoreCase(String s, int offset, int end, String lowerCase)

Description

True if the lower-case version of s[off:end] starts with the given lower-case string.

License

Apache License

Declaration

static boolean startsWithIgnoreCase(String s, int offset, int end, String lowerCase) 

Method Source Code

//package com.java2s;
// Licensed under the Apache License, Version 2.0 (the "License");

public class Main {
    /**//from   w ww.  j  a  v a2  s .  com
     * True if the lower-case version of s[off:end] starts with the given
     * lower-case string.
     */
    static boolean startsWithIgnoreCase(String s, int offset, int end, String lowerCase) {
        int n = lowerCase.length();
        if (end - offset < n) {
            return false;
        }
        int off = offset;
        for (int i = 0; i < n; ++off, ++i) {
            if (lcase(s.charAt(off)) != lowerCase.charAt(i)) {
                return false;
            }
        }
        return true;
    }

    /**
     * True if the lower-case version of s[off:end] starts with the given
     * lower-case string.
     */
    static boolean startsWithIgnoreCase(char[] s, int offset, int end, String lowerCase) {
        int n = lowerCase.length();
        if (end - offset < n) {
            return false;
        }
        int off = offset;
        for (int i = 0; i < n; ++off, ++i) {
            if (lcase(s[off]) != lowerCase.charAt(i)) {
                return false;
            }
        }
        return true;
    }

    /** Returns ch or the lower-case equivalent if ch is in ['A'..'Z']. */
    static char lcase(char ch) {
        return 'A' <= ch && ch <= 'Z' ? (char) (ch | 32) : ch;
    }

    static char charAt(char[] s, int i) {
        return s[i];
    }
}

Related

  1. startsWithIgnoreCase(String inputValue, String prefix)
  2. startsWithIgnoreCase(String main, String with)
  3. startsWithIgnoreCase(String name, Iterable patterns)
  4. startsWithIgnoreCase(String originalString, String checkPhrase)
  5. startsWithIgnoreCase(String p_sStr, String p_sSubStr)
  6. startsWithIgnoreCase(String s, String prefix)
  7. startsWithIgnoreCase(String s, String prefix)
  8. startsWithIgnoreCase(String s, String prefix)
  9. startsWithIgnoreCase(String s, String start)