private static boolean containsValue(String expectedValue, List<String> actualValues) { final int numActualValues = actualValues.size(); for (int i = 0; i < numActualValues; i++) { if (Ascii.equalsIgnoreCase(expectedValue, actualValues.get(i))) { return true; } } return false; }
@Nullable static MediaType guessFromPath(String path, @Nullable String contentEncoding) { if (contentEncoding == null || Ascii.equalsIgnoreCase(contentEncoding, "identity")) { return guessFromPath(path); } requireNonNull(path, "path"); // If the path is for a precompressed file, it will have an additional extension indicating the // encoding, which we don't want to use when determining content type. return guessFromPath(path.substring(0, path.lastIndexOf('.'))); }
public void testEqualsIgnoreCase() { assertTrue(Ascii.equalsIgnoreCase("", "")); assertFalse(Ascii.equalsIgnoreCase("", "x")); assertFalse(Ascii.equalsIgnoreCase("x", "")); assertTrue(Ascii.equalsIgnoreCase(LOWER, UPPER)); assertTrue(Ascii.equalsIgnoreCase(UPPER, LOWER)); // Create new strings here to avoid early-out logic. assertTrue(Ascii.equalsIgnoreCase(new String(IGNORED), new String(IGNORED))); // Compare to: "\u00c1".equalsIgnoreCase("\u00e1") == true assertFalse(Ascii.equalsIgnoreCase("\u00c1", "\u00e1")); // Test chars just outside the alphabetic range ('A'-1 vs 'a'-1, 'Z'+1 vs 'z'+1) assertFalse(Ascii.equalsIgnoreCase("@", "`")); assertFalse(Ascii.equalsIgnoreCase("[", "{")); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { boolean handled = false; if (msg instanceof HttpResponse) { // The server rejected the upgrade request and sent its response in HTTP/1. assert upgradeEvt == UPGRADE_REJECTED; final String connection = ((HttpResponse) msg).headers().get(HttpHeaderNames.CONNECTION); needsToClose = connection != null && Ascii.equalsIgnoreCase("close", connection); handled = true; } if (msg instanceof HttpContent) { if (msg instanceof LastHttpContent) { // Received the rejecting response completely. onUpgradeResponse(ctx, false); } handled = true; } if (!handled) { ctx.fireChannelRead(msg); } else { ReferenceCountUtil.release(msg); } }
@Nullable @Override public MediaType contentType() { final String contentTypeString = get(HttpHeaderNames.CONTENT_TYPE); if (contentTypeString == null) { return null; } final MediaType contentType = this.contentType; if (contentType != null && Ascii.equalsIgnoreCase(contentType.toString(), contentTypeString.trim())) { return contentType; } try { this.contentType = MediaType.parse(contentTypeString); return this.contentType; } catch (IllegalArgumentException unused) { // Invalid media type return null; } }
@GwtIncompatible // String.toUpperCase() has browser semantics public void testEqualsIgnoreCaseUnicodeEquivalence() { // Note that it's possible in future that the JDK's idea to toUpperCase() or equalsIgnoreCase() // may change and break assumptions in this test [*]. This is not a bug in the implementation of // Ascii.equalsIgnoreCase(), but it is a signal that its documentation may need updating as // regards edge cases. // The Unicode point {@code 00df} is the lowercase form of sharp-S (ß), whose uppercase is "SS". assertEquals("PASSWORD", "pa\u00dfword".toUpperCase()); // [*] assertFalse("pa\u00dfword".equalsIgnoreCase("PASSWORD")); // [*] assertFalse(Ascii.equalsIgnoreCase("pa\u00dfword", "PASSWORD")); } }
private boolean handle100Continue(int id, HttpRequest nettyReq, HttpHeaders nettyHeaders) { if (nettyReq.protocolVersion().compareTo(HttpVersion.HTTP_1_1) < 0) { // Ignore HTTP/1.0 requests. return true; } final String expectValue = nettyHeaders.get(HttpHeaderNames.EXPECT); if (expectValue == null) { // No 'expect' header. return true; } // '100-continue' is the only allowed expectation. if (!Ascii.equalsIgnoreCase("100-continue", expectValue)) { return false; } // Send a '100 Continue' response. writer.writeHeaders(id, 1, CONTINUE_RESPONSE, false); // Remove the 'expect' header so that it's handled in a way invisible to a Service. nettyHeaders.remove(HttpHeaderNames.EXPECT); return true; }
/** * Test to see if this content type has the specified type and subtype. Comparison is case-insensitive. */ public boolean is(CharSequence type, CharSequence subtype) { return Ascii.equalsIgnoreCase(this.type, type) && Ascii.equalsIgnoreCase(this.subtype, subtype); }
@Override public String getHeader(String name) { if (equalsIgnoreCase(name, "content-length") || equalsIgnoreCase(name, "content-encoding")) { return null; } return request.getHeader(name); }
private void lookAhead() { do { if (!delegate.hasMoreElements()) { moreElementsState = MoreElementsState.NO; return; } nextElement = delegate.nextElement(); } while (equalsIgnoreCase(nextElement, "content-length") || equalsIgnoreCase(nextElement, "content-encoding")); moreElementsState = MoreElementsState.YES; } }
/** * Test to see if this content type has the specified suffix. */ public boolean hasSuffix(CharSequence suffix) { int pos = subtype.length() - suffix.length(); return pos > 0 && subtype.charAt(pos - 1) == '+' && Ascii.equalsIgnoreCase(subtype.subSequence(pos, subtype.length()), suffix); }
/** * Returns a UUID from a URI. */ public static UUID fromUri(URI uri) { checkArgument(Ascii.equalsIgnoreCase(uri.getScheme(), "urn"), "expected 'urn' scheme: %s", uri); String ssp = uri.getSchemeSpecificPart(); checkArgument(ssp != null && Ascii.equalsIgnoreCase(ssp.substring(0, 5), "uuid:"), "expected 'uuid' namespace: %s ", uri); return fromString(ssp.substring(5)); }
@JsonCreator public AccessToken(@JsonProperty("token_type") String tokenType, @JsonProperty("access_token") String accessToken, @JsonProperty("expires_in") long expiresIn, @JsonProperty("refresh_token") String refreshToken) { requireNonNull(tokenType, "tokenType"); checkArgument(Ascii.equalsIgnoreCase(tokenType, BEARER), "tokenType: %s (expected: %s)", tokenType, BEARER); this.accessToken = requireNonNull(accessToken, "accessToken"); this.expiresIn = expiresIn; this.refreshToken = requireNonNull(refreshToken, "refreshToken"); deadline = Instant.now().plus(expiresIn, ChronoUnit.SECONDS); }
@Override public int getIntHeader(String name) { if (equalsIgnoreCase(name, "content-length")) { return -1; } return request.getIntHeader(name); }
/** * Returns a UUID from a URI string representation. */ public static UUID fromUriString(CharSequence uri) { checkArgument(uri.length() == 45, "UUID URN should be exactly 45 characters (was %s): %s", uri.length(), uri); checkArgument(Ascii.equalsIgnoreCase("urn:uuid:", uri.subSequence(0, 9)), "expected UUID URN scheme: %s", uri); return fromString(uri.subSequence(9, 45)); }
/** * Returns {@code true} if the attribute name is static and matches the given name (ignoring * case). */ public boolean definitelyMatchesAttributeName(String attributeName) { return getChild(0) instanceof RawTextNode && Ascii.equalsIgnoreCase(attributeName, ((RawTextNode) getChild(0)).getRawText()); }
/** * Returns {@code true} if the attribute name is static and matches the given name (ignoring * case). */ public boolean definitelyMatchesAttributeName(String attributeName) { return getChild(0) instanceof RawTextNode && Ascii.equalsIgnoreCase(attributeName, ((RawTextNode) getChild(0)).getRawText()); }
@Benchmark boolean equalsIgnoreCaseStringOnly(int reps) { // This benchmark has no concept of "noWorkToDo". String lhs = testString; String rhs = testString.toUpperCase(); boolean dummy = false; for (int i = 0; i < reps; i++) { dummy ^= Ascii.equalsIgnoreCase(lhs, rhs); } return dummy; }
public void testEqualsIgnoreCase() { assertTrue(Ascii.equalsIgnoreCase("", "")); assertFalse(Ascii.equalsIgnoreCase("", "x")); assertFalse(Ascii.equalsIgnoreCase("x", "")); assertTrue(Ascii.equalsIgnoreCase(LOWER, UPPER)); assertTrue(Ascii.equalsIgnoreCase(UPPER, LOWER)); // Create new strings here to avoid early-out logic. assertTrue(Ascii.equalsIgnoreCase(new String(IGNORED), new String(IGNORED))); // Compare to: "\u00c1".equalsIgnoreCase("\u00e1") == true assertFalse(Ascii.equalsIgnoreCase("\u00c1", "\u00e1")); // Test chars just outside the alphabetic range ('A'-1 vs 'a'-1, 'Z'+1 vs 'z'+1) assertFalse(Ascii.equalsIgnoreCase("@", "`")); assertFalse(Ascii.equalsIgnoreCase("[", "{")); }
@GwtIncompatible // String.toUpperCase() has browser semantics public void testEqualsIgnoreCaseUnicodeEquivalence() { // Note that it's possible in future that the JDK's idea to toUpperCase() or equalsIgnoreCase() // may change and break assumptions in this test [*]. This is not a bug in the implementation of // Ascii.equalsIgnoreCase(), but it is a signal that its documentation may need updating as // regards edge cases. // The Unicode point {@code 00df} is the lowercase form of sharp-S (ß), whose uppercase is "SS". assertEquals("PASSWORD", "pa\u00dfword".toUpperCase()); // [*] assertFalse("pa\u00dfword".equalsIgnoreCase("PASSWORD")); // [*] assertFalse(Ascii.equalsIgnoreCase("pa\u00dfword", "PASSWORD")); } }