StringUtils { @Nonnull public static int[] toCodePoints(@Nonnull final String s) { assert s != null; final int[] codePoints = new int[s.codePointCount(0, s.length())]; assert codePoints != null; assert codePoints.length <= s.length(); int stringIndex = 0; for (int codePointsIndex = 0; codePointsIndex < codePoints.length; codePointsIndex++) { codePoints[codePointsIndex] = s.codePointAt(stringIndex); stringIndex += Character.charCount(codePoints[codePointsIndex]); } return codePoints; } private  StringUtils(); @Nonnull static String nullToEmpty(@Nullable final String s); @Nullable static String emptyToNull(@Nullable final String s); @Nullable static String trim(@Nullable final String s); @Nullable static List<String> trim(@Nullable final List<String> sList); @Nullable static Set<String> trim(@Nullable final Set<String> sSet); @Nullable static String literalToLowerCase(@Nullable final String s); @Nonnull static int[] toCodePoints(@Nonnull final String s); @Nonnull static String mkString(@Nonnull final String separator, @Nonnull final Collection<?> values); @Nonnull static String mkRevString(@Nonnull final String separator, @Nonnull final Collection<T> values); @SafeVarargs @Nonnull static String mkString(@Nonnull final String separator, @Nonnull final T... values); @SafeVarargs @Nonnull static String mkRevString(@Nonnull final String separator, @Nonnull final T... values); @Nonnull static String generateRandomStringFromChars(@Nonnull final char[] chars, final int length); @SuppressWarnings("ConstantConditions") @Nonnull static String encodeToJsonString(@Nonnull final String input); @Nullable static String decodeFromJsonString(@Nonnull final String input);  }
@Test public void testToCodePoints() { LOG.info("testToCodePoints"); final String[] strings = { "", "a", "\uD801\uDC00", "aa", "\uD801\uDC00a", "a\uD801\uDC00", "\uD801\uDC00\uD801\uDC00", "aaa", "\uD801\uDC00aa", "a\uD801\uDC00a", "aa\uD801\uDC00", "\uD801\uDC00\uD801\uDC00a", "a\uD801\uDC00\uD801\uDC00", "\uD801\uDC00a\uD801\uDC00", "\uD801\uDC00\uD801\uDC00\uD801\uDC00" }; final int[][] codePoints = { {}, {0x61}, {0x10400}, {0x61, 0x61}, {0x10400, 0x61}, {0x61, 0x10400}, {0x10400, 0x10400}, {0x61, 0x61, 0x61}, {0x10400, 0x61, 0x61}, {0x61, 0x10400, 0x61}, {0x61, 0x61, 0x10400}, {0x10400, 0x10400, 0x61}, {0x61, 0x10400, 0x10400}, {0x10400, 0x61, 0x10400}, {0x10400, 0x10400, 0x10400} }; assert strings.length == codePoints.length; for (int i = 0; i < strings.length; i++) { LOG.debug("testToCodePoints: strings[{}]=\"{}\", expected={}", i, strings[i], codePoints[i]); Assert.assertArrayEquals(codePoints[i], StringUtils.toCodePoints(strings[i])); } }