public void testFixedLengthSplitZeroChunkLen() { try { Splitter.fixedLength(0); fail(); } catch (IllegalArgumentException expected) { } }
public void testFixedLengthSplitNegativeChunkLen() { try { Splitter.fixedLength(-1); fail(); } catch (IllegalArgumentException expected) { } }
public void testFixedLengthSplitEmptyStringWithOmitEmptyStrings() { assertThat(Splitter.fixedLength(3).omitEmptyStrings().split("")).isEmpty(); }
public void testFixedLengthSplitOnlyOneChunk() { String simple = "abc"; Iterable<String> letters = Splitter.fixedLength(3).split(simple); assertThat(letters).containsExactly("abc").inOrder(); }
public void testFixedLengthSplitEmptyString() { String simple = ""; Iterable<String> letters = Splitter.fixedLength(3).split(simple); assertThat(letters).containsExactly("").inOrder(); }
public void testFixedLengthSplitIntoChars() { String simple = "abcd"; Iterable<String> letters = Splitter.fixedLength(1).split(simple); assertThat(letters).containsExactly("a", "b", "c", "d").inOrder(); }
public void testFixedLengthSimpleSplit() { String simple = "abcde"; Iterable<String> letters = Splitter.fixedLength(2).split(simple); assertThat(letters).containsExactly("ab", "cd", "e").inOrder(); }
public void testFixedLengthSplitEqualChunkLength() { String simple = "abcdef"; Iterable<String> letters = Splitter.fixedLength(2).split(simple); assertThat(letters).containsExactly("ab", "cd", "ef").inOrder(); }
public void testFixedLengthSplitSmallerString() { String simple = "ab"; Iterable<String> letters = Splitter.fixedLength(3).split(simple); assertThat(letters).containsExactly("ab").inOrder(); }
private static void testEncodingWithSeparators( BaseEncoding encoding, String decoded, String encoded) { testEncoding(encoding, decoded, encoded); // test separators work for (int sepLength = 3; sepLength <= 5; sepLength++) { for (String separator : ImmutableList.of(",", "\n", ";;", "")) { testEncoding( encoding.withSeparator(separator, sepLength), decoded, Joiner.on(separator).join(Splitter.fixedLength(sepLength).split(encoded))); } } }
public void testLimitOne() { String simple = "abcd"; Iterable<String> letters = Splitter.fixedLength(1).limit(1).split(simple); assertThat(letters).containsExactly("abcd").inOrder(); }
public void testLimitFixedLength() { String simple = "abcd"; Iterable<String> letters = Splitter.fixedLength(1).limit(2).split(simple); assertThat(letters).containsExactly("a", "bcd").inOrder(); }
public void testLimitLarge() { String simple = "abcd"; Iterable<String> letters = Splitter.fixedLength(1).limit(100).split(simple); assertThat(letters).containsExactly("a", "b", "c", "d").inOrder(); }
@GwtIncompatible // Reader/Writer private static void testStreamingEncodingWithSeparators( BaseEncoding encoding, String decoded, String encoded) throws IOException { testStreamingEncoding(encoding, decoded, encoded); // test separators work for (int sepLength = 3; sepLength <= 5; sepLength++) { for (String separator : ImmutableList.of(",", "\n", ";;", "")) { testStreamingEncoding( encoding.withSeparator(separator, sepLength), decoded, Joiner.on(separator).join(Splitter.fixedLength(sepLength).split(encoded))); } } }
/** * split the string into a list of characters * this duplicates some of the functionalility of makeStrings * added because it wasn't obvious that makeString would give * you characters when no seperator was present */ public static List<String> characters(String s) { if (s == null) { return ImmutableList.of(); } return ImmutableList.copyOf(Splitter.fixedLength(1).split(s)); }
public static List<Double> makeNumbers(String s, String separator) { if (s == null || s.length() == 0) { return ImmutableList.of(); } Iterable<String> parts; if (separator == null || separator.isEmpty()) parts = Splitter.fixedLength(1).split(s); else parts = Splitter.on(separator).split(s); ArrayList<Double> numbers = new ArrayList<Double>(); for (String part : parts) { numbers.add(Double.parseDouble(part)); } return ImmutableList.copyOf(numbers); }
/** * Make a list of strings from a big string with separators. * Whitespace is not stripped. * * @param s The input string, e.g. "a;b;c" * @param separator The separator, e.g. ";". If the separator is empty, return each character separately. * @return A list of strings. */ public static List<String> makeStrings(String s, String separator) { if (s == null) { return ImmutableList.of(); } if (separator == null || separator.isEmpty()) { return ImmutableList.copyOf(Splitter.fixedLength(1).split(s)); } return ImmutableList.copyOf(Splitter.on(separator).split(s)); }
protected String[] splitFixedLength(String line, int length) { Iterable<String> splitIter = Splitter.fixedLength(length).split(line); List<String> tok = new ArrayList<>(); Iterables.addAll(tok, splitIter); return Iterables.toArray(tok, String.class); }
private static String pem(byte[] encoded, String marker) { String ls = System.getProperty("line.separator"); StringBuilder builder = new StringBuilder(); builder.append(marker).append(ls); builder.append(on(ls).join(fixedLength(64).split(base64().encode(encoded)))).append(ls); builder.append(marker.replace("BEGIN", "END")).append(ls); return builder.toString(); }
private static String pem(byte[] encoded, String marker) { String ls = System.getProperty("line.separator"); StringBuilder builder = new StringBuilder(); builder.append(marker).append(ls); builder.append(on(ls).join(fixedLength(64).split(base64().encode(encoded)))).append(ls); builder.append(marker.replace("BEGIN", "END")).append(ls); return builder.toString(); }