mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
add method
This commit is contained in:
parent
7db5d0f31f
commit
2505a7d4dd
@ -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;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user