This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-text.git
commit 4e421276f45c6c36cc9f045c792855770190809e Author: Gary Gregory <[email protected]> AuthorDate: Tue Jun 2 08:15:53 2026 -0400 Reuse CharUtils.isOctal() --- .../apache/commons/text/translate/OctalUnescaper.java | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java b/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java index 9d787267..a5c97a2c 100644 --- a/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java +++ b/src/main/java/org/apache/commons/text/translate/OctalUnescaper.java @@ -19,6 +19,8 @@ package org.apache.commons.text.translate; import java.io.IOException; import java.io.Writer; +import org.apache.commons.lang3.CharUtils; + /** * Translate escaped octal Strings back to their octal values. * @@ -38,16 +40,6 @@ public class OctalUnescaper extends CharSequenceTranslator { // empty } - /** - * Tests if the given char is an octal digit. Octal digits are the character representations of the digits 0 to 7. - * - * @param ch the char to check. - * @return true if the given char is the character representation of one of the digits from 0 to 7. - */ - private boolean isOctalDigit(final char ch) { - return ch >= '0' && ch <= '7'; - } - /** * Tests if the given char is the character representation of one of the digit from 0 to 3. * @@ -65,7 +57,7 @@ public class OctalUnescaper extends CharSequenceTranslator { public int translate(final CharSequence input, final int index, final Writer writer) throws IOException { final int remaining = input.length() - index - 1; // how many characters left, ignoring the first \ final StringBuilder builder = new StringBuilder(); - if (input.charAt(index) == '\\' && remaining > 0 && isOctalDigit(input.charAt(index + 1))) { + if (input.charAt(index) == '\\' && remaining > 0 && CharUtils.isOctal(input.charAt(index + 1))) { final int next = index + 1; final int next2 = index + 2; final int next3 = index + 3; @@ -73,9 +65,9 @@ public class OctalUnescaper extends CharSequenceTranslator { // we know this is good as we checked it in the if block above builder.append(input.charAt(next)); - if (remaining > 1 && isOctalDigit(input.charAt(next2))) { + if (remaining > 1 && CharUtils.isOctal(input.charAt(next2))) { builder.append(input.charAt(next2)); - if (remaining > 2 && isZeroToThree(input.charAt(next)) && isOctalDigit(input.charAt(next3))) { + if (remaining > 2 && isZeroToThree(input.charAt(next)) && CharUtils.isOctal(input.charAt(next3))) { builder.append(input.charAt(next3)); } }
