mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
remove StrBuilder
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user