commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brit...@apache.org
Subject [41/48] [lang] LANG-1336: Add NUL Byte To CharUtils. Thanks to Beluga Behr.
Date Thu, 08 Jun 2017 08:16:15 GMT
LANG-1336: Add NUL Byte To CharUtils. Thanks to Beluga Behr.


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/ad648cf8
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/ad648cf8
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/ad648cf8

Branch: refs/heads/release
Commit: ad648cf8a8a90bdee129266ca7b686a5b9a87561
Parents: 21bab1d
Author: Benedikt Ritter <britter@apache.org>
Authored: Wed Jun 7 09:54:34 2017 +0200
Committer: Benedikt Ritter <britter@apache.org>
Committed: Wed Jun 7 09:59:12 2017 +0200

----------------------------------------------------------------------
 src/changes/changes.xml                                   |  1 +
 src/main/java/org/apache/commons/lang3/CharUtils.java     |  6 ++++++
 src/main/java/org/apache/commons/lang3/StringUtils.java   |  6 +++---
 .../java/org/apache/commons/lang3/text/StrBuilder.java    |  3 ++-
 .../java/org/apache/commons/lang3/StringUtilsTest.java    | 10 +++++-----
 5 files changed, 17 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ad648cf8/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 4496b9b..b005ab6 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
   <body>
 
   <release version="3.6" date="2017-MM-DD" description="TBD">
+    <action issue="LANG-1336" type="add" dev="britter" due-to="Beluga Behr">Add NUL
Byte To CharUtils</action>
     <action issue="LANG-1337" type="fix" dev="kinow">Fix test failures in IBM JDK 8
for ToStringBuilderTest</action>
     <action issue="LANG-1304" type="add" dev="pschumacher" due-to="Andy Klimczak">Add
method in StringUtils to determine if string contains both mixed cased characters</action>
     <action issue="LANG-1334" type="update" dev="djones">Deprecate CharEncoding in
favour of java.nio.charset.StandardCharsets</action>

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ad648cf8/src/main/java/org/apache/commons/lang3/CharUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/CharUtils.java b/src/main/java/org/apache/commons/lang3/CharUtils.java
index f697c08..51b347a 100644
--- a/src/main/java/org/apache/commons/lang3/CharUtils.java
+++ b/src/main/java/org/apache/commons/lang3/CharUtils.java
@@ -50,6 +50,12 @@ public class CharUtils {
      */
     public static final char CR = '\r';
 
+    /**
+     * {@code \u0000} null control character ('\0'), abbreviated NUL.
+     *
+     * @since 3.6
+     */
+    public static final char NUL = '\0';
 
     static {
         for (char c = 0; c < CHAR_STRING_ARRAY.length; c++) {

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ad648cf8/src/main/java/org/apache/commons/lang3/StringUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/StringUtils.java b/src/main/java/org/apache/commons/lang3/StringUtils.java
index f98433a..97a073f 100644
--- a/src/main/java/org/apache/commons/lang3/StringUtils.java
+++ b/src/main/java/org/apache/commons/lang3/StringUtils.java
@@ -9009,7 +9009,7 @@ public class StringUtils {
      */
     public static String wrap(final String str, final char wrapWith) {
 
-        if (isEmpty(str) || wrapWith == '\0') {
+        if (isEmpty(str) || wrapWith == CharUtils.NUL) {
             return str;
         }
 
@@ -9080,7 +9080,7 @@ public class StringUtils {
      * @since 3.5
      */
     public static String wrapIfMissing(final String str, final char wrapWith) {
-        if (isEmpty(str) || wrapWith == '\0') {
+        if (isEmpty(str) || wrapWith == CharUtils.NUL) {
             return str;
         }
         final StringBuilder builder = new StringBuilder(str.length() + 2);
@@ -9205,7 +9205,7 @@ public class StringUtils {
      * @since 3.6
      */
     public static String unwrap(final String str, final char wrapChar) {
-        if (isEmpty(str) || wrapChar == '\0') {
+        if (isEmpty(str) || wrapChar == CharUtils.NUL) {
             return str;
         }
 

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ad648cf8/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
index 4e69cd5..cf42495 100644
--- a/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
+++ b/src/main/java/org/apache/commons/lang3/text/StrBuilder.java
@@ -26,6 +26,7 @@ import java.util.List;
 import java.util.Objects;
 
 import org.apache.commons.lang3.ArrayUtils;
+import org.apache.commons.lang3.CharUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.builder.Builder;
 
@@ -213,7 +214,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable,
Build
             final int newEnd = length;
             size = length;
             for (int i = oldEnd; i < newEnd; i++) {
-                buffer[i] = '\0';
+                buffer[i] = CharUtils.NUL;
             }
         }
         return this;

http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ad648cf8/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
index aa9ec73..615030e 100644
--- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
@@ -3106,10 +3106,10 @@ public class StringUtilsTest {
 
     @Test
     public void testWrap_StringChar() {
-        assertNull(StringUtils.wrap(null, '\0'));
+        assertNull(StringUtils.wrap(null, CharUtils.NUL));
         assertNull(StringUtils.wrap(null, '1'));
 
-        assertEquals("", StringUtils.wrap("", '\0'));
+        assertEquals("", StringUtils.wrap("", CharUtils.NUL));
         assertEquals("xabx", StringUtils.wrap("ab", 'x'));
         assertEquals("\"ab\"", StringUtils.wrap("ab", '\"'));
         assertEquals("\"\"ab\"\"", StringUtils.wrap("\"ab\"", '\"'));
@@ -3121,10 +3121,10 @@ public class StringUtilsTest {
 
     @Test
     public void testWrapIfMissing_StringChar() {
-        assertNull(StringUtils.wrapIfMissing(null, '\0'));
+        assertNull(StringUtils.wrapIfMissing(null, CharUtils.NUL));
         assertNull(StringUtils.wrapIfMissing(null, '1'));
 
-        assertEquals("", StringUtils.wrapIfMissing("", '\0'));
+        assertEquals("", StringUtils.wrapIfMissing("", CharUtils.NUL));
         assertEquals("xabx", StringUtils.wrapIfMissing("ab", 'x'));
         assertEquals("\"ab\"", StringUtils.wrapIfMissing("ab", '\"'));
         assertEquals("\"ab\"", StringUtils.wrapIfMissing("\"ab\"", '\"'));
@@ -3202,7 +3202,7 @@ public class StringUtilsTest {
     @Test
     public void testUnwrap_StringChar() {
         assertNull(StringUtils.unwrap(null, null));
-        assertNull(StringUtils.unwrap(null, '\0'));
+        assertNull(StringUtils.unwrap(null, CharUtils.NUL));
         assertNull(StringUtils.unwrap(null, '1'));
 
         assertEquals("abc", StringUtils.unwrap("abc", null));


Mime
View raw message