add config

This commit is contained in:
Looly 2021-09-11 23:44:38 +08:00
parent f08ae8cf7d
commit a7817ab5b0
3 changed files with 22 additions and 1 deletions

View File

@ -3,9 +3,11 @@
-------------------------------------------------------------------------------------------------------------
# 5.7.13 (2021-09-10)
# 5.7.13 (2021-09-11)
### 🐣新特性
* 【core 】 CsvReadConfig增加trimField选项issue#I49M0C@Gitee
*
### 🐞Bug修复
* 【core 】 修复FuncKey函数无效问题
* 【core 】 修复ImgUtil.copyImage读取网络URL后宽高报错问题issue#1821@Github

View File

@ -332,6 +332,10 @@ public final class CsvParser implements Closeable, Serializable {
// 忽略多余引号后的换行符
field = StrUtil.trim(field, 1, (c-> c == CharUtil.LF || c == CharUtil.CR));
if(this.config.trimField){
// issue#I49M0C@Gitee
field = StrUtil.trim(field);
}
field = StrUtil.unWrap(field, textDelimiter);
field = StrUtil.replace(field, "" + textDelimiter + textDelimiter, textDelimiter + "");

View File

@ -21,6 +21,8 @@ public class CsvReadConfig extends CsvConfig<CsvReadConfig> implements Serializa
protected long beginLineNo;
/** 结束的行(包括),此处为原始文件行号 */
protected long endLineNo = Long.MAX_VALUE-1;
/** 每个字段是否去除两边空白符 */
protected boolean trimField;
/**
* 默认配置
@ -87,4 +89,17 @@ public class CsvReadConfig extends CsvConfig<CsvReadConfig> implements Serializa
this.endLineNo = endLineNo;
return this;
}
/**
* 设置每个字段是否去除两边空白符<br>
* 如果字段以{@link #textDelimiter}包围则保留两边空格
*
* @param trimField 去除两边空白符
* @return this
* @since 5.7.13
*/
public CsvReadConfig setTrimField(boolean trimField) {
this.trimField = trimField;
return this;
}
}