mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-24 18:04:54 +08:00
remove StrBuilder
This commit is contained in:
parent
50e6afc59a
commit
4209cffa06
@ -3,10 +3,9 @@ package cn.hutool.core.bean;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
@ -222,7 +221,7 @@ public class BeanPath implements Serializable{
|
||||
final List<String> localPatternParts = new ArrayList<>();
|
||||
final int length = expression.length();
|
||||
|
||||
final StrBuilder builder = StrUtil.strBuilder();
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
char c;
|
||||
boolean isNumStart = false;// 下标标识符开始
|
||||
for (int i = 0; i < length; i++) {
|
||||
@ -255,7 +254,7 @@ public class BeanPath implements Serializable{
|
||||
if (builder.length() > 0) {
|
||||
localPatternParts.add(unWrapIfPossible(builder));
|
||||
}
|
||||
builder.reset();
|
||||
builder.setLength(0);
|
||||
} else {
|
||||
// 非边界符号,追加字符
|
||||
builder.append(c);
|
||||
|
@ -1,11 +1,9 @@
|
||||
package cn.hutool.core.io;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* 借助{@link StrBuilder} 提供快读的字符串写出,相比jdk的StringWriter非线程安全,速度更快。
|
||||
* 借助{@link StringBuilder} 提供快读的字符串写出,相比jdk的StringWriter非线程安全,速度更快。
|
||||
*
|
||||
* @author looly
|
||||
* @since 5.3.3
|
||||
|
@ -4248,7 +4248,7 @@ public class CharSequenceUtil {
|
||||
* @since 4.1.0
|
||||
*/
|
||||
public static String concat(final boolean isNullToEmpty, final CharSequence... strs) {
|
||||
final StrBuilder sb = new StrBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for (final CharSequence str : strs) {
|
||||
sb.append(isNullToEmpty ? nullToEmpty(str) : str);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public class NamingCase {
|
||||
}
|
||||
|
||||
final int length = str.length();
|
||||
final StrBuilder sb = new StrBuilder();
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
char c;
|
||||
for (int i = 0; i < length; i++) {
|
||||
c = str.charAt(i);
|
||||
|
@ -1,586 +0,0 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 可复用的字符串生成器,非线程安全<br>
|
||||
* TODO 6.x移除此类,java8的StringBuilder非常完善了,无需重写。
|
||||
*
|
||||
* @author Looly
|
||||
* @since 4.0.0
|
||||
*/
|
||||
public class StrBuilder implements CharSequence, Appendable, Serializable {
|
||||
private static final long serialVersionUID = 6341229705927508451L;
|
||||
|
||||
/**
|
||||
* 默认容量
|
||||
*/
|
||||
public static final int DEFAULT_CAPACITY = 16;
|
||||
|
||||
/**
|
||||
* 存放的字符数组
|
||||
*/
|
||||
private char[] value;
|
||||
/**
|
||||
* 当前指针位置,或者叫做已经加入的字符数,此位置总在最后一个字符之后
|
||||
*/
|
||||
private int position;
|
||||
|
||||
/**
|
||||
* 创建字符串构建器
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public static StrBuilder create() {
|
||||
return new StrBuilder();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字符串构建器
|
||||
*
|
||||
* @param initialCapacity 初始容量
|
||||
* @return this
|
||||
*/
|
||||
public static StrBuilder create(final int initialCapacity) {
|
||||
return new StrBuilder(initialCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建字符串构建器
|
||||
*
|
||||
* @param strs 初始字符串
|
||||
* @return this
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public static StrBuilder create(final CharSequence... strs) {
|
||||
return new StrBuilder(strs);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ Constructor start
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*/
|
||||
public StrBuilder() {
|
||||
this(DEFAULT_CAPACITY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param initialCapacity 初始容量
|
||||
*/
|
||||
public StrBuilder(final int initialCapacity) {
|
||||
value = new char[initialCapacity];
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造
|
||||
*
|
||||
* @param strs 初始字符串
|
||||
* @since 4.0.1
|
||||
*/
|
||||
public StrBuilder(final CharSequence... strs) {
|
||||
this(ArrayUtil.isEmpty(strs) ? DEFAULT_CAPACITY : (totalLength(strs) + DEFAULT_CAPACITY));
|
||||
for (final CharSequence str : strs) {
|
||||
append(str);
|
||||
}
|
||||
}
|
||||
// ------------------------------------------------------------------------------------ Constructor end
|
||||
|
||||
// ------------------------------------------------------------------------------------ Append
|
||||
|
||||
/**
|
||||
* 追加对象,对象会被转换为字符串
|
||||
*
|
||||
* @param obj 对象
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder append(final Object obj) {
|
||||
return insert(this.position, obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加一个字符
|
||||
*
|
||||
* @param c 字符
|
||||
* @return this
|
||||
*/
|
||||
@Override
|
||||
public StrBuilder append(final char c) {
|
||||
return insert(this.position, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加一个字符数组
|
||||
*
|
||||
* @param src 字符数组
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder append(final char[] src) {
|
||||
if (ArrayUtil.isEmpty(src)) {
|
||||
return this;
|
||||
}
|
||||
return append(src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加一个字符数组
|
||||
*
|
||||
* @param src 字符数组
|
||||
* @param srcPos 开始位置(包括)
|
||||
* @param length 长度
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder append(final char[] src, final int srcPos, final int length) {
|
||||
return insert(this.position, src, srcPos, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrBuilder append(final CharSequence csq) {
|
||||
return insert(this.position, csq);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StrBuilder append(final CharSequence csq, final int start, final int end) {
|
||||
return insert(this.position, csq, start, end);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ Insert
|
||||
|
||||
/**
|
||||
* 追加对象,对象会被转换为字符串
|
||||
*
|
||||
* @param index 插入位置
|
||||
* @param obj 对象
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder insert(final int index, final Object obj) {
|
||||
if (obj instanceof CharSequence) {
|
||||
return insert(index, (CharSequence) obj);
|
||||
}
|
||||
return insert(index, Convert.toStr(obj));
|
||||
}
|
||||
|
||||
/**
|
||||
* 插入指定字符
|
||||
*
|
||||
* @param index 位置
|
||||
* @param c 字符
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder insert(int index, final char c) {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
moveDataAfterIndex(index, 1);
|
||||
value[index] = c;
|
||||
this.position = Math.max(this.position, index) + 1;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定位置插入数据<br>
|
||||
* 如果插入位置为当前位置,则定义为追加<br>
|
||||
* 如果插入位置大于当前位置,则中间部分补充空格
|
||||
*
|
||||
* @param index 插入位置
|
||||
* @param src 源数组
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder insert(final int index, final char[] src) {
|
||||
if (ArrayUtil.isEmpty(src)) {
|
||||
return this;
|
||||
}
|
||||
return insert(index, src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定位置插入数据<br>
|
||||
* 如果插入位置为当前位置,则定义为追加<br>
|
||||
* 如果插入位置大于当前位置,则中间部分补充空格
|
||||
*
|
||||
* @param index 插入位置
|
||||
* @param src 源数组
|
||||
* @param srcPos 位置
|
||||
* @param length 长度
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder insert(int index, final char[] src, int srcPos, int length) {
|
||||
if (ArrayUtil.isEmpty(src) || srcPos > src.length || length <= 0) {
|
||||
return this;
|
||||
}
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
if (srcPos < 0) {
|
||||
srcPos = 0;
|
||||
} else if (srcPos + length > src.length) {
|
||||
// 长度越界,只截取最大长度
|
||||
length = src.length - srcPos;
|
||||
}
|
||||
|
||||
moveDataAfterIndex(index, length);
|
||||
// 插入数据
|
||||
System.arraycopy(src, srcPos, value, index, length);
|
||||
this.position = Math.max(this.position, index) + length;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定位置插入字符串的某个部分<br>
|
||||
* 如果插入位置为当前位置,则定义为追加<br>
|
||||
* 如果插入位置大于当前位置,则中间部分补充空格
|
||||
*
|
||||
* @param index 位置
|
||||
* @param csq 字符串
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder insert(int index, CharSequence csq) {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
if (null == csq) {
|
||||
csq = StrUtil.EMPTY;
|
||||
}
|
||||
final int len = csq.length();
|
||||
moveDataAfterIndex(index, csq.length());
|
||||
if (csq instanceof String) {
|
||||
((String) csq).getChars(0, len, this.value, index);
|
||||
} else if (csq instanceof StringBuilder) {
|
||||
((StringBuilder) csq).getChars(0, len, this.value, index);
|
||||
} else if (csq instanceof StringBuffer) {
|
||||
((StringBuffer) csq).getChars(0, len, this.value, index);
|
||||
} else if (csq instanceof StrBuilder) {
|
||||
((StrBuilder) csq).getChars(0, len, this.value, index);
|
||||
} else {
|
||||
for (int i = 0, j = this.position; i < len; i++, j++) {
|
||||
this.value[j] = csq.charAt(i);
|
||||
}
|
||||
}
|
||||
this.position = Math.max(this.position, index) + len;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 指定位置插入字符串的某个部分<br>
|
||||
* 如果插入位置为当前位置,则定义为追加<br>
|
||||
* 如果插入位置大于当前位置,则中间部分补充空格
|
||||
*
|
||||
* @param index 位置
|
||||
* @param csq 字符串
|
||||
* @param start 字符串开始位置(包括)
|
||||
* @param end 字符串结束位置(不包括)
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder insert(int index, CharSequence csq, int start, int end) {
|
||||
if (csq == null) {
|
||||
csq = "null";
|
||||
}
|
||||
final int csqLen = csq.length();
|
||||
if (start > csqLen) {
|
||||
return this;
|
||||
}
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
if (end > csqLen) {
|
||||
end = csqLen;
|
||||
}
|
||||
if (start >= end) {
|
||||
return this;
|
||||
}
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
|
||||
final int length = end - start;
|
||||
moveDataAfterIndex(index, length);
|
||||
for (int i = start, j = this.position; i < end; i++, j++) {
|
||||
value[j] = csq.charAt(i);
|
||||
}
|
||||
this.position = Math.max(this.position, index) + length;
|
||||
return this;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ Others
|
||||
|
||||
/**
|
||||
* 将指定段的字符列表写出到目标字符数组中
|
||||
*
|
||||
* @param srcBegin 起始位置(包括)
|
||||
* @param srcEnd 结束位置(不包括)
|
||||
* @param dst 目标数组
|
||||
* @param dstBegin 目标起始位置(包括)
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder getChars(int srcBegin, int srcEnd, final char[] dst, final int dstBegin) {
|
||||
if (srcBegin < 0) {
|
||||
srcBegin = 0;
|
||||
}
|
||||
if (srcEnd < 0) {
|
||||
srcEnd = 0;
|
||||
} else if (srcEnd > this.position) {
|
||||
srcEnd = this.position;
|
||||
}
|
||||
if (srcBegin > srcEnd) {
|
||||
throw new StringIndexOutOfBoundsException("srcBegin > srcEnd");
|
||||
}
|
||||
System.arraycopy(value, srcBegin, dst, dstBegin, srcEnd - srcBegin);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否有内容
|
||||
*
|
||||
* @return 是否有内容
|
||||
*/
|
||||
public boolean hasContent() {
|
||||
return position > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否为空
|
||||
*
|
||||
* @return 是否为空
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
return position == 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除全部字符,位置归零
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder clear() {
|
||||
return reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除全部字符,位置归零
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder reset() {
|
||||
this.position = 0;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除到指定位置<br>
|
||||
* 如果新位置小于等于0,则删除全部
|
||||
*
|
||||
* @param newPosition 新的位置,不包括这个位置
|
||||
* @return this
|
||||
*/
|
||||
public StrBuilder delTo(int newPosition) {
|
||||
if (newPosition < 0) {
|
||||
newPosition = 0;
|
||||
}
|
||||
return del(newPosition, this.position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定长度的字符,规则如下:
|
||||
*
|
||||
* <pre>
|
||||
* 1、end大于等于最大长度,结束按照最大长度计算,相当于删除start之后虽有部分(性能最好)
|
||||
* 2、end小于start时,抛出StringIndexOutOfBoundsException
|
||||
* 3、start小于0 按照0处理
|
||||
* 4、start等于end不处理
|
||||
* 5、start和end都位于长度区间内,删除这段内容(内存拷贝)
|
||||
* </pre>
|
||||
*
|
||||
* @param start 开始位置,负数按照0处理(包括)
|
||||
* @param end 结束位置,超出最大长度按照最大长度处理(不包括)
|
||||
* @return this
|
||||
* @throws StringIndexOutOfBoundsException 当start > end抛出此异常
|
||||
*/
|
||||
public StrBuilder del(int start, int end) throws StringIndexOutOfBoundsException {
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
|
||||
if (end >= this.position) {
|
||||
// end在边界及以外,相当于删除后半部分
|
||||
this.position = start;
|
||||
return this;
|
||||
} else if (end < 0) {
|
||||
// start和end都为0的情况下表示删除全部
|
||||
end = 0;
|
||||
}
|
||||
|
||||
final int len = end - start;
|
||||
// 截取中间部分,需要将后半部分复制到删除的开始位置
|
||||
if (len > 0) {
|
||||
System.arraycopy(value, start + len, value, start, this.position - end);
|
||||
this.position -= len;
|
||||
} else if (len < 0) {
|
||||
throw new StringIndexOutOfBoundsException("Start is greater than End.");
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成字符串
|
||||
*
|
||||
* @param isReset 是否重置,重置后相当于空的构建器
|
||||
* @return 生成的字符串
|
||||
*/
|
||||
public String toString(final boolean isReset) {
|
||||
if (position > 0) {
|
||||
final String s = new String(value, 0, position);
|
||||
if (isReset) {
|
||||
reset();
|
||||
}
|
||||
return s;
|
||||
}
|
||||
return StrUtil.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置并返回生成的字符串
|
||||
*
|
||||
* @return 字符串
|
||||
*/
|
||||
public String toStringAndReset() {
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成字符串
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return toString(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int length() {
|
||||
return this.position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public char charAt(int index) {
|
||||
if(index < 0){
|
||||
index = this.position + index;
|
||||
}
|
||||
if ((index < 0) || (index > this.position)) {
|
||||
throw new StringIndexOutOfBoundsException(index);
|
||||
}
|
||||
return this.value[index];
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence subSequence(final int start, final int end) {
|
||||
return subString(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回自定段的字符串
|
||||
*
|
||||
* @param start 开始位置(包括)
|
||||
* @return this
|
||||
*/
|
||||
public String subString(final int start) {
|
||||
return subString(start, this.position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回自定段的字符串
|
||||
*
|
||||
* @param start 开始位置(包括)
|
||||
* @param end 结束位置(不包括)
|
||||
* @return this
|
||||
*/
|
||||
public String subString(final int start, final int end) {
|
||||
return new String(this.value, start, end - start);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------------------ Private method start
|
||||
|
||||
/**
|
||||
* 指定位置之后的数据后移指定长度
|
||||
*
|
||||
* @param index 位置
|
||||
* @param length 位移长度
|
||||
*/
|
||||
private void moveDataAfterIndex(final int index, final int length) {
|
||||
ensureCapacity(Math.max(this.position, index) + length);
|
||||
if (index < this.position) {
|
||||
// 插入位置在已有数据范围内,后移插入位置之后的数据
|
||||
System.arraycopy(this.value, index, this.value, index + length, this.position - index);
|
||||
} else if (index > this.position) {
|
||||
// 插入位置超出范围,则当前位置到index清除为空格
|
||||
Arrays.fill(this.value, this.position, index, StrUtil.C_SPACE);
|
||||
}
|
||||
// 不位移
|
||||
}
|
||||
|
||||
/**
|
||||
* 确认容量是否够用,不够用则扩展容量
|
||||
*
|
||||
* @param minimumCapacity 最小容量
|
||||
*/
|
||||
private void ensureCapacity(final int minimumCapacity) {
|
||||
// overflow-conscious code
|
||||
if (minimumCapacity - value.length > 0) {
|
||||
expandCapacity(minimumCapacity);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 扩展容量<br>
|
||||
* 首先对容量进行二倍扩展,如果小于最小容量,则扩展为最小容量
|
||||
*
|
||||
* @param minimumCapacity 需要扩展的最小容量
|
||||
*/
|
||||
private void expandCapacity(final int minimumCapacity) {
|
||||
int newCapacity = (value.length << 1) + 2;
|
||||
// overflow-conscious code
|
||||
if (newCapacity - minimumCapacity < 0) {
|
||||
newCapacity = minimumCapacity;
|
||||
}
|
||||
if (newCapacity < 0) {
|
||||
throw new OutOfMemoryError("Capacity is too long and max than Integer.MAX");
|
||||
}
|
||||
value = Arrays.copyOf(value, newCapacity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 给定字符串数组的总长度<br>
|
||||
* null字符长度定义为0
|
||||
*
|
||||
* @param strs 字符串数组
|
||||
* @return 总长度
|
||||
* @since 4.0.1
|
||||
*/
|
||||
private static int totalLength(final CharSequence... strs) {
|
||||
int totalLength = 0;
|
||||
for (final CharSequence str : strs) {
|
||||
totalLength += (null == str ? 0 : str.length());
|
||||
}
|
||||
return totalLength;
|
||||
}
|
||||
// ------------------------------------------------------------------------------------ Private method end
|
||||
}
|
@ -4,7 +4,6 @@ import cn.hutool.core.exceptions.UtilException;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.lang.id.Pid;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.File;
|
||||
@ -327,7 +326,7 @@ public class RuntimeUtil {
|
||||
final int length = cmd.length();
|
||||
final Stack<Character> stack = new Stack<>();
|
||||
boolean inWrap = false;
|
||||
final StrBuilder cache = StrUtil.strBuilder();
|
||||
final StringBuilder cache = new StringBuilder();
|
||||
|
||||
char c;
|
||||
for (int i = 0; i < length; i++) {
|
||||
@ -354,7 +353,7 @@ public class RuntimeUtil {
|
||||
cache.append(c);
|
||||
} else {
|
||||
cmds.add(cache.toString());
|
||||
cache.reset();
|
||||
cache.setLength(0);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
@ -363,7 +362,7 @@ public class RuntimeUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (cache.hasContent()) {
|
||||
if (cache.length() > 0) {
|
||||
cmds.add(cache.toString());
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,8 @@
|
||||
package cn.hutool.db.sql;
|
||||
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -80,8 +79,8 @@ public class NamedSql {
|
||||
|
||||
final int len = namedSql.length();
|
||||
|
||||
final StrBuilder name = StrUtil.strBuilder();
|
||||
final StrBuilder sqlBuilder = StrUtil.strBuilder();
|
||||
final StringBuilder name = new StringBuilder();
|
||||
final StringBuilder sqlBuilder = new StringBuilder();
|
||||
char c;
|
||||
Character nameStartChar = null;
|
||||
for (int i = 0; i < len; i++) {
|
||||
@ -108,7 +107,7 @@ public class NamedSql {
|
||||
}
|
||||
|
||||
// 收尾,如果SQL末尾存在变量,处理之
|
||||
if (false == name.isEmpty()) {
|
||||
if (name.length() > 0) {
|
||||
replaceVar(nameStartChar, name, sqlBuilder, paramMap);
|
||||
}
|
||||
|
||||
@ -123,8 +122,8 @@ public class NamedSql {
|
||||
* @param sqlBuilder 结果SQL缓存
|
||||
* @param paramMap 变量map(非空)
|
||||
*/
|
||||
private void replaceVar(final Character nameStartChar, final StrBuilder name, final StrBuilder sqlBuilder, final Map<String, Object> paramMap){
|
||||
if(name.isEmpty()){
|
||||
private void replaceVar(final Character nameStartChar, final StringBuilder name, final StringBuilder sqlBuilder, final Map<String, Object> paramMap){
|
||||
if(name.length() == 0){
|
||||
if(null != nameStartChar){
|
||||
// 类似于:的情况,需要补上:
|
||||
sqlBuilder.append(nameStartChar);
|
||||
@ -158,7 +157,7 @@ public class NamedSql {
|
||||
}
|
||||
|
||||
//清空变量,表示此变量处理结束
|
||||
name.clear();
|
||||
name.setLength(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,8 +1,6 @@
|
||||
package cn.hutool.extra.pinyin.engine.pinyin4j;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.extra.pinyin.PinyinEngine;
|
||||
import cn.hutool.extra.pinyin.PinyinException;
|
||||
import net.sourceforge.pinyin4j.PinyinHelper;
|
||||
@ -16,7 +14,7 @@ import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombi
|
||||
* 封装了Pinyin4j的引擎。
|
||||
*
|
||||
* <p>
|
||||
* pinyin4j(http://sourceforge.net/projects/pinyin4j)封装。
|
||||
* pinyin4j(<a href="http://sourceforge.net/projects/pinyin4j">http://sourceforge.net/projects/pinyin4j</a>)封装。
|
||||
* </p>
|
||||
*
|
||||
* <p>
|
||||
@ -84,7 +82,7 @@ public class Pinyin4jEngine implements PinyinEngine {
|
||||
|
||||
@Override
|
||||
public String getPinyin(final String str, final String separator) {
|
||||
final StrBuilder result = StrUtil.strBuilder();
|
||||
final StringBuilder result = new StringBuilder();
|
||||
boolean isFirst = true;
|
||||
final int strLen = str.length();
|
||||
try {
|
||||
|
@ -10,10 +10,9 @@ import cn.hutool.core.net.RFC3986;
|
||||
import cn.hutool.core.net.URLEncoder;
|
||||
import cn.hutool.core.net.url.UrlQuery;
|
||||
import cn.hutool.core.regex.ReUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.http.cookie.GlobalCookieManager;
|
||||
import cn.hutool.http.server.SimpleServer;
|
||||
|
||||
@ -528,7 +527,7 @@ public class HttpUtil {
|
||||
if(StrUtil.isEmpty(paramPart)){
|
||||
return paramPart;
|
||||
}
|
||||
final StrBuilder builder = StrBuilder.create(paramPart.length() + 16);
|
||||
final StringBuilder builder = new StringBuilder(paramPart.length() + 16);
|
||||
final int len = paramPart.length();
|
||||
String name = null;
|
||||
int pos = 0; // 未处理字符开始位置
|
||||
@ -572,7 +571,7 @@ public class HttpUtil {
|
||||
// 以&结尾则去除之
|
||||
final int lastIndex = builder.length() - 1;
|
||||
if ('&' == builder.charAt(lastIndex)) {
|
||||
builder.delTo(lastIndex);
|
||||
builder.delete(lastIndex, builder.length());
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
@ -4,10 +4,9 @@ import cn.hutool.core.collection.iter.ComputeIter;
|
||||
import cn.hutool.core.io.IORuntimeException;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
@ -45,7 +44,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
/**
|
||||
* 当前读取字段
|
||||
*/
|
||||
private final StrBuilder currentField = new StrBuilder(512);
|
||||
private final StringBuilder currentField = new StringBuilder(512);
|
||||
|
||||
/**
|
||||
* 标题行
|
||||
@ -206,7 +205,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
|
||||
final List<String> currentFields = new ArrayList<>(maxFieldCount > 0 ? maxFieldCount : DEFAULT_ROW_CAPACITY);
|
||||
|
||||
final StrBuilder currentField = this.currentField;
|
||||
final StringBuilder currentField = this.currentField;
|
||||
final Buffer buf = this.buf;
|
||||
int preChar = this.preChar;//前一个特殊分界字符
|
||||
int copyLen = 0; //拷贝长度
|
||||
@ -223,9 +222,10 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
// CSV读取结束
|
||||
finished = true;
|
||||
|
||||
if (currentField.hasContent() || preChar == config.fieldSeparator) {
|
||||
if (currentField.length() > 0 || preChar == config.fieldSeparator) {
|
||||
//剩余部分作为一个字段
|
||||
addField(currentFields, currentField.toStringAndReset());
|
||||
addField(currentFields, currentField.toString());
|
||||
currentField.setLength(0);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -279,7 +279,8 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
copyLen = 0;
|
||||
}
|
||||
buf.mark();
|
||||
addField(currentFields, currentField.toStringAndReset());
|
||||
addField(currentFields, currentField.toString());
|
||||
currentField.setLength(0);
|
||||
} else if (c == config.textDelimiter) {
|
||||
// 引号开始
|
||||
inQuotes = true;
|
||||
@ -290,7 +291,8 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
buf.appendTo(currentField, copyLen);
|
||||
}
|
||||
buf.mark();
|
||||
addField(currentFields, currentField.toStringAndReset());
|
||||
addField(currentFields, currentField.toString());
|
||||
currentField.setLength(0);
|
||||
preChar = c;
|
||||
break;
|
||||
} else if (c == CharUtil.LF) {
|
||||
@ -300,7 +302,8 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
buf.appendTo(currentField, copyLen);
|
||||
}
|
||||
buf.mark();
|
||||
addField(currentFields, currentField.toStringAndReset());
|
||||
addField(currentFields, currentField.toString());
|
||||
currentField.setLength(0);
|
||||
preChar = c;
|
||||
break;
|
||||
}
|
||||
@ -434,13 +437,13 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
}
|
||||
|
||||
/**
|
||||
* 将数据追加到{@link StrBuilder},追加结束后需手动调用{@link #mark()} 重置读取位置
|
||||
* 将数据追加到{@link StringBuilder},追加结束后需手动调用{@link #mark()} 重置读取位置
|
||||
*
|
||||
* @param builder {@link StrBuilder}
|
||||
* @param builder {@link StringBuilder}
|
||||
* @param length 追加的长度
|
||||
* @see #mark()
|
||||
*/
|
||||
void appendTo(final StrBuilder builder, final int length) {
|
||||
void appendTo(final StringBuilder builder, final int length) {
|
||||
builder.append(this.buf, this.mark, length);
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,7 @@
|
||||
package cn.hutool.poi.excel.sax;
|
||||
|
||||
import cn.hutool.core.text.StrBuilder;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.hutool.poi.excel.cell.FormulaCellValue;
|
||||
import cn.hutool.poi.excel.sax.handler.RowHandler;
|
||||
import org.apache.poi.ss.usermodel.BuiltinFormats;
|
||||
@ -56,9 +55,9 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
private boolean isInSheetData;
|
||||
|
||||
// 上一次的内容
|
||||
private final StrBuilder lastContent = StrUtil.strBuilder();
|
||||
private final StringBuilder lastContent = new StringBuilder();
|
||||
// 上一次的内容
|
||||
private final StrBuilder lastFormula = StrUtil.strBuilder();
|
||||
private final StringBuilder lastFormula = new StringBuilder();
|
||||
// 存储每行的列元素
|
||||
private List<Object> rowCellList = new ArrayList<>();
|
||||
|
||||
@ -198,8 +197,8 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
setCellType(attributes);
|
||||
|
||||
// 清空之前的数据
|
||||
lastContent.reset();
|
||||
lastFormula.reset();
|
||||
lastContent.setLength(0);
|
||||
lastFormula.setLength(0);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -239,7 +238,7 @@ public class SheetDataSaxHandler extends DefaultHandler {
|
||||
|
||||
final String contentStr = StrUtil.trim(lastContent);
|
||||
Object value = ExcelSaxUtil.getDataValue(this.cellDataType, contentStr, this.sharedStrings, this.numFmtString);
|
||||
if (false == this.lastFormula.isEmpty()) {
|
||||
if (this.lastFormula.length() > 0) {
|
||||
value = new FormulaCellValue(StrUtil.trim(lastFormula), value);
|
||||
}
|
||||
addCellValue(curCell++, value);
|
||||
|
Loading…
Reference in New Issue
Block a user