This commit is contained in:
Looly 2025-02-06 10:58:37 +08:00
parent cb91d17971
commit 1ef308674b

View File

@ -21,7 +21,6 @@ import org.dromara.hutool.core.collection.CollUtil;
import org.dromara.hutool.core.comparator.VersionComparator; import org.dromara.hutool.core.comparator.VersionComparator;
import org.dromara.hutool.core.func.SerFunction; import org.dromara.hutool.core.func.SerFunction;
import org.dromara.hutool.core.lang.Assert; import org.dromara.hutool.core.lang.Assert;
import org.dromara.hutool.core.math.NumberUtil;
import org.dromara.hutool.core.regex.ReUtil; import org.dromara.hutool.core.regex.ReUtil;
import org.dromara.hutool.core.text.finder.CharFinder; import org.dromara.hutool.core.text.finder.CharFinder;
import org.dromara.hutool.core.text.finder.CharMatcherFinder; import org.dromara.hutool.core.text.finder.CharMatcherFinder;
@ -1622,23 +1621,10 @@ public class CharSequenceUtil extends StrValidator {
* @param partLength 每等份的长度 * @param partLength 每等份的长度
* @return 切分后的数组 * @return 切分后的数组
* @since 3.0.6 * @since 3.0.6
* @see SplitUtil#splitByLength(CharSequence, int)
*/ */
public static String[] cut(final CharSequence str, final int partLength) { public static String[] cut(final CharSequence str, final int partLength) {
if (null == str) { return SplitUtil.splitByLength(str, partLength);
return null;
}
final int len = str.length();
if (len < partLength) {
return new String[]{str.toString()};
}
final int part = NumberUtil.count(len, partLength);
final String[] array = new String[part];
final String str2 = str.toString();
for (int i = 0; i < part; i++) {
array[i] = str2.substring(i * partLength, (i == part - 1) ? len : (partLength + i * partLength));
}
return array;
} }
// region ----- sub // region ----- sub