/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.digit().trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.digit().trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.digit().trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
private void doTestTrimLeadingFrom(String in, String out) { // Try a few different matchers which all match '-' and not 'x' assertEquals(out, is('-').trimLeadingFrom(in)); assertEquals(out, is('-').or(is('#')).trimLeadingFrom(in)); assertEquals(out, isNot('x').trimLeadingFrom(in)); assertEquals(out, is('x').negate().trimLeadingFrom(in)); assertEquals(out, anyOf("-#").trimLeadingFrom(in)); assertEquals(out, anyOf("-#123").trimLeadingFrom(in)); }
tail.add(CharMatcher.whitespace().trimLeadingFrom(tokString(afterLastImport, toks.size()))); if (!toks.isEmpty()) { Tok lastTok = getLast(toks);
public static Location get(String base, String path) { base = CharMatcher.is('/').trimTrailingFrom(base); path = CharMatcher.is('/').trimLeadingFrom(path); return new AutoValue_Location(base, path, -1, -1); }
public void testTrimLeadingFrom() { // trimming - doTestTrimLeadingFrom("-", ""); doTestTrimLeadingFrom("x-", "x-"); doTestTrimLeadingFrom("-x", "x"); doTestTrimLeadingFrom("--", ""); doTestTrimLeadingFrom("x--", "x--"); doTestTrimLeadingFrom("--x", "x"); doTestTrimLeadingFrom("-x-", "x-"); doTestTrimLeadingFrom("x-x", "x-x"); doTestTrimLeadingFrom("---", ""); doTestTrimLeadingFrom("--x-", "x-"); doTestTrimLeadingFrom("--xx", "xx"); doTestTrimLeadingFrom("-x--", "x--"); doTestTrimLeadingFrom("-x-x", "x-x"); doTestTrimLeadingFrom("-xx-", "xx-"); doTestTrimLeadingFrom("x--x", "x--x"); doTestTrimLeadingFrom("x-x-", "x-x-"); doTestTrimLeadingFrom("x-xx", "x-xx"); doTestTrimLeadingFrom("x-x--xx---x----x", "x-x--xx---x----x"); // additional testing using the doc example assertEquals("catbab", anyOf("ab").trimLeadingFrom("abacatbab")); }
private static SizeUnit parseUnit(String s) { final String value = CharMatcher.WHITESPACE.removeFrom(s); final String suffix = CharMatcher.DIGIT.trimLeadingFrom(value).trim(); return SUFFIXES.get(suffix); }
private static String checkValidIdentifier(String identifier, boolean compound) { Preconditions.checkNotNull(identifier); String trimmed = identifier.trim(); Preconditions.checkArgument(!trimmed.isEmpty(), "Invalid identifier: '%s'", identifier); String[] parts = compound ? trimmed.split("\\.") : new String[] {trimmed}; for (String part : parts) { Preconditions.checkArgument( IDENTIFIER_REST.matchesAllOf(IDENTIFIER_START.trimLeadingFrom(part)), "Invalid identifier: '%s'", identifier); } return trimmed; }
private static TimeUnit parseUnit(String s) { final String value = CharMatcher.WHITESPACE.removeFrom(s); final String suffix = CharMatcher.DIGIT.trimLeadingFrom(value); return SUFFIXES.get(suffix); }
/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.DIGIT.trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.DIGIT.trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.DIGIT.trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.length() == 0) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
private String toUrl(String value) { try { URI uri = new URI(value); if (!uri.isAbsolute()) { // turn it into an absolute URL return SLASH.trimTrailingFrom(applicationProperties.getBaseUrl(UrlMode.CANONICAL)) + '/' + SLASH.trimLeadingFrom(value); } } catch (Exception e) { // not a valid URI, but the validator should determine that as well and throw an appropriate exception } return value; } }
/** * Returns the simple name of the underlying class as given in the source code. * * <p>Behaves identically to {@link Class#getSimpleName()} but does not require the class to be * loaded. */ public String getSimpleName() { int lastDollarSign = className.lastIndexOf('$'); if (lastDollarSign != -1) { String innerClassName = className.substring(lastDollarSign + 1); // local and anonymous classes are prefixed with number (1,2,3...), anonymous classes are // entirely numeric whereas local classes have the user supplied name as a suffix return CharMatcher.digit().trimLeadingFrom(innerClassName); } String packageName = getPackageName(); if (packageName.isEmpty()) { return className; } // Since this is a top level class, its simple name is always the part after package name. return className.substring(packageName.length() + 1); }
/** * Takes an address and a relative name and returns a rooted or relative name. * <p> * If a valid address is supplied then the returned name will always be a rooted name (i.e. * starting with {@code /}), otherwise it may be relative. {@code address} should not start * with a {@code /} and if it does, that prefix will be stripped. */ public static String joinAddressName(String address, String name) { address = CharMatcher.is('/').trimLeadingFrom(address); if (address.isEmpty()) { return clean(name); } if (name.isEmpty()) { return clean("/" + address); } return clean("/" + address + "/" + name); }
public static Location get(String base, String path) { base = CharMatcher.is('/').trimTrailingFrom(base); path = CharMatcher.is('/').trimLeadingFrom(path); return new AutoValue_Location(base, path, -1, -1); }
public static Location get(String base, String path) { base = CharMatcher.is('/').trimTrailingFrom(base); path = CharMatcher.is('/').trimLeadingFrom(path); return new AutoValue_Location(base, path, -1, -1); }
private void doTestTrimLeadingFrom(String in, String out) { // Try a few different matchers which all match '-' and not 'x' assertEquals(out, is('-').trimLeadingFrom(in)); assertEquals(out, is('-').or(is('#')).trimLeadingFrom(in)); assertEquals(out, isNot('x').trimLeadingFrom(in)); assertEquals(out, is('x').negate().trimLeadingFrom(in)); assertEquals(out, anyOf("-#").trimLeadingFrom(in)); assertEquals(out, anyOf("-#123").trimLeadingFrom(in)); }
@Override public boolean isSatisfiedBy(String candidateValue) { String testValue = candidateValue; if (options.isTrimmed()) { testValue = CharMatcher.whitespace().trimFrom(testValue); } else { if (options.isLeadTrimmed()) { testValue = CharMatcher.whitespace().trimLeadingFrom(testValue); } if (options.isTailTrimmed()) { testValue = CharMatcher.whitespace().trimTrailingFrom(testValue); } } return isSatisfiedByString(testValue); }