refactor: 导表工具重构,增加部分特性,修复部分问题

1、增加测试用例;
2、支持多文件合并导表;
3、支持 "#" 开头忽略;
4、修复越界问题;
5、优化模板样式,增加模板规则说明;
This commit is contained in:
kercylan98
2023-07-01 16:07:30 +08:00
parent 73cefc9b48
commit afdda793bc
22 changed files with 268 additions and 313 deletions
+14
View File
@@ -1,6 +1,7 @@
package matrix
import (
"github.com/kercylan98/minotaur/utils/generic"
"github.com/kercylan98/minotaur/utils/geometry"
)
@@ -60,6 +61,19 @@ func (slf *Matrix[T]) Get(x, y int) (value T) {
return slf.m[geometry.CoordinateToPos(slf.w, x, y)]
}
// GetExist 获取特定坐标的内容,如果不存在则返回 false
func (slf *Matrix[T]) GetExist(x, y int) (value T, exist bool) {
pos := geometry.CoordinateToPos(slf.w, x, y)
if pos >= len(slf.m) {
return
}
t := slf.m[pos]
if generic.IsNil(t) {
return
}
return slf.m[pos], true
}
// GetWithPos 获取特定坐标的内容
func (slf *Matrix[T]) GetWithPos(pos int) (value T) {
return slf.m[pos]
+10
View File
@@ -1,5 +1,7 @@
package hash
import "encoding/json"
// Exist 检查特定 key 是否存在
func Exist[K comparable, V any](m map[K]V, key K) bool {
_, exist := m[key]
@@ -15,3 +17,11 @@ func AllExist[K comparable, V any](m map[K]V, keys ...K) bool {
}
return true
}
// ToJson 将 map 转换为 json 字符串
func ToJson[K comparable, V any](m map[K]V) string {
if data, err := json.Marshal(m); err == nil {
return string(data)
}
return "{}"
}