List of usage examples for com.google.common.base CharMatcher matches
public abstract boolean matches(char c);
From source file:org.opendaylight.restconf.parser.builder.YangInstanceIdentifierDeserializer.java
private static void nextSequenceEnd(final CharMatcher matcher, final MainVarsWrapper variables) { while (!allCharsConsumed(variables) && matcher.matches(variables.getData().charAt(variables.getOffset()))) { variables.setOffset(variables.getOffset() + 1); }//from www .ja v a2 s. co m }
From source file:fr.openwide.core.spring.util.StringUtils.java
public static String capitalize(String str, CharMatcher charMatcher) { if (str == null) { return null; }// w ww . j a v a 2 s. c o m final char[] buffer = str.toCharArray(); boolean capitalizeNext = true; for (int i = 0; i < buffer.length; i++) { final char ch = buffer[i]; if (charMatcher.matches(ch)) { capitalizeNext = true; } else if (capitalizeNext) { buffer[i] = Character.toTitleCase(ch); capitalizeNext = false; } } return new String(buffer); }
From source file:org.auraframework.impl.css.parser.ThemeValueProviderImpl.java
/** * Format a raw reference before passing to the expression engine. Basically the means we strip the first leading * and trailing double quotes or single quotes. This is only if the reference begins and ends with matching quotes. * In CSS the quotes are necessary for the CSS Parser, however we don't want to pass the quotes to the expression * engine, or it will end up seeing the whole thing as a literal. * //from w w w . java 2s .c om * <p> * If the first character is <i>not</i> a quote then we return the original reference unchanged. This might be true * if evaluating a reference that isn't coming from a CSS file source. * * @param reference The raw reference string, e.g., including quotes, "namespace.theme.variable" * * @return The formatted reference. * * @throws AuraRuntimeException if the reference is not enclosed with matching quotes. */ private static String formatReference(String reference, Location location) { CharMatcher mode; // figure out if using double or single quotes if (SINGLE_Q.matches(reference.charAt(0))) { mode = SINGLE_Q; } else if (DOUBLE_Q.matches(reference.charAt(0))) { mode = DOUBLE_Q; } else { // unquoted return reference; } // ensure the last character is a matching quote if (!mode.matches(reference.charAt(reference.length() - 1))) { throw new AuraRuntimeException(String.format(MISSING_CLOSING, reference), location); } // remove first and last chars, which should be quotes return reference.substring(1, reference.length() - 1); }
From source file:com.google.devtools.build.lib.syntax.StringModule.java
private static String stringLStrip(String self, String chars) { CharMatcher matcher = CharMatcher.anyOf(chars); for (int i = 0; i < self.length(); i++) { if (!matcher.matches(self.charAt(i))) { return self.substring(i); }/*w w w . j a va 2s .c o m*/ } return ""; // All characters were stripped. }
From source file:com.google.devtools.build.lib.syntax.StringModule.java
private static String stringRStrip(String self, String chars) { CharMatcher matcher = CharMatcher.anyOf(chars); for (int i = self.length() - 1; i >= 0; i--) { if (!matcher.matches(self.charAt(i))) { return self.substring(0, i + 1); }/* w w w. j av a 2s. c o m*/ } return ""; // All characters were stripped. }
From source file:com.davidbracewell.string.StringUtils.java
/** * Generates a random string of a given length * * @param length The length of the string * @param min The min character in the string * @param max The max character in the string * @param validChar CharMatcher that must match for a character to be returned in the string * @return A string of random characters *//*from ww w .j ava 2 s .c om*/ public static String randomString(int length, int min, int max, CharMatcher validChar) { Preconditions.checkArgument(length >= 0, "Length must be non-negative"); if (length == 0) { return EMPTY; } Random random = new Random(); int maxRandom = max - min; char[] array = new char[length]; for (int i = 0; i < array.length; i++) { char c; do { c = (char) (random.nextInt(maxRandom) + min); } while (Character.isLowSurrogate(c) || Character.isHighSurrogate(c) || !validChar.matches(c)); array[i] = c; } return new String(array); }
From source file:com.google.devtools.build.lib.syntax.StringModule.java
private static boolean matches(String str, CharMatcher matcher, boolean requiresAtLeastOneCasedLetter) { if (str.isEmpty()) { return false; } else if (!requiresAtLeastOneCasedLetter) { return matcher.matchesAllOf(str); }//from ww w .jav a2s. c o m int casedLetters = 0; for (char current : str.toCharArray()) { if (!matcher.matches(current)) { return false; } else if (requiresAtLeastOneCasedLetter && CASED.matches(current)) { ++casedLetters; } } return casedLetters > 0; }
From source file:nl.tue.gale.common.uri.SimpleCharMatcher.java
private SimpleCharMatcher(CharMatcher matcher) { for (int i = 0; i < 256; i++) if (matcher.matches((char) i)) table[i >> 5] |= (1 << i); }
From source file:fr.putnami.pwt.plugin.code.client.token.evaluator.WhitespaceTokenEvaluator.java
private boolean matches(CharMatcher charMatcher, int charOrEof) { if (charOrEof == CharacterScanner.EOF) { return false; }//from w ww . j a v a 2 s. c om return charMatcher.matches((char) charOrEof); }
From source file:org.openhealthtools.mdht.mdmi.util.DateUtil.java
/** * For outputting dates, tries to match the output precision with the input precision. * This has been tested with quoted and unquoted literals and supports varying expressions * of the same precision./*from w w w. ja va2 s . c om*/ * TODO: Differing expressions of precision (e.g., from day as digit to day as name) * has not been tested because the engine has a bug in which it always passes the destination * format string, not the source. * * @param outFormat The maximal precision output format. * @param originalFormat The orginalFormat of the date, from the date wrapper. * @return A truncation of outFormat to match the precision of the originalFormat */ public static String matchPrecision(String outFormat, String originalFormat) { // Check for nulls if (originalFormat == null || originalFormat.equals("") || originalFormat.equals("DATE")) return outFormat; // Use our static data and a string matcher to add all the weird precision overlaps originalFormat = originalFormat.replaceAll("'.*'", ""); // Remove quoted literals String newOF_src = outFormat.replaceAll("'.*'", ""); StringBuilder newOF_trg = new StringBuilder(); for (int i = 0; i < dateParts.length; i++) { if (dateParts[i].matchesAnyOf(originalFormat)) newOF_trg.append(dateParts[i].retainFrom(newOF_src)); } // Use Guava's charmatcher to deal with everything but single-quoted literals CharMatcher matcher = CharMatcher.anyOf(newOF_trg).or(CharMatcher.JAVA_LETTER.negate()); // bugfix 2/9/15 - remove trailing non-format chars (e.g. :) if (!outFormat.contains("'")) return CharMatcher.JAVA_LETTER.negate().trimTrailingFrom(matcher.retainFrom(outFormat)); else { // There are single-quoted literals. Yuck. StringBuilder newOut = new StringBuilder(); boolean instring = false; for (int i = 0; i < outFormat.length(); i++) { char current = outFormat.charAt(i); if (current == '\'') { if (instring == false) instring = true; else instring = false; } if (instring || matcher.matches(current)) newOut.append(current); } return newOut.toString(); } }