mirror of
https://github.com/octopusYan/dayz-mod-translator.git
synced 2024-12-27 11:36:43 +08:00
style: 缩进
This commit is contained in:
parent
1294fb5414
commit
223abc7ac5
@ -287,7 +287,7 @@ public class CsvBaseReader implements Serializable {
|
||||
rowHandler.handle(csvParser.next());
|
||||
}
|
||||
} finally {
|
||||
if(close){
|
||||
if (close) {
|
||||
IoUtil.close(csvParser);
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ public class CsvData implements Iterable<CsvRow>, Serializable {
|
||||
* @return the header row - might be {@code null} if no header exists
|
||||
*/
|
||||
public List<String> getHeader() {
|
||||
if(null == this.header){
|
||||
if (null == this.header) {
|
||||
return null;
|
||||
}
|
||||
return Collections.unmodifiableList(this.header);
|
||||
|
@ -122,11 +122,11 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
}
|
||||
|
||||
// 读取范围校验
|
||||
if(lineNo < config.beginLineNo){
|
||||
if (lineNo < config.beginLineNo) {
|
||||
// 未达到读取起始行,继续
|
||||
continue;
|
||||
}
|
||||
if(lineNo > config.endLineNo){
|
||||
if (lineNo > config.endLineNo) {
|
||||
// 超出结束行,读取结束
|
||||
break;
|
||||
}
|
||||
@ -199,7 +199,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
private List<String> readLine() throws IORuntimeException {
|
||||
// 矫正行号
|
||||
// 当一行内容包含多行数据时,记录首行行号,但是读取下一行时,需要把多行内容的行数加上
|
||||
if(inQuotesLineCount > 0){
|
||||
if (inQuotesLineCount > 0) {
|
||||
this.lineNo += this.inQuotesLineCount;
|
||||
this.inQuotesLineCount = 0;
|
||||
}
|
||||
@ -237,16 +237,16 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
final char c = buf.get();
|
||||
|
||||
// 注释行标记
|
||||
if(preChar < 0 || preChar == CharUtil.CR || preChar == CharUtil.LF){
|
||||
if (preChar < 0 || preChar == CharUtil.CR || preChar == CharUtil.LF) {
|
||||
// 判断行首字符为指定注释字符的注释开始,直到遇到换行符
|
||||
// 行首分两种,1是preChar < 0表示文本开始,2是换行符后紧跟就是下一行的开始
|
||||
// issue#IA8WE0 如果注释符出现在包装符内,被认为是普通字符
|
||||
if((false == inQuotes) && null != this.config.commentCharacter && c == this.config.commentCharacter){
|
||||
if ((false == inQuotes) && null != this.config.commentCharacter && c == this.config.commentCharacter) {
|
||||
inComment = true;
|
||||
}
|
||||
}
|
||||
// 注释行处理
|
||||
if(inComment){
|
||||
if (inComment) {
|
||||
if (c == CharUtil.CR || c == CharUtil.LF) {
|
||||
// 注释行以换行符为结尾
|
||||
lineNo++;
|
||||
@ -261,15 +261,15 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
if (inQuotes) {
|
||||
//引号内,作为内容,直到引号结束
|
||||
if (c == config.textDelimiter) {
|
||||
if(buf.canRead(1) && buf.read(1) == CharUtil.DOUBLE_QUOTES) {
|
||||
if (buf.canRead(1) && buf.read(1) == CharUtil.DOUBLE_QUOTES) {
|
||||
continuousCount++;
|
||||
} else if(continuousCount != 0 && (continuousCount + 1) % 2 == 0) {
|
||||
} else if (continuousCount != 0 && (continuousCount + 1) % 2 == 0) {
|
||||
continuousCount = 0;
|
||||
} else {
|
||||
inQuotes = false;
|
||||
}
|
||||
} else {
|
||||
if(continuousCount != 0) continuousCount = 0;
|
||||
if (continuousCount != 0) continuousCount = 0;
|
||||
// 字段内容中新行
|
||||
if (isLineEnd(c, preChar)) {
|
||||
inQuotesLineCount++;
|
||||
@ -344,18 +344,18 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
final char textDelimiter = this.config.textDelimiter;
|
||||
|
||||
// 忽略多余引号后的换行符
|
||||
field = StrUtil.trim(field, 1, (c-> c == CharUtil.LF || c == CharUtil.CR));
|
||||
field = StrUtil.trim(field, 1, (c -> c == CharUtil.LF || c == CharUtil.CR));
|
||||
// 去除手写csv列值前后的缩进符
|
||||
field = field.replaceAll("\t+\"|\"\t+", "\"");
|
||||
|
||||
if(StrUtil.isWrap(field, textDelimiter)){
|
||||
if (StrUtil.isWrap(field, textDelimiter)) {
|
||||
field = StrUtil.sub(field, 1, field.length() - 1);
|
||||
// https://datatracker.ietf.org/doc/html/rfc4180#section-2
|
||||
// 第七条规则,只有包装内的包装符需要转义
|
||||
field = StrUtil.replace(field, String.valueOf(textDelimiter) + textDelimiter, String.valueOf(textDelimiter));
|
||||
}
|
||||
|
||||
if(this.config.trimField){
|
||||
if (this.config.trimField) {
|
||||
// issue#I49M0C@Gitee
|
||||
field = StrUtil.trim(field);
|
||||
}
|
||||
@ -399,7 +399,7 @@ public final class CsvParser extends ComputeIter<CsvRow> implements Closeable, S
|
||||
*
|
||||
* @author looly
|
||||
*/
|
||||
private static class Buffer implements Serializable{
|
||||
private static class Buffer implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
final char[] buf;
|
||||
|
@ -6,22 +6,33 @@ import java.io.Serializable;
|
||||
* CSV读取配置项
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
public class CsvReadConfig extends CsvConfig<CsvReadConfig> implements Serializable {
|
||||
private static final long serialVersionUID = 5396453565371560052L;
|
||||
|
||||
/** 指定标题行号,-1表示无标题行 */
|
||||
/**
|
||||
* 指定标题行号,-1表示无标题行
|
||||
*/
|
||||
protected long headerLineNo = -1;
|
||||
/** 是否跳过空白行,默认true */
|
||||
/**
|
||||
* 是否跳过空白行,默认true
|
||||
*/
|
||||
protected boolean skipEmptyRows = true;
|
||||
/** 每行字段个数不同时是否抛出异常,默认false */
|
||||
/**
|
||||
* 每行字段个数不同时是否抛出异常,默认false
|
||||
*/
|
||||
protected boolean errorOnDifferentFieldCount;
|
||||
/** 定义开始的行(包括),此处为原始文件行号 */
|
||||
/**
|
||||
* 定义开始的行(包括),此处为原始文件行号
|
||||
*/
|
||||
protected long beginLineNo;
|
||||
/** 结束的行(包括),此处为原始文件行号 */
|
||||
protected long endLineNo = Long.MAX_VALUE-1;
|
||||
/** 每个字段是否去除两边空白符 */
|
||||
/**
|
||||
* 结束的行(包括),此处为原始文件行号
|
||||
*/
|
||||
protected long endLineNo = Long.MAX_VALUE - 1;
|
||||
/**
|
||||
* 每个字段是否去除两边空白符
|
||||
*/
|
||||
protected boolean trimField;
|
||||
|
||||
/**
|
||||
|
@ -101,6 +101,7 @@ public class CsvReader extends CsvBaseReader implements Iterable<CsvRow>, Closea
|
||||
this.reader = reader;
|
||||
}
|
||||
//--------------------------------------------------------------------------------------------- Constructor end
|
||||
|
||||
/**
|
||||
* 读取CSV文件,此方法只能调用一次<br>
|
||||
* 调用此方法的前提是构造中传入文件路径或Reader
|
||||
|
@ -12,7 +12,9 @@ import java.util.*;
|
||||
*/
|
||||
public final class CsvRow implements List<String> {
|
||||
|
||||
/** 原始行号 */
|
||||
/**
|
||||
* 原始行号
|
||||
*/
|
||||
private final long originalLineNumber;
|
||||
|
||||
final Map<String, Integer> headerMap;
|
||||
@ -100,7 +102,7 @@ public final class CsvRow implements List<String> {
|
||||
* @return Bean
|
||||
* @since 5.3.6
|
||||
*/
|
||||
public <T> T toBean(Class<T> clazz){
|
||||
public <T> T toBean(Class<T> clazz) {
|
||||
return BeanUtil.toBeanIgnoreError(getFieldMap(), clazz);
|
||||
}
|
||||
|
||||
@ -239,7 +241,7 @@ public final class CsvRow implements List<String> {
|
||||
sb.append("fields=");
|
||||
if (headerMap != null) {
|
||||
sb.append('{');
|
||||
for (final Iterator<Map.Entry<String, String>> it = getFieldMap().entrySet().iterator(); it.hasNext();) {
|
||||
for (final Iterator<Map.Entry<String, String>> it = getFieldMap().entrySet().iterator(); it.hasNext(); ) {
|
||||
|
||||
final Map.Entry<String, String> entry = it.next();
|
||||
sb.append(entry.getKey());
|
||||
|
Loading…
Reference in New Issue
Block a user