LANG-1336: Add NUL Byte To CharUtils. Thanks to Beluga Behr.
This commit is contained in:
parent
21bab1d3a0
commit
ad648cf8a8
|
@ -46,6 +46,7 @@ The <action> type attribute can be add,update,fix,remove.
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<release version="3.6" date="2017-MM-DD" description="TBD">
|
<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-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-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>
|
<action issue="LANG-1334" type="update" dev="djones">Deprecate CharEncoding in favour of java.nio.charset.StandardCharsets</action>
|
||||||
|
|
|
@ -50,6 +50,12 @@ public class CharUtils {
|
||||||
*/
|
*/
|
||||||
public static final char CR = '\r';
|
public static final char CR = '\r';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code \u0000} null control character ('\0'), abbreviated NUL.
|
||||||
|
*
|
||||||
|
* @since 3.6
|
||||||
|
*/
|
||||||
|
public static final char NUL = '\0';
|
||||||
|
|
||||||
static {
|
static {
|
||||||
for (char c = 0; c < CHAR_STRING_ARRAY.length; c++) {
|
for (char c = 0; c < CHAR_STRING_ARRAY.length; c++) {
|
||||||
|
|
|
@ -9009,7 +9009,7 @@ public class StringUtils {
|
||||||
*/
|
*/
|
||||||
public static String wrap(final String str, final char wrapWith) {
|
public static String wrap(final String str, final char wrapWith) {
|
||||||
|
|
||||||
if (isEmpty(str) || wrapWith == '\0') {
|
if (isEmpty(str) || wrapWith == CharUtils.NUL) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9080,7 +9080,7 @@ public class StringUtils {
|
||||||
* @since 3.5
|
* @since 3.5
|
||||||
*/
|
*/
|
||||||
public static String wrapIfMissing(final String str, final char wrapWith) {
|
public static String wrapIfMissing(final String str, final char wrapWith) {
|
||||||
if (isEmpty(str) || wrapWith == '\0') {
|
if (isEmpty(str) || wrapWith == CharUtils.NUL) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
final StringBuilder builder = new StringBuilder(str.length() + 2);
|
final StringBuilder builder = new StringBuilder(str.length() + 2);
|
||||||
|
@ -9205,7 +9205,7 @@ public class StringUtils {
|
||||||
* @since 3.6
|
* @since 3.6
|
||||||
*/
|
*/
|
||||||
public static String unwrap(final String str, final char wrapChar) {
|
public static String unwrap(final String str, final char wrapChar) {
|
||||||
if (isEmpty(str) || wrapChar == '\0') {
|
if (isEmpty(str) || wrapChar == CharUtils.NUL) {
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
|
import org.apache.commons.lang3.CharUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.commons.lang3.builder.Builder;
|
import org.apache.commons.lang3.builder.Builder;
|
||||||
|
|
||||||
|
@ -213,7 +214,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable, Build
|
||||||
final int newEnd = length;
|
final int newEnd = length;
|
||||||
size = length;
|
size = length;
|
||||||
for (int i = oldEnd; i < newEnd; i++) {
|
for (int i = oldEnd; i < newEnd; i++) {
|
||||||
buffer[i] = '\0';
|
buffer[i] = CharUtils.NUL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -3106,10 +3106,10 @@ public class StringUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrap_StringChar() {
|
public void testWrap_StringChar() {
|
||||||
assertNull(StringUtils.wrap(null, '\0'));
|
assertNull(StringUtils.wrap(null, CharUtils.NUL));
|
||||||
assertNull(StringUtils.wrap(null, '1'));
|
assertNull(StringUtils.wrap(null, '1'));
|
||||||
|
|
||||||
assertEquals("", StringUtils.wrap("", '\0'));
|
assertEquals("", StringUtils.wrap("", CharUtils.NUL));
|
||||||
assertEquals("xabx", StringUtils.wrap("ab", 'x'));
|
assertEquals("xabx", StringUtils.wrap("ab", 'x'));
|
||||||
assertEquals("\"ab\"", StringUtils.wrap("ab", '\"'));
|
assertEquals("\"ab\"", StringUtils.wrap("ab", '\"'));
|
||||||
assertEquals("\"\"ab\"\"", StringUtils.wrap("\"ab\"", '\"'));
|
assertEquals("\"\"ab\"\"", StringUtils.wrap("\"ab\"", '\"'));
|
||||||
|
@ -3121,10 +3121,10 @@ public class StringUtilsTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testWrapIfMissing_StringChar() {
|
public void testWrapIfMissing_StringChar() {
|
||||||
assertNull(StringUtils.wrapIfMissing(null, '\0'));
|
assertNull(StringUtils.wrapIfMissing(null, CharUtils.NUL));
|
||||||
assertNull(StringUtils.wrapIfMissing(null, '1'));
|
assertNull(StringUtils.wrapIfMissing(null, '1'));
|
||||||
|
|
||||||
assertEquals("", StringUtils.wrapIfMissing("", '\0'));
|
assertEquals("", StringUtils.wrapIfMissing("", CharUtils.NUL));
|
||||||
assertEquals("xabx", StringUtils.wrapIfMissing("ab", 'x'));
|
assertEquals("xabx", StringUtils.wrapIfMissing("ab", 'x'));
|
||||||
assertEquals("\"ab\"", StringUtils.wrapIfMissing("ab", '\"'));
|
assertEquals("\"ab\"", StringUtils.wrapIfMissing("ab", '\"'));
|
||||||
assertEquals("\"ab\"", StringUtils.wrapIfMissing("\"ab\"", '\"'));
|
assertEquals("\"ab\"", StringUtils.wrapIfMissing("\"ab\"", '\"'));
|
||||||
|
@ -3202,7 +3202,7 @@ public class StringUtilsTest {
|
||||||
@Test
|
@Test
|
||||||
public void testUnwrap_StringChar() {
|
public void testUnwrap_StringChar() {
|
||||||
assertNull(StringUtils.unwrap(null, null));
|
assertNull(StringUtils.unwrap(null, null));
|
||||||
assertNull(StringUtils.unwrap(null, '\0'));
|
assertNull(StringUtils.unwrap(null, CharUtils.NUL));
|
||||||
assertNull(StringUtils.unwrap(null, '1'));
|
assertNull(StringUtils.unwrap(null, '1'));
|
||||||
|
|
||||||
assertEquals("abc", StringUtils.unwrap("abc", null));
|
assertEquals("abc", StringUtils.unwrap("abc", null));
|
||||||
|
|
Loading…
Reference in New Issue