Example usage for java.lang String regionMatches

List of usage examples for java.lang String regionMatches

Introduction

In this page you can find the example usage for java.lang String regionMatches.

Prototype

public boolean regionMatches(boolean ignoreCase, int toffset, String other, int ooffset, int len) 

Source Link

Document

Tests if two string regions are equal.

Usage

From source file:org.yccheok.jstock.gui.UtilsRef.java

public static boolean isWindows() {
    String windowsString = "Windows";
    String osName = System.getProperty("os.name");

    if (osName == null)
        return false;

    return osName.regionMatches(true, 0, windowsString, 0, windowsString.length());
}

From source file:org.nuclos.common2.StringUtils.java

/**
 * Concatenate strings to one html string that starts with <code>&lt;html&gt;&lt;body&gt;</code>
 * and ends with <code>&lt;/html&gt;&lt;/body&gt;</code>. The parts will be separated by <code>&lt;br/&gt;</code>.
 * If a part is itself a html string (recognized if it starts with <code>&lt;html&gt;</code>), the start and end tags will be removed prior to concatenation.
 *
 * @param parts//from   ww w  .java 2s.c o m
 * @return
 */
public static String concatHtml(String... parts) {
    StringBuilder result = new StringBuilder();
    result.append("<html><body>");
    int i = 0;
    for (String part : parts) {
        if (StringUtils.isNullOrEmpty(part)) {
            continue;
        }
        if (i > 0) {
            result.append("<br/>");
        }
        if (part.regionMatches(true, 0, "<html>", 0, "<html>".length())) {
            result.append(part.replaceAll("\\<\\/?(?i:html)\\>", "").replaceAll("\\<\\/?(?i:body)\\>", ""));
        } else {
            result.append(StringEscapeUtils.escapeHtml(part));
        }
        i++;
    }
    return result.append("</body></html>").toString();
}

From source file:org.moyrax.javascript.shell.Global.java

private static String getCharCodingFromType(String type) {
    int i = type.indexOf(';');
    if (i >= 0) {
        int end = type.length();
        ++i;//from  w  ww.ja v  a 2s. co m
        while (i != end && type.charAt(i) <= ' ') {
            ++i;
        }
        String charset = "charset";
        if (charset.regionMatches(true, 0, type, i, charset.length())) {
            i += charset.length();
            while (i != end && type.charAt(i) <= ' ') {
                ++i;
            }
            if (i != end && type.charAt(i) == '=') {
                ++i;
                while (i != end && type.charAt(i) <= ' ') {
                    ++i;
                }
                if (i != end) {
                    // i is at the start of non-empty
                    // charCoding spec
                    while (type.charAt(end - 1) <= ' ') {
                        --end;
                    }
                    return type.substring(i, end);
                }
            }
        }
    }
    return null;
}

From source file:com.caved_in.commons.utilities.StringUtil.java

/**
 * This method uses a region to check case-insensitive equality. This
 * means the internal array does not need to be copied like a
 * toLowerCase() call would./*w w w  .j a  v  a  2  s. c o  m*/
 *
 * @param string String to check
 * @param prefix Prefix of string to compare
 * @return true if provided string starts with, ignoring case, the prefix
 * provided
 * @throws NullPointerException     if prefix is null
 * @throws IllegalArgumentException if string is null
 */
public static boolean startsWithIgnoreCase(final String string, final String prefix)
        throws IllegalArgumentException, NullPointerException {
    Validate.notNull(string, "Cannot check a null string for a match");
    if (string.length() < prefix.length()) {
        return false;
    }
    return string.regionMatches(true, 0, prefix, 0, prefix.length());
}

From source file:org.apache.maven.doxia.siterenderer.DefaultSiteRenderer.java

static boolean endsWithIgnoreCase(String str, String searchStr) {
    if (str.length() < searchStr.length()) {
        return false;
    }//from  w ww .java 2  s.  com

    return str.regionMatches(true, str.length() - searchStr.length(), searchStr, 0, searchStr.length());
}

From source file:MSBodyPart.java

/**
 * Process the "begin" line to extract the filename,
 * and from it determine the Content-Type.
 *///from   ww w . ja  va2 s  .  co m
private void processBegin() {
    InputStream in = getContentStream();
    try {
        BufferedReader r = new BufferedReader(new InputStreamReader(in));
        String begin = r.readLine();
        // format is "begin 666 filename.txt"
        if (begin != null && begin.regionMatches(true, 0, "begin ", 0, 6)) {
            int i = begin.indexOf(' ', 6);
            if (i > 0) {
                filename = begin.substring(i + 1);
                FileTypeMap map = FileTypeMap.getDefaultFileTypeMap();
                type = map.getContentType(filename);
                if (type == null)
                    type = "application/octet-stream";
            }
        }
    } catch (IOException ex) {
        // ignore
    } finally {
        try {
            in.close();
        } catch (IOException ex) {
            // ignore it
        }
        if (filename == UNKNOWN)
            filename = null;
        if (type == UNKNOWN || type == null)
            type = "text/plain";
    }
}

From source file:com.hs.mail.security.login.PropertiesLoginModule.java

