add method

This commit is contained in:
Looly 2023-04-17 10:07:17 +08:00
parent 7db5d0f31f
commit 2505a7d4dd
2 changed files with 6 additions and 6 deletions

View File

@ -3146,7 +3146,7 @@ public class CharSequenceUtil extends StrChecker {
public static int totalLength(final CharSequence... strs) {
int totalLength = 0;
for (final CharSequence str : strs) {
totalLength += (null == str ? 0 : str.length());
totalLength += length(str);
}
return totalLength;
}
@ -3159,7 +3159,7 @@ public class CharSequenceUtil extends StrChecker {
* @return 切割后的剩余的前半部分字符串+"..."
* @since 4.0.10
*/
public static String maxLength(final CharSequence string, final int length) {
public static String limitLength(final CharSequence string, final int length) {
Assert.isTrue(length > 0);
if (null == string) {
return null;

View File

@ -345,13 +345,13 @@ public class StrUtilTest {
}
@Test
public void maxLengthTest() {
public void limitLengthTest() {
final String text = "我是一段正文,很长的正文,需要截取的正文";
String str = StrUtil.maxLength(text, 5);
String str = StrUtil.limitLength(text, 5);
Assertions.assertEquals("我是一段正...", str);
str = StrUtil.maxLength(text, 21);
str = StrUtil.limitLength(text, 21);
Assertions.assertEquals(text, str);
str = StrUtil.maxLength(text, 50);
str = StrUtil.limitLength(text, 50);
Assertions.assertEquals(text, str);
}