List of usage examples for com.google.common.base CharMatcher inRange
public static CharMatcher inRange(final char startInclusive, final char endInclusive)
From source file:net.orpiske.sfs.filter.simple.CharacterFilter.java
@Override public String filter(String source) { CharMatcher legalChars = CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('A', 'Z')); return legalChars.retainFrom(source.subSequence(0, source.length())); }
From source file:net.orpiske.sfs.filter.simple.AlphaNumericFilter.java
@Override public String filter(String source) { CharMatcher legalChars = CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('A', 'Z')) .or(CharMatcher.inRange('0', '9')); return legalChars.retainFrom(source.subSequence(0, source.length())); }
From source file:co.cask.cdap.app.verification.AbstractVerifier.java
protected boolean isId(final String name) { return !name.isEmpty() && CharMatcher.inRange('A', 'Z').or(CharMatcher.inRange('a', 'z')).or(CharMatcher.is('-')) .or(CharMatcher.is('_')).or(CharMatcher.inRange('0', '9')).matchesAllOf(name); }
From source file:com.omricat.yacc.data.model.CurrencyCode.java
/** * Creates a new instance with the passed {@code String} as key. * @param key {@code String} to use as key *//* w w w . ja v a2 s. c o m*/ public CurrencyCode(@NotNull final String key) { checkNotNull(key); checkArgument(CharMatcher.inRange('A', 'Z').matchesAllOf(key)); checkArgument(key.length() == 3); this.key = checkNotNull(key); }
From source file:com.google.devtools.build.lib.unix.ProcMeminfoParser.java
@VisibleForTesting public ProcMeminfoParser(String fileName) throws IOException { List<String> lines = Files.readLines(new File(fileName), Charset.defaultCharset()); ImmutableMap.Builder<String, Long> builder = ImmutableMap.builder(); for (String line : lines) { int colon = line.indexOf(':'); if (colon == -1) { continue; }/*from w w w .j av a 2s . co m*/ String keyword = line.substring(0, colon); String valString = line.substring(colon + 1); try { long val = Long.parseLong(CharMatcher.inRange('0', '9').retainFrom(valString)); builder.put(keyword, val); } catch (NumberFormatException e) { // Ignore: we'll fail later if somebody tries to capture this value. } } memInfo = builder.build(); }
From source file:io.prestosql.client.OkHttpUtil.java
public static Interceptor tokenAuth(String accessToken) { requireNonNull(accessToken, "accessToken is null"); checkArgument(CharMatcher.inRange((char) 33, (char) 126).matchesAllOf(accessToken)); return chain -> chain .proceed(chain.request().newBuilder().addHeader(AUTHORIZATION, "Bearer " + accessToken).build()); }
From source file:com.android.build.gradle.tasks.GenerateSplitAbiRes.java
@TaskAction protected void doFullTaskAction() throws IOException, InterruptedException, ProcessException { for (String split : getSplits()) { String resPackageFileName = getOutputFileForSplit(split).getAbsolutePath(); File tmpDirectory = new File(getOutputDirectory(), getOutputBaseName()); tmpDirectory.mkdirs();/*from w ww .j a v a2 s . co m*/ File tmpFile = new File(tmpDirectory, "AndroidManifest.xml"); String versionNameToUse = getVersionName(); if (versionNameToUse == null) { versionNameToUse = String.valueOf(getVersionCode()); } try (OutputStreamWriter fileWriter = new OutputStreamWriter(new FileOutputStream(tmpFile), "UTF-8")) { // Split name can only contains 0-9, a-z, A-Z, '.' and '_'. Replace all other // characters with underscore. String splitName = CharMatcher.inRange('0', '9').or(CharMatcher.inRange('A', 'Z')) .or(CharMatcher.inRange('a', 'z')).or(CharMatcher.is('_')).or(CharMatcher.is('.')).negate() .replaceFrom(split + "_" + getOutputBaseName(), '_'); fileWriter.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<manifest xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " package=\"" + getApplicationId() + "\"\n" + " android:versionCode=\"" + getVersionCode() + "\"\n" + " android:versionName=\"" + versionNameToUse + "\"\n" + " split=\"lib_" + splitName + "\">\n" + " <uses-sdk android:minSdkVersion=\"21\"/>\n" + "</manifest> "); fileWriter.flush(); } Aapt aapt = AaptGradleFactory.make(getBuilder(), variantOutputData.getScope().getVariantScope(), FileUtils.mkdirs( new File(variantOutputData.getScope().getVariantScope().getIncrementalDir(getName()), "aapt-temp"))); AaptPackageConfig.Builder aaptConfig = new AaptPackageConfig.Builder(); aaptConfig.setManifestFile(tmpFile).setOptions(getAaptOptions()).setDebuggable(isDebuggable()) .setResourceOutputApk(new File(resPackageFileName)).setVariantType( variantOutputData.getScope().getVariantScope().getVariantConfiguration().getType()); getBuilder().processResources(aapt, aaptConfig, false /* enforceUniquePackageName */); } }
From source file:google.registry.model.domain.launch.LaunchNotice.java
/** * Validate the checksum of the notice against the domain label. * * @throws IllegalArgumentException//www. j a v a2s . c o m * @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(); } }
From source file:brooklyn.location.cloud.CloudMachineNamer.java
public static String sanitize(String s) { return CharMatcher.inRange('A', 'Z').or(CharMatcher.inRange('a', 'z')).or(CharMatcher.inRange('0', '9')) .negate().trimAndCollapseFrom(s, '-'); }
From source file:org.apache.brooklyn.location.cloud.names.AbstractCloudMachineNamer.java
@Beta //probably won't live here long-term public static String sanitize(String s) { return CharMatcher.inRange('A', 'Z').or(CharMatcher.inRange('a', 'z')).or(CharMatcher.inRange('0', '9')) .negate().trimAndCollapseFrom(s, '-'); }