This commit is contained in:
Looly 2022-11-03 23:37:48 +08:00
parent b696ad4b08
commit 3b1a375096
4 changed files with 31 additions and 6 deletions

View File

@ -1810,8 +1810,21 @@ public class CharSequenceUtil extends StrChecker {
* @param length 要截取的长度
* @return 截取后的字符串
*/
public static String subWithLength(final String input, final int fromIndex, final int length) {
return sub(input, fromIndex, fromIndex + length);
public static String subByLength(final String input, final int fromIndex, final int length) {
if (isEmpty(input)) {
return null;
}
if (length <= 0) {
return EMPTY;
}
final int toIndex;
if(fromIndex < 0){
toIndex = fromIndex - length;
}else{
toIndex = fromIndex + length;
}
return sub(input, fromIndex, toIndex);
}
/**

View File

@ -1,13 +1,12 @@
package cn.hutool.core.tree;
import cn.hutool.core.lang.builder.Builder;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.tree.parser.NodeParser;
import cn.hutool.core.lang.builder.Builder;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.tree.parser.NodeParser;
import cn.hutool.core.util.ObjUtil;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@ -56,7 +55,7 @@ public class TreeBuilder<E> implements Builder<MapTree<E>> {
public TreeBuilder(final E rootId, final TreeNodeConfig config) {
root = new MapTree<>(config);
root.setId(rootId);
this.idTreeMap = new HashMap<>();
this.idTreeMap = new LinkedHashMap<>();
}
/**

View File

@ -212,4 +212,10 @@ public class CharSequenceUtilTest {
final String result = StrUtil.replaceFirst(str, "YES", "", true);
Assert.assertEquals(result, " and yes i do");
}
@Test
public void issueI5YN49Test() {
final String str = "A5E6005700000000000000000000000000000000000000090D0100000000000001003830";
Assert.assertEquals("38", StrUtil.subByLength(str,-2,2));
}
}

View File

@ -240,4 +240,11 @@ public class HttpRequestTest {
final HttpRequest a = HttpRequest.post("https://hutool.cn/").form("a", 1);
Console.log(a.toString());
}
@Test
@Ignore
public void issueI5Y68WTest() {
final HttpResponse httpResponse = HttpRequest.get("http://82.157.17.173:8100/app/getAddress").execute();
Console.log(httpResponse.body());
}
}