@Test public void testSafeSplit() { Assert.assertEquals( Arrays.asList("1234567890", "abcdefghij"), CodeTransformations.safeSplit("1234567890abcdefghij", 10)); Assert.assertEquals( Arrays.asList("1234567890", "abcdefghij", "AB"), CodeTransformations.safeSplit("1234567890abcdefghijAB", 10)); Assert.assertEquals(Collections.singletonList("1234567890"), CodeTransformations.safeSplit("1234567890", 10)); Assert.assertEquals( Arrays.asList("12345678", "9'abcdefgh", "ij"), CodeTransformations.safeSplit("123456789'abcdefghij", 10)); Assert.assertEquals( Arrays.asList("xx\\u1234xx", "xxxxxxxxxx"), CodeTransformations.safeSplit("xx\\u1234xxxxxxxxxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxx\\u1234", "xxxxxxxxxx"), CodeTransformations.safeSplit("xxxx\\u1234xxxxxxxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxx","x\\u1234xxx", "xxxxxx"), CodeTransformations.safeSplit("xxxxx\\u1234xxxxxxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxx","x\\u1234xxx", "xxxxx"), CodeTransformations.safeSplit("xxxxxx\\u1234xxxxxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxxx","x\\u1234xxx", "xxxx"), CodeTransformations.safeSplit("xxxxxxx\\u1234xxxxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxxxx","x\\u1234xxx", "xxx"), CodeTransformations.safeSplit("xxxxxxxx\\u1234xxxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxxxxx","x\\u1234xxx", "xx"), CodeTransformations.safeSplit("xxxxxxxxx\\u1234xxxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxxxxxx","x\\u1234xxx", "x"), CodeTransformations.safeSplit("xxxxxxxxxx\\u1234xxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxxxxxx","x\\u1234xxx", "x"), CodeTransformations.safeSplit("xxxxxxxxxx\\u1234xxxx", 10)); Assert.assertEquals( Arrays.asList("xxxxxxxxxx","x\\u1234xxx"), CodeTransformations.safeSplit("xxxxxxxxxxx\\u1234xxx", 10)); }
static List<String> safeSplit(String javaStringLiteral, int maxChunkSize) { String remainder = javaStringLiteral; List<String> results = new ArrayList<>(remainder.length() / maxChunkSize); while (remainder.length() > maxChunkSize) { int cutIndex = maxChunkSize; while (cutIndex > 0 && escapesNear(remainder, cutIndex)) { cutIndex--; } if (cutIndex <= 0) { throw new IllegalStateException("unable to split " + javaStringLiteral); } String piece = remainder.substring(0, cutIndex); results.add(piece); remainder = remainder.substring(cutIndex); } if (!remainder.isEmpty()) { results.add(remainder); } return results; }
CodeTransformations { static List<String> safeSplit(String javaStringLiteral, int maxChunkSize) { String remainder = javaStringLiteral; List<String> results = new ArrayList<>(remainder.length() / maxChunkSize); while (remainder.length() > maxChunkSize) { int cutIndex = maxChunkSize; while (cutIndex > 0 && escapesNear(remainder, cutIndex)) { cutIndex--; } if (cutIndex <= 0) { throw new IllegalStateException("unable to split " + javaStringLiteral); } String piece = remainder.substring(0, cutIndex); results.add(piece); remainder = remainder.substring(cutIndex); } if (!remainder.isEmpty()) { results.add(remainder); } return results; } }
CodeTransformations { static List<String> safeSplit(String javaStringLiteral, int maxChunkSize) { String remainder = javaStringLiteral; List<String> results = new ArrayList<>(remainder.length() / maxChunkSize); while (remainder.length() > maxChunkSize) { int cutIndex = maxChunkSize; while (cutIndex > 0 && escapesNear(remainder, cutIndex)) { cutIndex--; } if (cutIndex <= 0) { throw new IllegalStateException("unable to split " + javaStringLiteral); } String piece = remainder.substring(0, cutIndex); results.add(piece); remainder = remainder.substring(cutIndex); } if (!remainder.isEmpty()) { results.add(remainder); } return results; }  }
CodeTransformations { static List<String> safeSplit(String javaStringLiteral, int maxChunkSize) { String remainder = javaStringLiteral; List<String> results = new ArrayList<>(remainder.length() / maxChunkSize); while (remainder.length() > maxChunkSize) { int cutIndex = maxChunkSize; while (cutIndex > 0 && escapesNear(remainder, cutIndex)) { cutIndex--; } if (cutIndex <= 0) { throw new IllegalStateException("unable to split " + javaStringLiteral); } String piece = remainder.substring(0, cutIndex); results.add(piece); remainder = remainder.substring(cutIndex); } if (!remainder.isEmpty()) { results.add(remainder); } return results; }  static String transformFixedClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformEnumClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformParseCalls(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String addGetClassSchemaMethod(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String removeBuilderSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeBinaryMessageCodecSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeAvroGeneratedAnnotation(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformExternalizableSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformCustomCodersSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); }
CodeTransformations { static List<String> safeSplit(String javaStringLiteral, int maxChunkSize) { String remainder = javaStringLiteral; List<String> results = new ArrayList<>(remainder.length() / maxChunkSize); while (remainder.length() > maxChunkSize) { int cutIndex = maxChunkSize; while (cutIndex > 0 && escapesNear(remainder, cutIndex)) { cutIndex--; } if (cutIndex <= 0) { throw new IllegalStateException("unable to split " + javaStringLiteral); } String piece = remainder.substring(0, cutIndex); results.add(piece); remainder = remainder.substring(cutIndex); } if (!remainder.isEmpty()) { results.add(remainder); } return results; }  static String transformFixedClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformEnumClass(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformParseCalls(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String addGetClassSchemaMethod(
      String code,
      AvroVersion generatedWith,
      AvroVersion minSupportedVersion,
      AvroVersion maxSupportedVersion
  ); static String removeBuilderSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeBinaryMessageCodecSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String removeAvroGeneratedAnnotation(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformExternalizableSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion); static String transformCustomCodersSupport(String code, AvroVersion minSupportedVersion, AvroVersion maxSupportedVersion);  }