@Override public IntStream codePoints() { return value.codePoints(); }
@CheckForNull private static String removeCharZeros(@Nullable String str) { if (str == null || str.isEmpty()) { return str; } return str.codePoints() .filter(c -> c != "\u0000".codePointAt(0)) .collect(StringBuilder::new, StringBuilder::appendCodePoint, StringBuilder::append) .toString(); } }
@Benchmark public long java8_1() { // Using Java8 (case 2) return testString.codePoints().filter(ch -> ch == '.').count(); }
@Benchmark public long java8_1() { // Using Java8 (case 2) return testString.codePoints().filter(ch -> ch == '.').count(); }
public static Slice unescapeLiteralLikePattern(Slice pattern, Slice escape) { if (escape == null) { return pattern; } String stringEscape = escape.toStringUtf8(); char escapeChar = stringEscape.charAt(0); String stringPattern = pattern.toStringUtf8(); StringBuilder unescapedPattern = new StringBuilder(stringPattern.length()); boolean escaped = false; for (int currentChar : stringPattern.codePoints().toArray()) { if (!escaped && (currentChar == escapeChar)) { escaped = true; } else { unescapedPattern.append(Character.toChars(currentChar)); escaped = false; } } return Slices.utf8Slice(unescapedPattern.toString()); }
PrimitiveIterator.OfInt iterator = s.codePoints().iterator(); while (iterator.hasNext()) { int codePoint = iterator.nextInt();
private static String lowerByCodePoint(String string) { int[] upperCodePoints = string.codePoints().map(Character::toLowerCase).toArray(); return new String(upperCodePoints, 0, upperCodePoints.length); }
private static String upperByCodePoint(String string) { int[] upperCodePoints = string.codePoints().map(Character::toUpperCase).toArray(); return new String(upperCodePoints, 0, upperCodePoints.length); }
public static boolean isLikePattern(Slice pattern, Slice escape) { String stringPattern = pattern.toStringUtf8(); if (escape == null) { return stringPattern.contains("%") || stringPattern.contains("_"); } String stringEscape = escape.toStringUtf8(); checkCondition(stringEscape.length() == 1, INVALID_FUNCTION_ARGUMENT, "Escape string must be a single character"); char escapeChar = stringEscape.charAt(0); boolean escaped = false; boolean isLikePattern = false; for (int currentChar : stringPattern.codePoints().toArray()) { if (!escaped && (currentChar == escapeChar)) { escaped = true; } else if (escaped) { checkEscape(currentChar == '%' || currentChar == '_' || currentChar == escapeChar); escaped = false; } else if ((currentChar == '%') || (currentChar == '_')) { isLikePattern = true; } } checkEscape(!escaped); return isLikePattern; }
private boolean codePointsInRange(String s) { return s.codePoints().allMatch(this::codePointInRange); }
@Override public List<String> doShrink(SourceOfRandomness random, String larger) { List<String> shrinks = new ArrayList<>(); List<Integer> codePoints = larger.codePoints().boxed().collect(toList()); shrinks.addAll(removals(codePoints)); List<List<Integer>> oneItemShrinks = shrinksOfOneItem(random, codePoints, new CodePointShrink(this::codePointInRange)); shrinks.addAll(oneItemShrinks.stream() .map(this::convert) .filter(this::codePointsInRange) .collect(toList())); return shrinks; }
public static boolean checkCharacter(String s){ return s.codePoints().allMatch(code -> CharUtils.isAsciiPrintable((char) code)); } }
/** Returns true iff the given file's formatting is up-to-date. */ public boolean isClean(File file) throws IOException { Objects.requireNonNull(file); String raw = new String(Files.readAllBytes(file.toPath()), encoding); String unix = LineEnding.toUnix(raw); // check the newlines (we can find these problems without even running the steps) int totalNewLines = (int) unix.codePoints().filter(val -> val == '\n').count(); int windowsNewLines = raw.length() - unix.length(); if (lineEndingsPolicy.isUnix(file)) { if (windowsNewLines != 0) { return false; } } else { if (windowsNewLines != totalNewLines) { return false; } } // check the other formats String formatted = compute(unix, file); // return true iff the formatted string equals the unix one return formatted.equals(unix); }
@Property public void works( Optional<@From(Encoded.class) @InCharset("US-ASCII") String> optional) { assumeTrue(optional.isPresent()); assertTrue(optional.get().codePoints().allMatch(i -> i < 128)); } }
@Property public void works( Optional<@From(Encoded.class) @InCharset("US-ASCII") String> optional) { assumeTrue(optional.isPresent()); assertTrue(optional.get().codePoints().allMatch(i -> i < 128)); } }
private static String upperByCodePoint(String string) { int[] upperCodePoints = string.codePoints().map(Character::toUpperCase).toArray(); return new String(upperCodePoints, 0, upperCodePoints.length); }
private static String lowerByCodePoint(String string) { int[] upperCodePoints = string.codePoints().map(Character::toLowerCase).toArray(); return new String(upperCodePoints, 0, upperCodePoints.length); }
private static String lowerByCodePoint(String string) { int[] upperCodePoints = string.codePoints().map(Character::toLowerCase).toArray(); return new String(upperCodePoints, 0, upperCodePoints.length); }
private static void assertReverse(String string) { Slice actualReverse = reverse(utf8Slice(string)); int[] codePoints = string.codePoints().toArray(); codePoints = Ints.toArray(Lists.reverse(Ints.asList(codePoints))); Slice expectedReverse = wrappedBuffer(new String(codePoints, 0, codePoints.length).getBytes(UTF_8)); assertEquals(actualReverse, expectedReverse); }
private static void assertReverse(String string) { Slice actualReverse = reverse(utf8Slice(string)); int[] codePoints = string.codePoints().toArray(); codePoints = Ints.toArray(Lists.reverse(Ints.asList(codePoints))); Slice expectedReverse = wrappedBuffer(new String(codePoints, 0, codePoints.length).getBytes(UTF_8)); assertEquals(actualReverse, expectedReverse); }