From 65aac67cf48d4fd73440a0f1acf9fb33d27edd2a Mon Sep 17 00:00:00 2001 From: kercylan98 Date: Wed, 5 Jul 2023 11:43:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=85=8D=E7=BD=AE=E5=AF=BC=E8=A1=A8?= =?UTF-8?q?=E9=83=A8=E5=88=86=E6=9C=AA=E5=A1=AB=E5=86=99=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E5=AF=BC=E8=87=B4=E6=95=B4=E4=B8=AA=E8=A1=A8=E8=A2=AB?= =?UTF-8?q?=E6=88=AA=E6=96=AD=E9=97=AE=E9=A2=98=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- planner/configexport/internal/config.go | 10 ++++-- planner/configexport/internal/field_types.go | 38 ++++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/planner/configexport/internal/config.go b/planner/configexport/internal/config.go index c40a0f7..17d7cc1 100644 --- a/planner/configexport/internal/config.go +++ b/planner/configexport/internal/config.go @@ -260,13 +260,19 @@ func (slf *Config) initData() error { continue } var value any + var zero bool if slf.horizontal { c := slf.matrix.Get(x+i, y) - if c == nil || (currentIndex < slf.IndexCount && len(strings.TrimSpace(c.String())) == 0) { + if c == nil { + value = getValueZero(field.SourceType) + zero = true + } else if currentIndex < slf.IndexCount && len(strings.TrimSpace(c.String())) == 0 { stop = true break } - value = getValueWithType(field.SourceType, c.String()) + if !zero { + value = getValueWithType(field.SourceType, c.String()) + } } else { c := slf.matrix.Get(x, y+i+offset) for c == nil { diff --git a/planner/configexport/internal/field_types.go b/planner/configexport/internal/field_types.go index e8a7e02..d44ddd3 100644 --- a/planner/configexport/internal/field_types.go +++ b/planner/configexport/internal/field_types.go @@ -54,6 +54,44 @@ var basicType = map[string]func(fieldValue string) any{ "boolean": withBoolType, } +func getValueZero(fileType string) any { + switch basicTypeName[fileType] { + case "string": + return getValueWithType(fileType, "") + case "int": + return getValueWithType(fileType, "0") + case "int8": + return getValueWithType(fileType, "0") + case "int16": + return getValueWithType(fileType, "0") + case "int32": + return getValueWithType(fileType, "0") + case "int64": + return getValueWithType(fileType, "0") + case "uint": + return getValueWithType(fileType, "0") + case "uint8": + return getValueWithType(fileType, "0") + case "uint16": + return getValueWithType(fileType, "0") + case "uint32": + return getValueWithType(fileType, "0") + case "uint64": + return getValueWithType(fileType, "0") + case "float32": + return getValueWithType(fileType, "0") + case "float64": + return getValueWithType(fileType, "0") + case "byte": + return getValueWithType(fileType, "0") + case "rune": + return getValueWithType(fileType, "0") + case "bool": + return getValueWithType(fileType, "false") + } + return nil +} + func getValueWithType(fieldType string, fieldValue string) any { fieldType = strings.ToLower(strings.TrimSpace(fieldType)) handle, exist := basicType[fieldType]