提交 d9b212fb 编写于 作者: aaronchen2k2k's avatar aaronchen2k2k

update resource

上级 bc4a7dc4
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -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 {
......
......@@ -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
}
}
......
......@@ -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)
}
......
......@@ -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"`
}
......
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册