Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/main/java/org/apache/commons/lang3/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2076,11 +2076,12 @@ public static String getDigits(final String str) {
final char[] buffer = new char[len];
int count = 0;

for (int i = 0; i < len; i++) {
final char tempChar = str.charAt(i);
if (Character.isDigit(tempChar)) {
buffer[count++] = tempChar;
for (int i = 0; i < len;) {
final int codePoint = str.codePointAt(i);
if (Character.isDigit(codePoint)) {
count += Character.toChars(codePoint, buffer, count);
}
i += Character.charCount(codePoint);
}
return new String(buffer, 0, count);
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,14 @@ void testGetDigitsKeycaps() {
assertEquals("0123456789", StringUtils.getDigits("0️⃣1️⃣2️⃣3️⃣4️⃣5️⃣6️⃣7️⃣8️⃣9️⃣#️⃣"));
}

@Test
void testGetDigitsSupplementary() {
// U+1D7CF MATHEMATICAL BOLD DIGIT ONE: Character.isDigit is true but it is a surrogate pair
final String mathOne = new String(Character.toChars(0x1D7CF));
assertEquals(mathOne, StringUtils.getDigits(mathOne));
assertEquals(mathOne + "9", StringUtils.getDigits("a" + mathOne + "9"));
}

@Test
void testGetFuzzyDistance() {
assertEquals(0, StringUtils.getFuzzyDistance("", "", Locale.ENGLISH));
Expand Down
Loading