mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +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) {
|
public static int totalLength(final CharSequence... strs) {
|
||||||
int totalLength = 0;
|
int totalLength = 0;
|
||||||
for (final CharSequence str : strs) {
|
for (final CharSequence str : strs) {
|
||||||
totalLength += (null == str ? 0 : str.length());
|
totalLength += length(str);
|
||||||
}
|
}
|
||||||
return totalLength;
|
return totalLength;
|
||||||
}
|
}
|
||||||
@ -3159,7 +3159,7 @@ public class CharSequenceUtil extends StrChecker {
|
|||||||
* @return 切割后的剩余的前半部分字符串+"..."
|
* @return 切割后的剩余的前半部分字符串+"..."
|
||||||
* @since 4.0.10
|
* @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);
|
Assert.isTrue(length > 0);
|
||||||
if (null == string) {
|
if (null == string) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -345,13 +345,13 @@ public class StrUtilTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void maxLengthTest() {
|
public void limitLengthTest() {
|
||||||
final String text = "我是一段正文,很长的正文,需要截取的正文";
|
final String text = "我是一段正文,很长的正文,需要截取的正文";
|
||||||
String str = StrUtil.maxLength(text, 5);
|
String str = StrUtil.limitLength(text, 5);
|
||||||
Assertions.assertEquals("我是一段正...", str);
|
Assertions.assertEquals("我是一段正...", str);
|
||||||
str = StrUtil.maxLength(text, 21);
|
str = StrUtil.limitLength(text, 21);
|
||||||
Assertions.assertEquals(text, str);
|
Assertions.assertEquals(text, str);
|
||||||
str = StrUtil.maxLength(text, 50);
|
str = StrUtil.limitLength(text, 50);
|
||||||
Assertions.assertEquals(text, str);
|
Assertions.assertEquals(text, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user