@Override public String detect(String identifier) { if (identifier.length() <= lengthsOfPrefixAndSuffix) { return NOT_DETECTED; } boolean prefixMatches = prefix.isEmpty() || (identifier.startsWith(prefix) && Ascii.isUpperCase(identifier.charAt(prefix.length()))); boolean suffixMatches = suffix.isEmpty() || identifier.endsWith(suffix); if (prefixMatches && suffixMatches) { String detected = identifier.substring(prefix.length(), identifier.length() - suffix.length()); return prefix.isEmpty() ? detected : CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, detected); } return NOT_DETECTED; }
private static boolean shouldDisableFor(Reporter reporter, Element element) { while (element != null) { if (element.getKind() == ElementKind.PACKAGE) { for (String segment : DOT_SPLITTER.split(((PackageElement) element).getQualifiedName())) { if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) { reporter.warning(WARNING_START + " uppercase package names"); return true; } } } if (element.getKind().isClass() || element.getKind().isInterface()) { if (Ascii.isLowerCase(element.getSimpleName().charAt(0))) { reporter.warning(WARNING_START + " lowercase class names"); return true; } } element = element.getEnclosingElement(); } return false; }
/** * Returns a string representation for this MapMaker instance. The exact form of the returned * string is not specified. */ @Override public String toString() { MoreObjects.ToStringHelper s = MoreObjects.toStringHelper(this); if (initialCapacity != UNSET_INT) { s.add("initialCapacity", initialCapacity); } if (concurrencyLevel != UNSET_INT) { s.add("concurrencyLevel", concurrencyLevel); } if (keyStrength != null) { s.add("keyStrength", Ascii.toLowerCase(keyStrength.toString())); } if (valueStrength != null) { s.add("valueStrength", Ascii.toLowerCase(valueStrength.toString())); } if (keyEquivalence != null) { s.addValue("keyEquivalence"); } return s.toString(); }
/** * Constructor used to implement {@link #from(String)}, and from subclasses. */ InternetDomainName(String name) { // Normalize: // * ASCII characters to lowercase // * All dot-like characters to '.' // * Strip trailing '.' name = Ascii.toLowerCase(DOTS_MATCHER.replaceFrom(name, '.')); if (name.endsWith(".")) { name = name.substring(0, name.length() - 1); } checkArgument(name.length() <= MAX_LENGTH, "Domain name too long: '%s':", name); this.name = name; this.parts = ImmutableList.copyOf(DOT_SPLITTER.split(name)); checkArgument(parts.size() <= MAX_PARTS, "Domain has too many parts: '%s'", name); checkArgument(validateSyntax(parts), "Not a valid domain name: '%s'", name); this.publicSuffixIndex = findPublicSuffix(); }
public void testToString() { for (String inputName : SOMEWHERE_UNDER_PS) { InternetDomainName domain = InternetDomainName.from(inputName); /* * We would ordinarily use constants for the expected results, but * doing it by derivation allows us to reuse the test case definitions * used in other tests. */ String expectedName = Ascii.toLowerCase(inputName); expectedName = expectedName.replaceAll("[\u3002\uFF0E\uFF61]", "."); if (expectedName.endsWith(".")) { expectedName = expectedName.substring(0, expectedName.length() - 1); } assertEquals(expectedName, domain.toString()); } }
/** * True when s ends with suffix in a way that suffix is not part of a larger * word by camel-casing or underscore naming conventions. */ public static boolean endsWithWordOrIs(String s, String suffix) { if (suffix.isEmpty()) { return true; } String lc = Ascii.toLowerCase(s); if (lc.endsWith(suffix)) { int beforeSuffix = lc.length() - suffix.length() - 1; if (beforeSuffix < 0) { return true; } if (!Character.isLetterOrDigit(lc.charAt(beforeSuffix))) { return true; } if (Ascii.isLowerCase(s.charAt(beforeSuffix)) && Ascii.isUpperCase(s.charAt(beforeSuffix + 1))) { return true; } } return false; }
/** * Returns a string representation for this MapMaker instance. The exact form of the returned * string is not specificed. */ @Override public String toString() { MoreObjects.ToStringHelper s = MoreObjects.toStringHelper(this); if (initialCapacity != UNSET_INT) { s.add("initialCapacity", initialCapacity); } if (concurrencyLevel != UNSET_INT) { s.add("concurrencyLevel", concurrencyLevel); } if (keyStrength != null) { s.add("keyStrength", Ascii.toLowerCase(keyStrength.toString())); } if (valueStrength != null) { s.add("valueStrength", Ascii.toLowerCase(valueStrength.toString())); } if (keyEquivalence != null) { s.addValue("keyEquivalence"); } return s.toString(); }
private static int millisPerUnit(String unit) { switch (Ascii.toLowerCase(unit)) { case "d": return DateTimeConstants.MILLIS_PER_DAY; case "h": return DateTimeConstants.MILLIS_PER_HOUR; case "m": return DateTimeConstants.MILLIS_PER_MINUTE; case "s": return DateTimeConstants.MILLIS_PER_SECOND; case "ms": return 1; default: throw new IllegalArgumentException("Unknown duration unit " + unit); } }
public final T setHeader(String name, @Nullable String value) { checkArgument(CharMatcher.whitespace().matchesNoneOf(name)); name = Ascii.toLowerCase(name); value = emptyToNull(value); switch (name) { case "content-type": setContentType(value == null ? null : MediaType.parse(value)); break; case "content-length": setContentLength(value == null ? -1 : Long.parseLong(value)); break; default: if (value == null) { headers.remove(name); } else { checkArgument(CRLF.matchesNoneOf(value)); headers.put(name, checkNotNull(value)); } } return castThis(); }
/** Stores a report on GCS, returning the name of the file stored. */ private String saveReportToGcs(String tld, String reportCsv, ReportType reportType) throws IOException { // Upload resulting CSV file to GCS byte[] reportBytes = reportCsv.getBytes(UTF_8); String reportFilename = String.format( "%s-%s-%s.csv", tld, Ascii.toLowerCase(reportType.toString()), DateTimeFormat.forPattern("yyyyMM").print(yearMonth)); String reportBucketname = String.format("%s/%s", reportingBucket, subdir); final GcsFilename gcsFilename = new GcsFilename(reportBucketname, reportFilename); gcsUtils.createFromBytes(gcsFilename, reportBytes); logger.infofmt( "Wrote %d bytes to file location %s", reportBytes.length, gcsFilename.toString()); return reportFilename; }
/** * Validate the checksum of the notice against the domain label. * * @throws IllegalArgumentException * @throws InvalidChecksumException */ public void validate(String domainLabel) throws InvalidChecksumException { // According to http://tools.ietf.org/html/draft-lozano-tmch-func-spec-08#section-6.3, a TCNID // is always 8 chars of checksum + 19 chars of a decimal notice id. Check the length before // taking substrings to avoid an IndexOutOfBoundsException. String tcnId = getNoticeId().getTcnId(); checkArgument(tcnId.length() == 27); int checksum = Ints.fromByteArray(base16().decode(Ascii.toUpperCase(tcnId.substring(0, 8)))); String noticeId = tcnId.substring(8); checkArgument(CharMatcher.inRange('0', '9').matchesAllOf(noticeId)); // The checksum in the first 8 chars must match the crc32 of label + expiration + notice id. String stringToHash = domainLabel + MILLISECONDS.toSeconds(getExpirationTime().getMillis()) + noticeId; int computedChecksum = crc32().hashString(stringToHash, UTF_8).asInt(); if (checksum != computedChecksum) { throw new InvalidChecksumException(); } }
public String apply(String input) { if (!input.isEmpty()) { if (this == CAPITALIZED && !Ascii.isUpperCase(input.charAt(0))) { return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, input); } if (this == LOWERIZED && !Ascii.isLowerCase(input.charAt(0))) { return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, input); } } return input; }
static boolean shouldDisableFor(ValueType type) { Reporter reporter = type.constitution.protoclass().report(); for (String segment : DOT_SPLITTER.split(type.constitution.implementationPackage())) { if (!segment.isEmpty() && Ascii.isUpperCase(segment.charAt(0))) { reporter.warning(WARNING_START + " uppercase package names"); return true; } } Element element = type.constitution.protoclass().sourceElement(); if (shouldDisableFor(reporter, element)) { return true; } for (ValueAttribute attribute : type.attributes) { if (Ascii.isUpperCase(attribute.names.get.charAt(0))) { reporter.warning(WARNING_START + " uppercase attribute names"); return true; } if (attribute.containedTypeElement != null) { if (shouldDisableFor(reporter, attribute.containedTypeElement)) { return true; } } } for (ValueType nested : type.nested) { if (shouldDisableFor(nested)) { return true; } } return false; }
void process() { if (startType.getKind().isPrimitive()) { // taking a shortcut for primitives String typeName = Ascii.toLowerCase(startType.getKind().name()); this.rawTypeName = typeName; this.returnTypeName = typeName; List<? extends AnnotationMirror> annotations = AnnotationMirrors.from(startType); if (!annotations.isEmpty()) { returnTypeName = typeAnnotationsToBuffer(annotations).append(typeName).toString(); } } else { this.buffer = new StringBuilder(100); caseType(startType); if (workaroundTypeString != null) { // to not mix the mess, we just replace buffer with workaround produced type string this.buffer = new StringBuilder(workaroundTypeString); } // It seems that array type annotations are not exposed in javac // Nested type argument's type annotations are not exposed as well (in javac) // So currently we instert only for top level, declared type (here), // and primitives (see above) TypeKind k = startType.getKind(); if (k == TypeKind.DECLARED || k == TypeKind.ERROR) { insertTypeAnnotationsIfPresent(startType, 0, rawTypeName.length()); } this.returnTypeName = buffer.toString(); } }
@Override public String apply(String input) { unresolved = false; boolean assumedUnqualified = Ascii.isUpperCase(input.charAt(0)); if (assumedUnqualified) { input = qualifyImportedIfPossible(input, false); } return input; }
String resolveTopForAttribute(String input) { unresolved = false; boolean assumedUnqualified = Ascii.isUpperCase(input.charAt(0)); if (assumedUnqualified) { input = qualifyImportedIfPossible(input, !unresolvedYetArguments.contains(input)); } return input; }
@Override public void serialize(ServerPort value, JsonGenerator gen, SerializerProvider serializers) throws IOException { final InetSocketAddress localAddr = value.localAddress(); final int port = localAddr.getPort(); final String proto = Ascii.toLowerCase(value.protocol().uriText()); final String host; if (localAddr.getAddress().isAnyLocalAddress()) { host = "*"; } else { final String hs = localAddr.getHostString(); if (NetUtil.isValidIpV6Address(hs)) { // Try to get the platform-independent consistent IPv6 address string. host = NetUtil.toAddressString(localAddr.getAddress()); } else { host = hs; } } gen.writeStartObject(); gen.writeObjectFieldStart("localAddress"); gen.writeStringField("host", host); gen.writeNumberField("port", port); gen.writeEndObject(); gen.writeStringField("protocol", proto); gen.writeEndObject(); }
/** * Returns a string representation for this CacheBuilder instance. The exact form of the returned * string is not specified. */ @Override public String toString() { MoreObjects.ToStringHelper s = MoreObjects.toStringHelper(this); if (initialCapacity != UNSET_INT) { s.add("initialCapacity", initialCapacity); } if (concurrencyLevel != UNSET_INT) { s.add("concurrencyLevel", concurrencyLevel); } if (maximumSize != UNSET_INT) { s.add("maximumSize", maximumSize); } if (maximumWeight != UNSET_INT) { s.add("maximumWeight", maximumWeight); } if (expireAfterWriteNanos != UNSET_INT) { s.add("expireAfterWrite", expireAfterWriteNanos + "ns"); } if (expireAfterAccessNanos != UNSET_INT) { s.add("expireAfterAccess", expireAfterAccessNanos + "ns"); } if (keyStrength != null) { s.add("keyStrength", Ascii.toLowerCase(keyStrength.toString())); } if (valueStrength != null) { s.add("valueStrength", Ascii.toLowerCase(valueStrength.toString())); } if (keyEquivalence != null) { s.addValue("keyEquivalence"); } if (valueEquivalence != null) { s.addValue("valueEquivalence"); } if (removalListener != null) { s.addValue("removalListener"); } return s.toString(); }
int decode(char ch) throws DecodingException { if (ch > Ascii.MAX || decodabet[ch] == -1) { throw new DecodingException( "Unrecognized character: " + (CharMatcher.invisible().matches(ch) ? "0x" + Integer.toHexString(ch) : ch)); } return decodabet[ch]; }
private boolean hasLowerCase() { for (char c : chars) { if (Ascii.isLowerCase(c)) { return true; } } return false; }
private boolean hasUpperCase() { for (char c : chars) { if (Ascii.isUpperCase(c)) { return true; } } return false; }
Alphabet upperCase() { if (!hasLowerCase()) { return this; } else { checkState(!hasUpperCase(), "Cannot call upperCase() on a mixed-case alphabet"); char[] upperCased = new char[chars.length]; for (int i = 0; i < chars.length; i++) { upperCased[i] = Ascii.toUpperCase(chars[i]); } return new Alphabet(name + ".upperCase()", upperCased); } }
Alphabet lowerCase() { if (!hasUpperCase()) { return this; } else { checkState(!hasLowerCase(), "Cannot call lowerCase() on a mixed-case alphabet"); char[] lowerCased = new char[chars.length]; for (int i = 0; i < chars.length; i++) { lowerCased[i] = Ascii.toLowerCase(chars[i]); } return new Alphabet(name + ".lowerCase()", lowerCased); } }
@Override public M create(Object... elements) { Multimap<String, String> multimap = ArrayListMultimap.create(); for (Object o : elements) { @SuppressWarnings("unchecked") Entry<String, String> entry = (Entry<String, String>) o; multimap.put(entry.getKey(), Ascii.toUpperCase(entry.getValue())); } return transform(multimap); }
public void testMap() { SpliteratorTester.of( () -> CollectSpliterators.map( Arrays.spliterator(new String[] {"a", "b", "c", "d", "e"}), Ascii::toUpperCase)) .expect("A", "B", "C", "D", "E"); }
private static String upperToHttpHeaderName(String constantName, ImmutableBiMap<String, String> specialCases, ImmutableSet<String> uppercaseAcronyms) { if (specialCases.containsKey(constantName)) { return specialCases.get(constantName); } List<String> parts = Lists.newArrayList(); for (String part : SPLITTER.split(constantName)) { if (!uppercaseAcronyms.contains(part)) { part = part.charAt(0) + Ascii.toLowerCase(part.substring(1)); } parts.add(part); } return JOINER.join(parts); }
@GwtIncompatible // Reader/Writer private static void testStreamingEncodingWithCasing( BaseEncoding encoding, String decoded, String encoded) throws IOException { testStreamingEncodingWithSeparators(encoding, decoded, encoded); testStreamingEncodingWithSeparators(encoding.upperCase(), decoded, Ascii.toUpperCase(encoded)); testStreamingEncodingWithSeparators(encoding.lowerCase(), decoded, Ascii.toLowerCase(encoded)); }
/** * Looks up a scheme by name. * @return {@link Scheme#UNKNOWN} if schemeName is not recognized. */ public Scheme schemeForName(String schemeName) { String lSchemeName = Ascii.toLowerCase(schemeName); Scheme s = additionalSchemes.get(lSchemeName); if (s == null) { s = BuiltinScheme.forName(lSchemeName); } return s != null ? s : Scheme.UNKNOWN; }