mirror of
https://gitee.com/dromara/hutool.git
synced 2026-02-09 09:16:26 +08:00
修复StrBuilderinsert插入计算错误问题(issue#ICTSRZ@Gitee)
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.40(2025-08-19)
|
# 5.8.40(2025-08-20)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【captcha】 `MathGenerator`四则运算方式支持不生成负数结果(pr#1363@Gitee)
|
* 【captcha】 `MathGenerator`四则运算方式支持不生成负数结果(pr#1363@Gitee)
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
* 【core 】 修复`ChineseDate `闰年闰月节日获取问题(issue#ICL1BT@Gitee)
|
* 【core 】 修复`ChineseDate `闰年闰月节日获取问题(issue#ICL1BT@Gitee)
|
||||||
* 【core 】 修复`TreeBuilder`append重复向idTreeMap中put问题(pr#3992@Github)
|
* 【core 】 修复`TreeBuilder`append重复向idTreeMap中put问题(pr#3992@Github)
|
||||||
* 【extra 】 修复`QLExpressEngine`allowClassSet无效问题(issue#3994@Github)
|
* 【extra 】 修复`QLExpressEngine`allowClassSet无效问题(issue#3994@Github)
|
||||||
|
* 【core 】 修复`StrBuilder`insert插入计算错误问题(issue#ICTSRZ@Gitee)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.39(2025-06-20)
|
# 5.8.39(2025-06-20)
|
||||||
|
|||||||
@@ -271,7 +271,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
|||||||
} else if (csq instanceof StrBuilder) {
|
} else if (csq instanceof StrBuilder) {
|
||||||
((StrBuilder) csq).getChars(0, len, this.value, index);
|
((StrBuilder) csq).getChars(0, len, this.value, index);
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0, j = this.position; i < len; i++, j++) {
|
for (int i = 0, j = index; i < len; i++, j++) {
|
||||||
this.value[j] = csq.charAt(i);
|
this.value[j] = csq.charAt(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -316,7 +316,7 @@ public class StrBuilder implements CharSequence, Appendable, Serializable {
|
|||||||
|
|
||||||
final int length = end - start;
|
final int length = end - start;
|
||||||
moveDataAfterIndex(index, length);
|
moveDataAfterIndex(index, length);
|
||||||
for (int i = start, j = this.position; i < end; i++, j++) {
|
for (int i = start, j = index; i < end; i++, j++) {
|
||||||
value[j] = csq.charAt(i);
|
value[j] = csq.charAt(i);
|
||||||
}
|
}
|
||||||
this.position = Math.max(this.position, index) + length;
|
this.position = Math.max(this.position, index) + length;
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package cn.hutool.core.text;
|
package cn.hutool.core.text;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
import cn.hutool.core.date.TimeInterval;
|
import cn.hutool.core.date.TimeInterval;
|
||||||
import cn.hutool.core.lang.Console;
|
import cn.hutool.core.lang.Console;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* StrBuilder单元测试
|
* StrBuilder单元测试
|
||||||
@@ -116,4 +117,18 @@ public class StrBuilderTest {
|
|||||||
builder = strBuilder.delTo(0);
|
builder = strBuilder.delTo(0);
|
||||||
assertEquals("", builder.toString());
|
assertEquals("", builder.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void issueICTSRZTest() {
|
||||||
|
final StrBuilder helloWorld = StrBuilder.create("Hello World");
|
||||||
|
helloWorld.insert(6, "Beautiful ", 0, 10);
|
||||||
|
Assertions.assertEquals("Hello Beautiful World", helloWorld.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void issueICTSRZTest2() {
|
||||||
|
final StrBuilder helloWorld = StrBuilder.create("Hello World");
|
||||||
|
helloWorld.insert(6, "Beautiful ");
|
||||||
|
Assertions.assertEquals("Hello Beautiful World", helloWorld.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user