mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
fix code
This commit is contained in:
parent
cb703d6a3f
commit
f363971187
@ -4141,7 +4141,7 @@ public class CharSequenceUtil extends StrChecker {
|
||||
* @return 字符串1和字符串2的公共前缀
|
||||
*/
|
||||
public static CharSequence commonPrefix(final CharSequence str1, final CharSequence str2) {
|
||||
if (isBlank(str1) || isBlank(str2)) {
|
||||
if (isEmpty(str1) || isEmpty(str2)) {
|
||||
return EMPTY;
|
||||
}
|
||||
final int minLength = Math.min(str1.length(), str2.length());
|
||||
@ -4165,7 +4165,7 @@ public class CharSequenceUtil extends StrChecker {
|
||||
* @return 字符串1和字符串2的公共后缀
|
||||
*/
|
||||
public static CharSequence commonSuffix(final CharSequence str1, final CharSequence str2) {
|
||||
if (isBlank(str1) || isBlank(str2)) {
|
||||
if (isEmpty(str1) || isEmpty(str2)) {
|
||||
return EMPTY;
|
||||
}
|
||||
int str1Index = str1.length() - 1;
|
||||
|
@ -243,6 +243,14 @@ public class CharSequenceUtilTest {
|
||||
|
||||
Assert.assertEquals("中文", CharSequenceUtil.commonPrefix("中文english", "中文french"));
|
||||
|
||||
// { space * 10 } + "abc"
|
||||
final String str1 = CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10) + "abc";
|
||||
|
||||
// { space * 5 } + "efg"
|
||||
final String str2 = CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 5) + "efg";
|
||||
|
||||
// Expect common prefix: { space * 5 }
|
||||
Assert.assertEquals(CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 5), CharSequenceUtil.commonPrefix(str1, str2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -267,5 +275,13 @@ public class CharSequenceUtilTest {
|
||||
|
||||
Assert.assertEquals("中文", CharSequenceUtil.commonSuffix("english中文", "Korean中文"));
|
||||
|
||||
// "abc" + { space * 10 }
|
||||
final String str1 = "abc" + CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10);
|
||||
|
||||
// "efg" + { space * 15 }
|
||||
final String str2 = "efg" + CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 15);
|
||||
|
||||
// Expect common suffix: { space * 10 }
|
||||
Assert.assertEquals(CharSequenceUtil.repeat(CharSequenceUtil.SPACE, 10), CharSequenceUtil.commonSuffix(str1, str2));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user