/** * Checks if two strings have the same suffix of specified length * * @param s string * @param p string * @param len length of the common suffix * @return true if both s and p are not null and both have the same suffix. Otherwise - false */ public static boolean commonSuffixOfLength(String s, String p, int len) { return s != null && p != null && len >= 0 && s.regionMatches(s.length() - len, p, p.length() - len, len); }
/** * Checks if one string starts with another using the case-sensitivity rule. * <p> * This method mimics {@link String#startsWith(String)} but takes case-sensitivity * into account. * * @param str the string to check, not null * @param start the start to compare against, not null * @return true if equal using the case rules * @throws NullPointerException if either string is null */ public boolean checkStartsWith(final String str, final String start) { return str.regionMatches(!sensitive, 0, start, 0, start.length()); }
/** * Test if the given {@code String} starts with the specified prefix, * ignoring upper/lower case. * @param str the {@code String} to check * @param prefix the prefix to look for * @see java.lang.String#startsWith */ public static boolean startsWithIgnoreCase(@Nullable String str, @Nullable String prefix) { return (str != null && prefix != null && str.length() >= prefix.length() && str.regionMatches(true, 0, prefix, 0, prefix.length())); }
boolean matches(String hostname) { if (pattern.startsWith(WILDCARD)) { int firstDot = hostname.indexOf('.'); return (hostname.length() - firstDot - 1) == canonicalHostname.length() && hostname.regionMatches(false, firstDot + 1, canonicalHostname, 0, canonicalHostname.length()); } return hostname.equals(canonicalHostname); }
/** * Checks if one string contains another at a specific index using the case-sensitivity rule. * <p> * This method mimics parts of {@link String#regionMatches(boolean, int, String, int, int)} * but takes case-sensitivity into account. * * @param str the string to check, not null * @param strStartIndex the index to start at in str * @param search the start to search for, not null * @return true if equal using the case rules * @throws NullPointerException if either string is null */ public boolean checkRegionMatches(final String str, final int strStartIndex, final String search) { return str.regionMatches(!sensitive, strStartIndex, search, 0, search.length()); }
/** * Test if the given {@code String} ends with the specified suffix, * ignoring upper/lower case. * @param str the {@code String} to check * @param suffix the suffix to look for * @see java.lang.String#endsWith */ public static boolean endsWithIgnoreCase(@Nullable String str, @Nullable String suffix) { return (str != null && suffix != null && str.length() >= suffix.length() && str.regionMatches(true, str.length() - suffix.length(), suffix, 0, suffix.length())); }
/** Returns true if {@code string.substring(offset).startsWith(substring)}. */ private static boolean substringStartsWith(String string, int offset, String substring) { return string.regionMatches(offset, substring, 0, substring.length()); }
public int parseInto( ReadWritablePeriod period, String periodStr, int position, Locale locale) { if (periodStr.regionMatches(true, position, iText, 0, iText.length())) { return position + iText.length(); } return ~position; } }
/** * Checks if one string ends with another using the case-sensitivity rule. * <p> * This method mimics {@link String#endsWith} but takes case-sensitivity * into account. * * @param str the string to check, not null * @param end the end to compare against, not null * @return true if equal using the case rules * @throws NullPointerException if either string is null */ public boolean checkEndsWith(final String str, final String end) { final int endLen = end.length(); return str.regionMatches(!sensitive, str.length() - endLen, end, 0, endLen); }
/** * Sets the URL target of this request. * * @throws IllegalArgumentException if {@code url} is not a valid HTTP or HTTPS URL. Avoid this * exception by calling {@link HttpUrl#parse}; it returns null for invalid URLs. */ public Builder url(String url) { if (url == null) throw new NullPointerException("url == null"); // Silently replace web socket URLs with HTTP URLs. if (url.regionMatches(true, 0, "ws:", 0, 3)) { url = "http:" + url.substring(3); } else if (url.regionMatches(true, 0, "wss:", 0, 4)) { url = "https:" + url.substring(4); } return url(HttpUrl.get(url)); }
/** * Checks if two strings have the same suffix of specified length * * @param s string * @param p string * @param len length of the common suffix * @return true if both s and p are not null and both have the same suffix. Otherwise - false */ public static boolean commonSuffixOfLength(String s, String p, int len) { return s != null && p != null && len >= 0 && s.regionMatches(s.length() - len, p, p.length() - len, len); }
/** * Simple function to match <a href="http://en.wikipedia.org/wiki/Wildcard_DNS_record">DNS wildcard</a>. */ static boolean matches(String template, String hostName) { if (template.startsWith("*.")) { return template.regionMatches(2, hostName, 0, hostName.length()) || commonSuffixOfLength(hostName, template, template.length() - 1); } return template.equals(hostName); }
boolean matches(String hostname) { if (pattern.startsWith(WILDCARD)) { int firstDot = hostname.indexOf('.'); return (hostname.length() - firstDot - 1) == canonicalHostname.length() && hostname.regionMatches(false, firstDot + 1, canonicalHostname, 0, canonicalHostname.length()); } return hostname.equals(canonicalHostname); }
@Override boolean invoke() { return data.source.regionMatches(data.ignoreCase, data.toffset, data.other, data.ooffset, data.len); } }.run(data, "String");
public int parse(String periodStr, int position) { for (String text : iSuffixesSortedDescByLength) { if (periodStr.regionMatches(true, position, text, 0, text.length())) { if (!matchesOtherAffix(text.length(), periodStr, position)) { return position + text.length(); } } } return ~position; }
public int parse(String periodStr, int position) { String text = iText; int textLength = text.length(); if (periodStr.regionMatches(true, position, text, 0, textLength)) { if (!matchesOtherAffix(textLength, periodStr, position)) { return position + textLength; } } return ~position; }
/** * Simple function to match <a href="http://en.wikipedia.org/wiki/Wildcard_DNS_record">DNS wildcard</a>. */ static boolean matches(String template, String hostName) { if (template.startsWith("*.")) { return template.regionMatches(2, hostName, 0, hostName.length()) || commonSuffixOfLength(hostName, template, template.length() - 1); } return template.equals(hostName); }
public int scan(String periodStr, final int position) { int sourceLength = periodStr.length(); for (int pos = position; pos < sourceLength; pos++) { for (String text : iSuffixesSortedDescByLength) { if (periodStr.regionMatches(true, pos, text, 0, text.length())) { if (!matchesOtherAffix(text.length(), periodStr, pos)) { return pos; } } } } return ~position; }
/** * Check whether the given FieldError matches the given field. * @param field the field that we are looking up FieldErrors for * @param fieldError the candidate FieldError * @return whether the FieldError matches the given field */ protected boolean isMatchingFieldError(String field, FieldError fieldError) { if (field.equals(fieldError.getField())) { return true; } // Optimization: use charAt and regionMatches instead of endsWith and startsWith (SPR-11304) int endIndex = field.length() - 1; return (endIndex >= 0 && field.charAt(endIndex) == '*' && (endIndex == 0 || field.regionMatches(0, fieldError.getField(), 0, endIndex))); }
public int parse(String periodStr, int position) { for (String text : iSuffixesSortedDescByLength) { if (periodStr.regionMatches(true, position, text, 0, text.length())) { if (!matchesOtherAffix(text.length(), periodStr, position)) { return position + text.length(); } } } return ~position; }