Browse Source

change to wrapAllWithPair

Looly 5 years ago
parent
commit
50837bf2f9

+ 1 - 0
CHANGELOG.md

@@ -17,6 +17,7 @@
 * 【core  】     增加Ipv4Util(pr#161@Gitee)
 * 【core  】     增加CalendarUtil和DateUtil增加isSameMonth方法(pr#161@Gitee)
 * 【core  】     Dict增加of方法(issue#1035@Github)
+* 【core  】     StrUtil.wrapAll方法不明确修改改为wrapAllWithPair(issue#1042@Github)
 
 ### Bug修复#
 * 【poi   】     修复ExcelBase.isXlsx方法判断问题(issue#I1S502@Gitee)

+ 6 - 6
hutool-core/src/main/java/cn/hutool/core/util/StrUtil.java

@@ -2731,14 +2731,14 @@ public class StrUtil {
 	}
 
 	/**
-	 * 包装多个字符串
+	 * 使用单个字符包装多个字符串
 	 *
 	 * @param prefixAndSuffix 前缀和后缀
 	 * @param strs            多个字符串
 	 * @return 包装的字符串数组
-	 * @since 4.0.7
+	 * @since 5.4.1
 	 */
-	public static String[] wrapAll(CharSequence prefixAndSuffix, CharSequence... strs) {
+	public static String[] wrapAllWithPair(CharSequence prefixAndSuffix, CharSequence... strs) {
 		return wrapAll(prefixAndSuffix, prefixAndSuffix, strs);
 	}
 
@@ -2792,14 +2792,14 @@ public class StrUtil {
 	}
 
 	/**
-	 * 包装多个字符串,如果已经包装,则不再包装
+	 * 使用成对的字符包装多个字符串,如果已经包装,则不再包装
 	 *
 	 * @param prefixAndSuffix 前缀和后缀
 	 * @param strs            多个字符串
 	 * @return 包装的字符串数组
-	 * @since 4.0.7
+	 * @since 5.4.1
 	 */
-	public static String[] wrapAllIfMissing(CharSequence prefixAndSuffix, CharSequence... strs) {
+	public static String[] wrapAllWithPairIfMissing(CharSequence prefixAndSuffix, CharSequence... strs) {
 		return wrapAllIfMissing(prefixAndSuffix, prefixAndSuffix, strs);
 	}
 

+ 9 - 0
hutool-core/src/test/java/cn/hutool/core/util/StrUtilTest.java

@@ -458,4 +458,13 @@ public class StrUtilTest {
 		String cleanBlank = StrUtil.filter("	 你 好 ", c -> !CharUtil.isBlankChar(c));
 		Assert.assertEquals("你好", cleanBlank);
 	}
+
+	@Test
+	public void wrapAllTest(){
+		String[] strings = StrUtil.wrapAll("`", "`", StrUtil.splitToArray("1,2,3,4", ','));
+		Assert.assertEquals("[`1`, `2`, `3`, `4`]", StrUtil.utf8Str(strings));
+
+		strings = StrUtil.wrapAllWithPair("`", StrUtil.splitToArray("1,2,3,4", ','));
+		Assert.assertEquals("[`1`, `2`, `3`, `4`]", StrUtil.utf8Str(strings));
+	}
 }