This commit is contained in:
Looly 2021-09-25 19:42:40 +08:00
parent ce33b3d5cb
commit 6db6d70293
2 changed files with 31 additions and 5 deletions

View File

@ -416,11 +416,7 @@ public class StrSplitter {
* @return 截取后的字符串数组 * @return 截取后的字符串数组
*/ */
public static String[] splitByLength(String text, int len) { public static String[] splitByLength(String text, int len) {
SplitIter splitIter = new SplitIter(text, SplitIter splitIter = new SplitIter(text, new LengthFinder(len), -1, false);
new LengthFinder(len),
Integer.MAX_VALUE,
false
);
return splitIter.toArray(false); return splitIter.toArray(false);
} }
//---------------------------------------------------------------------------------------------------------- Private method start //---------------------------------------------------------------------------------------------------------- Private method start

View File

@ -25,6 +25,19 @@ public class SplitIterTest {
Assert.assertEquals(6, splitIter.toList(false).size()); Assert.assertEquals(6, splitIter.toList(false).size());
} }
@Test
public void splitByCharIgnoreCaseTest(){
String str1 = "a, ,,eAedsas, ddf,";
//不忽略""
SplitIter splitIter = new SplitIter(str1,
new CharFinder('a', true),
Integer.MAX_VALUE,
false
);
Assert.assertEquals(4, splitIter.toList(false).size());
}
@Test @Test
public void splitByCharIgnoreEmptyTest(){ public void splitByCharIgnoreEmptyTest(){
String str1 = "a, ,,efedsfs, ddf,"; String str1 = "a, ,,efedsfs, ddf,";
@ -39,6 +52,23 @@ public class SplitIterTest {
Assert.assertEquals(4, strings.size()); Assert.assertEquals(4, strings.size());
} }
@Test
public void splitByCharTrimTest(){
String str1 = "a, ,,efedsfs, ddf,";
SplitIter splitIter = new SplitIter(str1,
new CharFinder(',', false),
Integer.MAX_VALUE,
true
);
final List<String> strings = splitIter.toList(true);
Assert.assertEquals(3, strings.size());
Assert.assertEquals("a", strings.get(0));
Assert.assertEquals("efedsfs", strings.get(1));
Assert.assertEquals("ddf", strings.get(2));
}
@Test @Test
public void splitByStrTest(){ public void splitByStrTest(){
String str1 = "a, ,,efedsfs, ddf,"; String str1 = "a, ,,efedsfs, ddf,";