From d9b212fb8054ae78862eee72d080551666d0d8ee Mon Sep 17 00:00:00 2001 From: aaron <462826@qq.com> Date: Mon, 21 Sep 2020 17:06:34 +0800 Subject: [PATCH] update resource --- demo/default.yaml | 4 ++-- res/en/sample.yaml | 4 ++-- res/zh/sample.yaml | 4 ++-- src/gen/decode.go | 6 +++--- src/gen/definition.go | 4 ++-- src/gen/output.go | 2 +- src/model/definition.go | 12 ++++++------ src/utils/string/string.go | 4 ++-- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/demo/default.yaml b/demo/default.yaml index 485390f0..3bcc4f17 100644 --- a/demo/default.yaml +++ b/demo/default.yaml @@ -94,8 +94,8 @@ fields: postfix: "\t" - field: field_length # 指定宽度。 - range: 1-9 # 001,002,003..., 099,100 - width: 3 # 包含前后缀的宽度。 + range: 1-99 # 01\t,02\t,03\t..., 99\t + length: 3 # 包含前后缀的宽度。 leftpad: 0 # 宽度不够时,补充的字符。 postfix: "\t" diff --git a/res/en/sample.yaml b/res/en/sample.yaml index 2c4b4e6a..45226f8e 100644 --- a/res/en/sample.yaml +++ b/res/en/sample.yaml @@ -94,8 +94,8 @@ fields: postfix: "\t" - field: field_length # Fixed length field. - range: 1-100 # 001,002,003..., 099,100 - width: 3 # the length in Byte including prefix and postfix. + range: 1-99 # 01\t,02\t,03\t..., 99\t + length: 3 # the length in Byte including prefix and postfix. leftpad: 0 # Using 0 to pad. postfix: "\t" diff --git a/res/zh/sample.yaml b/res/zh/sample.yaml index 485390f0..3bcc4f17 100644 --- a/res/zh/sample.yaml +++ b/res/zh/sample.yaml @@ -94,8 +94,8 @@ fields: postfix: "\t" - field: field_length # 指定宽度。 - range: 1-9 # 001,002,003..., 099,100 - width: 3 # 包含前后缀的宽度。 + range: 1-99 # 01\t,02\t,03\t..., 99\t + length: 3 # 包含前后缀的宽度。 leftpad: 0 # 宽度不够时,补充的字符。 postfix: "\t" diff --git a/src/gen/decode.go b/src/gen/decode.go index f33e0228..1c5544d1 100644 --- a/src/gen/decode.go +++ b/src/gen/decode.go @@ -73,9 +73,9 @@ func decodeOneLevel(line string, fields []model.DefField, rowMap *map[string]int for j, field := range fields { col := "" - if field.Width > 0 { - col = string(left[:field.Width]) - left = left[field.Width:] + if field.Length > 0 { + col = string(left[:field.Length]) + left = left[field.Length:] } else { sepStr := "" if j < len(fields) - 1 { diff --git a/src/gen/definition.go b/src/gen/definition.go index b8ae0389..4c6d8abe 100644 --- a/src/gen/definition.go +++ b/src/gen/definition.go @@ -222,8 +222,8 @@ func CopyField(child model.DefField, parent *model.DefField) { if child.Precision != 0 { (*parent).Precision = child.Precision } - if child.Width != 0 { - (*parent).Width = child.Width + if child.Length != 0 { + (*parent).Length = child.Length } } diff --git a/src/gen/output.go b/src/gen/output.go index 42959d4d..2bd0b6b0 100644 --- a/src/gen/output.go +++ b/src/gen/output.go @@ -33,7 +33,7 @@ func Print(rows [][]string, format string, table string, colIsNumArr []bool, for j, col := range cols { col = replacePlaceholder(col) field := vari.TopFieldMap[fields[j]] - if field.Width > runewidth.StringWidth(col) { + if field.Length > runewidth.StringWidth(col) { col = stringUtils.AddPad(col, field) } diff --git a/src/model/definition.go b/src/model/definition.go index 5d833ac7..b5344ddd 100644 --- a/src/model/definition.go +++ b/src/model/definition.go @@ -38,12 +38,12 @@ type DefData struct { Fields []DefField `yaml:"fields,flow"` } type DefField struct { - FieldBase `yaml:",inline"` - Fields []DefField `yaml:"fields,flow"` - Width int `yaml:"width"` - LeftPad string `yaml:"leftpad"` - RightPad string `yaml:"rightpad"` - Path string + FieldBase `yaml:",inline"` + Fields []DefField `yaml:"fields,flow"` + Length int `yaml:"length"` + LeftPad string `yaml:"leftpad"` + RightPad string `yaml:"rightpad"` + Path string Froms []DefField `yaml:"froms,flow"` } diff --git a/src/utils/string/string.go b/src/utils/string/string.go index 0d962ddc..459d83d1 100644 --- a/src/utils/string/string.go +++ b/src/utils/string/string.go @@ -143,8 +143,8 @@ func FormatStr(format string, val interface{}, precision int) (ret string, pass } func AddPad(str string, field model.DefField) string { - if field.Width > 0 && field.Width > runewidth.StringWidth(str) { - gap := field.Width - len(str) + if field.Length > 0 && field.Length > runewidth.StringWidth(str) { + gap := field.Length - len(str) if field.LeftPad != "" { field.LeftPad = field.LeftPad[:1] pads := strings.Repeat(field.LeftPad, gap) -- GitLab