use of com.google.common.base.CharMatcher in project binnavi by google.
the class Convert method isHexString.
/**
* Tests whether a given string is a valid hexadecimal string.
*
* @param string The string to check.
*
* @return True, if the string is a valid hexadecimal string. False, otherwise.
*/
public static boolean isHexString(final String string) {
Preconditions.checkNotNull(string, "Error: String argument can't be null");
final CharMatcher cm = CharMatcher.inRange('0', '9').or(CharMatcher.inRange('a', 'z')).or(CharMatcher.inRange('A', 'F'));
for (int i = 0; i < string.length(); i++) {
if (!cm.apply(string.charAt(i))) {
return false;
}
}
return string.length() != 0;
}
use of com.google.common.base.CharMatcher in project binnavi by google.
the class Convert method isDecString.
/**
* Tests whether a given string is a valid decimal string.
*
* @param string The string to check.
*
* @return True, if the string is a valid decimal string. False, otherwise.
*/
public static boolean isDecString(final String string) {
Preconditions.checkNotNull(string);
final CharMatcher cm = CharMatcher.inRange('0', '9');
for (int i = 0; i < string.length(); i++) {
if (!cm.apply(string.charAt(i))) {
return false;
}
}
return string.length() != 0;
}
use of com.google.common.base.CharMatcher in project presto by prestodb.
the class InvokeInstruction method checkUnqualifiedName.
private static void checkUnqualifiedName(String name) {
// JVM Specification 4.2.2 Unqualified Names
requireNonNull(name, "name is null");
checkArgument(!name.isEmpty(), "name is empty");
if (name.equals("<init>") || name.equals("<clinit>")) {
return;
}
CharMatcher invalid = CharMatcher.anyOf(".;[/<>");
checkArgument(invalid.matchesNoneOf(name), "invalid name: %s", name);
}
use of com.google.common.base.CharMatcher in project gerrit by GerritCodeReview.
the class FieldDef method checkName.
private static String checkName(String name) {
CharMatcher m = CharMatcher.anyOf("abcdefghijklmnopqrstuvwxyz0123456789_");
checkArgument(name != null && m.matchesAllOf(name), "illegal field name: %s", name);
return name;
}
use of com.google.common.base.CharMatcher in project cdap by caskdata.
the class StreamUtils method getGeneration.
/**
* Finds the current generation if of a stream. It scans the stream directory to look for largest generation
* number in directory name.
*
* @param streamLocation location to scan for generation id
* @return the generation id
*/
public static int getGeneration(Location streamLocation) throws IOException {
// Default generation is 0.
int genId = 0;
CharMatcher numMatcher = CharMatcher.inRange('0', '9');
List<Location> locations = streamLocation.list();
if (locations == null) {
return 0;
}
for (Location location : locations) {
if (numMatcher.matchesAllOf(location.getName()) && location.isDirectory()) {
int id = Integer.parseInt(location.getName());
if (id > genId) {
genId = id;
}
}
}
return genId;
}
Aggregations