/** * Returns a string containing all matching BMP characters of a character sequence, in order. For * example: * * <pre>{@code * CharMatcher.is('a').retainFrom("bazaar") * }</pre> * * ... returns {@code "aaa"}. */ public String retainFrom(CharSequence sequence) { return negate().removeFrom(sequence); }
/** * Get exactly value for SQL expression. * * <p>remove special char for SQL expression</p> * * @param value SQL expression * @return exactly SQL expression */ public static String getExactlyValue(final String value) { return null == value ? null : CharMatcher.anyOf("[]`'\"").removeFrom(value); }
/** * Get exactly SQL expression. * * <p>remove space for SQL expression</p> * * @param value SQL expression * @return exactly SQL expression */ public static String getExactlyExpression(final String value) { return null == value ? null : CharMatcher.anyOf(" ").removeFrom(value); }
/** * Returns a string containing all matching BMP characters of a character sequence, in order. For * example: * * <pre>{@code * CharMatcher.is('a').retainFrom("bazaar") * }</pre> * * ... returns {@code "aaa"}. */ public String retainFrom(CharSequence sequence) { return negate().removeFrom(sequence); }
/** * Returns a string containing all matching BMP characters of a character sequence, in order. For * example: * * <pre>{@code * CharMatcher.is('a').retainFrom("bazaar") * }</pre> * * ... returns {@code "aaa"}. */ public String retainFrom(CharSequence sequence) { return negate().removeFrom(sequence); }
private String parseValue(String n) { String number_value = CharMatcher.WHITESPACE.removeFrom(n); Pattern number_format = Pattern.compile("^(\\d{1,3})(((,\\d{3})*)|((\\.\\d+)?[MBK]))?$"); Matcher m = number_format.matcher(number_value); if (!m.find()) { DAO.severe("This is outputing wrong value. Need to be fixed"); } return number_value; }
static List<byte[]> readCertificates(Path path) throws CertificateException { final byte[] bytes; try { bytes = Files.readAllBytes(path); } catch (IOException e) { throw new CertificateException("Couldn't read certificates from file: " + path, e); } final String content = new String(bytes, StandardCharsets.US_ASCII); final Matcher m = CERT_PATTERN.matcher(content); final List<byte[]> certs = new ArrayList<>(); int start = 0; while (m.find(start)) { final String s = m.group(1); byte[] der = Base64.getDecoder().decode(CharMatcher.breakingWhitespace().removeFrom(s)); certs.add(der); start = m.end(); } if (certs.isEmpty()) { throw new CertificateException("No certificates found in file: " + path); } return certs; }
int replacementLen = replacement.length(); if (replacementLen == 0) { return removeFrom(sequence);
static byte[] readPrivateKey(Path path) throws KeyException { final byte[] bytes; try { bytes = Files.readAllBytes(path); } catch (IOException e) { throw new KeyException("Couldn't read private key from file: " + path, e); } final String content = new String(bytes, StandardCharsets.US_ASCII); final Matcher m = KEY_PATTERN.matcher(content); if (!m.find()) { throw new KeyException("No private key found in file: " + path); } final String s = CharMatcher.breakingWhitespace().removeFrom(m.group(1)); byte[] base64 = s.getBytes(StandardCharsets.US_ASCII); return Base64.getDecoder().decode(base64); }
int replacementLen = replacement.length(); if (replacementLen == 0) { return removeFrom(sequence);
@Description("mongodb ObjectId from the given string") @ScalarFunction("objectid") @SqlType("ObjectId") public static Slice ObjectId(@SqlType(StandardTypes.VARCHAR) Slice value) { return Slices.wrappedBuffer(new ObjectId(CharMatcher.is(' ').removeFrom(value.toStringUtf8())).toByteArray()); }
private void reallyTestAllMatches(CharMatcher matcher, CharSequence s) { assertTrue(matcher.matches(s.charAt(0))); assertEquals(0, matcher.indexIn(s)); assertEquals(0, matcher.indexIn(s, 0)); assertEquals(1, matcher.indexIn(s, 1)); assertEquals(-1, matcher.indexIn(s, s.length())); assertEquals(s.length() - 1, matcher.lastIndexIn(s)); assertTrue(matcher.matchesAnyOf(s)); assertTrue(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertEquals("", matcher.removeFrom(s)); assertEquals(Strings.repeat("z", s.length()), matcher.replaceFrom(s, 'z')); assertEquals(Strings.repeat("ZZ", s.length()), matcher.replaceFrom(s, "ZZ")); assertEquals("", matcher.trimFrom(s)); assertEquals(s.length(), matcher.countIn(s)); }
private void reallyTestMatchThenNoMatch(CharMatcher matcher, String s) { assertEquals(0, matcher.indexIn(s)); assertEquals(0, matcher.indexIn(s, 0)); assertEquals(-1, matcher.indexIn(s, 1)); assertEquals(-1, matcher.indexIn(s, 2)); assertEquals(0, matcher.lastIndexIn(s)); assertTrue(matcher.matchesAnyOf(s)); assertFalse(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertEquals(s.substring(1), matcher.removeFrom(s)); assertEquals("z" + s.substring(1), matcher.replaceFrom(s, 'z')); assertEquals("ZZ" + s.substring(1), matcher.replaceFrom(s, "ZZ")); assertEquals(s.substring(1), matcher.trimFrom(s)); assertEquals(1, matcher.countIn(s)); }
private void reallyTestNoMatchThenMatch(CharMatcher matcher, String s) { assertEquals(1, matcher.indexIn(s)); assertEquals(1, matcher.indexIn(s, 0)); assertEquals(1, matcher.indexIn(s, 1)); assertEquals(-1, matcher.indexIn(s, 2)); assertEquals(1, matcher.lastIndexIn(s)); assertTrue(matcher.matchesAnyOf(s)); assertFalse(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertEquals(s.substring(0, 1), matcher.removeFrom(s)); assertEquals(s.substring(0, 1) + "z", matcher.replaceFrom(s, 'z')); assertEquals(s.substring(0, 1) + "ZZ", matcher.replaceFrom(s, "ZZ")); assertEquals(s.substring(0, 1), matcher.trimFrom(s)); assertEquals(1, matcher.countIn(s)); }
private void reallyTestNoMatches(CharMatcher matcher, CharSequence s) { assertFalse(matcher.matches(s.charAt(0))); assertEquals(-1, matcher.indexIn(s)); assertEquals(-1, matcher.indexIn(s, 0)); assertEquals(-1, matcher.indexIn(s, 1)); assertEquals(-1, matcher.indexIn(s, s.length())); try { matcher.indexIn(s, s.length() + 1); fail(); } catch (IndexOutOfBoundsException expected) { } try { matcher.indexIn(s, -1); fail(); } catch (IndexOutOfBoundsException expected) { } assertEquals(-1, matcher.lastIndexIn(s)); assertFalse(matcher.matchesAnyOf(s)); assertFalse(matcher.matchesAllOf(s)); assertTrue(matcher.matchesNoneOf(s)); assertEquals(s.toString(), matcher.removeFrom(s)); assertEquals(s.toString(), matcher.replaceFrom(s, 'z')); assertEquals(s.toString(), matcher.replaceFrom(s, "ZZ")); assertEquals(s.toString(), matcher.trimFrom(s)); assertEquals(0, matcher.countIn(s)); }
@Test public void marshalingOfNested() { check(CharMatcher.whitespace().removeFrom( Marshaling.toJson( ImmutableGroupedClasses.NestedOne.builder().build()))).is("{}"); } }
@SuppressWarnings("deprecation") // intentionally testing apply() method private void reallyTestOneCharMatch(CharMatcher matcher, String s) { assertTrue(matcher.matches(s.charAt(0))); assertTrue(matcher.apply(s.charAt(0))); assertEquals(0, matcher.indexIn(s)); assertEquals(0, matcher.indexIn(s, 0)); assertEquals(-1, matcher.indexIn(s, 1)); assertEquals(0, matcher.lastIndexIn(s)); assertTrue(matcher.matchesAnyOf(s)); assertTrue(matcher.matchesAllOf(s)); assertFalse(matcher.matchesNoneOf(s)); assertEquals("", matcher.removeFrom(s)); assertEquals("z", matcher.replaceFrom(s, 'z')); assertEquals("ZZ", matcher.replaceFrom(s, "ZZ")); assertEquals("", matcher.trimFrom(s)); assertEquals(1, matcher.countIn(s)); }
@SuppressWarnings("deprecation") // intentionally testing apply() method private void reallyTestOneCharNoMatch(CharMatcher matcher, String s) { assertFalse(matcher.matches(s.charAt(0))); assertFalse(matcher.apply(s.charAt(0))); assertEquals(-1, matcher.indexIn(s)); assertEquals(-1, matcher.indexIn(s, 0)); assertEquals(-1, matcher.indexIn(s, 1)); assertEquals(-1, matcher.lastIndexIn(s)); assertFalse(matcher.matchesAnyOf(s)); assertFalse(matcher.matchesAllOf(s)); assertTrue(matcher.matchesNoneOf(s)); assertSame(s, matcher.removeFrom(s)); assertSame(s, matcher.replaceFrom(s, 'z')); assertSame(s, matcher.replaceFrom(s, "ZZ")); assertSame(s, matcher.trimFrom(s)); assertSame(0, matcher.countIn(s)); }
@Test public void nullableMarshaling() { check(CharMatcher.whitespace().removeFrom(Marshaling.toJson(ImmutableHasNullable.of()))).is("{}"); check(Marshaling.fromJson("{}", ImmutableHasNullable.class)).is(ImmutableHasNullable.of()); check(Marshaling.fromJson("{\"in\":1}", ImmutableHasNullable.class)).is(ImmutableHasNullable.of(1)); check(Marshaling.fromJson("{\"def\":\"1\"}", ImmutableHasNullable.class)) .is(ImmutableHasNullable.of().withDef("1")); }
private void reallyTestEmpty(CharMatcher matcher) throws Exception { assertEquals(-1, matcher.indexIn("")); assertEquals(-1, matcher.indexIn("", 0)); try { matcher.indexIn("", 1); fail(); } catch (IndexOutOfBoundsException expected) { } try { matcher.indexIn("", -1); fail(); } catch (IndexOutOfBoundsException expected) { } assertEquals(-1, matcher.lastIndexIn("")); assertFalse(matcher.matchesAnyOf("")); assertTrue(matcher.matchesAllOf("")); assertTrue(matcher.matchesNoneOf("")); assertEquals("", matcher.removeFrom("")); assertEquals("", matcher.replaceFrom("", 'z')); assertEquals("", matcher.replaceFrom("", "ZZ")); assertEquals("", matcher.trimFrom("")); assertEquals(0, matcher.countIn("")); }