add method

This commit is contained in:
Looly
2021-11-24 23:10:59 +08:00
parent ff8317dd8c
commit 30515f0351
3 changed files with 36 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
package cn.hutool.core.text;
import cn.hutool.core.util.CharsetUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -65,4 +66,16 @@ public class CharSequenceUtilTest {
index = CharSequenceUtil.indexOf("abc123", 'b', 0, 3);
Assert.assertEquals(1, index);
}
@Test
public void subPreGbkTest(){
// https://gitee.com/dromara/hutool/issues/I4JO2E
String s = "华硕K42Intel酷睿i31代2G以下独立显卡不含机械硬盘固态硬盘120GB-192GB4GB-6GB";
String v = CharSequenceUtil.subPreGbk(s, 40, false);
Assert.assertEquals(39, v.getBytes(CharsetUtil.CHARSET_GBK).length);
v = CharSequenceUtil.subPreGbk(s, 40, true);
Assert.assertEquals(41, v.getBytes(CharsetUtil.CHARSET_GBK).length);
}
}