private String getLine(File file, String start) throws LoginException {
    LineReader reader = null;/*from  w  ww .j a  v a  2 s  . c  o  m*/
    BufferedInputStream is = null;
    try {
        is = new BufferedInputStream(new FileInputStream(file));
        reader = new LineReader(is);
        int len = start.length();
        String line = null;
        while ((line = reader.readLine()) != null) {
            line = line.trim();
            if (!line.startsWith("#") && line.regionMatches(false, 0, start, 0, len)) {
                return line;
            }
        }
        return null;
    } catch (IOException e) {
        throw new LoginException("Error while reading file: " + file);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(reader);
    }
}

From source file:fr.aliacom.obm.ldap.PasswordHandler.java

public synchronized boolean verify(String digest, String password) throws NoSuchAlgorithmException {

    String alg = null;/*from   w  ww.ja va 2  s . c  o  m*/
    int size = 0;

    if (digest.regionMatches(true, 0, "{CRYPT}", 0, 7)) {
        digest = digest.substring(7);
        return UnixCrypt.matches(digest, password);
    } else if (digest.regionMatches(true, 0, "{SHA}", 0, 5)) {
        digest = digest.substring(5); // ignore the label
        alg = "SHA-1";
        size = 20;
    } else if (digest.regionMatches(true, 0, "{SSHA}", 0, 6)) {
        digest = digest.substring(6); // ignore the label
        alg = "SHA-1";
        size = 20;
    } else if (digest.regionMatches(true, 0, "{MD5}", 0, 5)) {
        digest = digest.substring(5); // ignore the label
        alg = "MD5";
        size = 16;
    } else if (digest.regionMatches(true, 0, "{SMD5}", 0, 6)) {
        digest = digest.substring(6); // ignore the label
        alg = "MD5";
        size = 16;
    }

    // TODO: vrifier si le synchronized que j'ai ajout est ncessaire
    MessageDigest msgDigest = MessageDigest.getInstance(alg);

    byte[][] hs = split(Base64.decodeBase64(digest), size);
    byte[] hash = hs[0];
    byte[] salt = hs[1];

    msgDigest.reset();
    msgDigest.update(password.getBytes(Charsets.UTF_8));
    msgDigest.update(salt);

    byte[] pwhash = msgDigest.digest();

    return MessageDigest.isEqual(hash, pwhash);
}

From source file:com.stratuscom.harvester.codebase.ClassServer.java

/**
 * Canonicalize the path//from   w  ww  .ja  v a 2 s.  c o m
 */
private String canon(String path) {
    if (path.regionMatches(true, 0, "http://", 0, 7)) {
        int i = path.indexOf('/', 7);
        if (i < 0) {
            path = "/";
        } else {
            path = path.substring(i);
        }
    }
    path = decode(path);
    if (path == null || path.length() == 0 || path.charAt(0) != '/') {
        return null;
    }
    return path.substring(1);
}

From source file:pcgen.io.exporttoken.SkillToken.java

/**
 * Convert a property name into the id of the property.
 *
 * @param property The property name.//from   w  ww. j av a  2 s.  c  om
 * @return The id of the property.
 */
public static int getPropertyId(String property) {
    int propId = 0;

    if ("NAME".equalsIgnoreCase(property)) {
        propId = SKILL_NAME;
    } else if ("TOTAL".equalsIgnoreCase(property)) {
        propId = SKILL_TOTAL;
    } else if ("RANK".equalsIgnoreCase(property)) {
        propId = SKILL_RANK;
    } else if ("MOD".equalsIgnoreCase(property)) {
        propId = SKILL_MOD;
    } else if ("ABILITY".equalsIgnoreCase(property)) {
        propId = SKILL_ABILITY;
    } else if ("ABMOD".equalsIgnoreCase(property)) {
        propId = SKILL_ABMOD;
    } else if ("MISC".equalsIgnoreCase(property)) {
        propId = SKILL_MISC;
    } else if ("COST".equalsIgnoreCase(property)) {
        propId = SKILL_COST;
    } else if ("UNTRAINED".equalsIgnoreCase(property)) {
        propId = SKILL_UNTRAINED;
    } else if ("EXCLUSIVE".equalsIgnoreCase(property)) {
        propId = SKILL_EXCLUSIVE;
    } else if (property.regionMatches(true, 0, "UNTRAINED", 0, 9)) {
        propId = SKILL_UNTRAINED_EXTENDED;
    } else if (property.regionMatches(true, 0, "ACP", 0, 3)) {
        propId = SKILL_ACP;
    } else if ("EXCLUSIVE_TOTAL".equalsIgnoreCase(property)) {
        propId = SKILL_EXCLUSIVE_TOTAL;
    } else if ("TRAINED_TOTAL".equalsIgnoreCase(property)) {
        propId = SKILL_TRAINED_TOTAL;
    } else if (property.regionMatches(true, 0, "EXPLAIN", 0, 7)) {
        propId = SKILL_EXPLANATION;
    } else if ("TYPE".equalsIgnoreCase(property)) {
        propId = SKILL_TYPE;
    } else if ("SIZE".equalsIgnoreCase(property)) {
        propId = SKILL_SIZE;
    } else if ("CLASSES".equalsIgnoreCase(property)) {
        propId = SKILL_CLASSES;
    }
    return propId;
}