forked from mirror/go-json
Remove only operation
This commit is contained in:
parent
e3acf4a01b
commit
40cc5ff367
|
@ -19,7 +19,6 @@ type opType struct {
|
||||||
HeadToAnonymousHead func() string
|
HeadToAnonymousHead func() string
|
||||||
HeadToOmitEmptyHead func() string
|
HeadToOmitEmptyHead func() string
|
||||||
HeadToStringTagHead func() string
|
HeadToStringTagHead func() string
|
||||||
HeadToOnlyHead func() string
|
|
||||||
PtrHeadToHead func() string
|
PtrHeadToHead func() string
|
||||||
FieldToEnd func() string
|
FieldToEnd func() string
|
||||||
FieldToOmitEmptyField func() string
|
FieldToOmitEmptyField func() string
|
||||||
|
@ -50,10 +49,6 @@ func (t opType) IsPtrHeadToHead() bool {
|
||||||
return t.Op != t.PtrHeadToHead()
|
return t.Op != t.PtrHeadToHead()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t opType) IsHeadToOnlyHead() bool {
|
|
||||||
return t.Op != t.HeadToOnlyHead()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t opType) IsFieldToEnd() bool {
|
func (t opType) IsFieldToEnd() bool {
|
||||||
return t.Op != t.FieldToEnd()
|
return t.Op != t.FieldToEnd()
|
||||||
}
|
}
|
||||||
|
@ -75,7 +70,6 @@ func createOpType(op, code string) opType {
|
||||||
HeadToAnonymousHead: func() string { return op },
|
HeadToAnonymousHead: func() string { return op },
|
||||||
HeadToOmitEmptyHead: func() string { return op },
|
HeadToOmitEmptyHead: func() string { return op },
|
||||||
HeadToStringTagHead: func() string { return op },
|
HeadToStringTagHead: func() string { return op },
|
||||||
HeadToOnlyHead: func() string { return op },
|
|
||||||
PtrHeadToHead: func() string { return op },
|
PtrHeadToHead: func() string { return op },
|
||||||
FieldToEnd: func() string { return op },
|
FieldToEnd: func() string { return op },
|
||||||
FieldToOmitEmptyField: func() string { return op },
|
FieldToOmitEmptyField: func() string { return op },
|
||||||
|
@ -222,18 +216,6 @@ func (t opType) headToStringTagHead() opType {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t opType) headToOnlyHead() opType {
|
|
||||||
if strings.HasSuffix(t.String(), "Head") || strings.HasSuffix(t.String(), "HeadOmitEmpty") || strings.HasSuffix(t.String(), "HeadStringTag") {
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
const toOnlyOffset = 1
|
|
||||||
if opType(int(t) + toOnlyOffset).String() == t.String() + "Only" {
|
|
||||||
return opType(int(t) + toOnlyOffset)
|
|
||||||
}
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
func (t opType) ptrHeadToHead() opType {
|
func (t opType) ptrHeadToHead() opType {
|
||||||
idx := strings.Index(t.String(), "Ptr")
|
idx := strings.Index(t.String(), "Ptr")
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
|
@ -334,91 +316,67 @@ func (t opType) fieldToStringTagField() opType {
|
||||||
for _, ptrOrNot := range []string{"", "Ptr", "NPtr"} {
|
for _, ptrOrNot := range []string{"", "Ptr", "NPtr"} {
|
||||||
for _, headType := range []string{"", "Anonymous"} {
|
for _, headType := range []string{"", "Anonymous"} {
|
||||||
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
|
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
|
||||||
for _, onlyOrNot := range []string{"", "Only"} {
|
|
||||||
ptrOrNot := ptrOrNot
|
ptrOrNot := ptrOrNot
|
||||||
headType := headType
|
headType := headType
|
||||||
opt := opt
|
opt := opt
|
||||||
typ := typ
|
typ := typ
|
||||||
onlyOrNot := onlyOrNot
|
|
||||||
|
|
||||||
op := fmt.Sprintf(
|
op := fmt.Sprintf(
|
||||||
"StructField%s%sHead%s%s%s",
|
"StructField%s%sHead%s%s",
|
||||||
ptrOrNot,
|
ptrOrNot,
|
||||||
headType,
|
headType,
|
||||||
opt,
|
opt,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
)
|
||||||
opTypes = append(opTypes, opType{
|
opTypes = append(opTypes, opType{
|
||||||
Op: op,
|
Op: op,
|
||||||
Code: "StructField",
|
Code: "StructField",
|
||||||
HeadToPtrHead: func() string {
|
HeadToPtrHead: func() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"StructFieldPtr%sHead%s%s%s",
|
"StructFieldPtr%sHead%s%s",
|
||||||
headType,
|
headType,
|
||||||
opt,
|
opt,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
HeadToNPtrHead: func() string {
|
HeadToNPtrHead: func() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"StructFieldNPtr%sHead%s%s%s",
|
"StructFieldNPtr%sHead%s%s",
|
||||||
headType,
|
headType,
|
||||||
opt,
|
opt,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
HeadToAnonymousHead: func() string {
|
HeadToAnonymousHead: func() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"StructField%sAnonymousHead%s%s%s",
|
"StructField%sAnonymousHead%s%s",
|
||||||
ptrOrNot,
|
ptrOrNot,
|
||||||
opt,
|
opt,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
HeadToOmitEmptyHead: func() string {
|
HeadToOmitEmptyHead: func() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"StructField%s%sHeadOmitEmpty%s%s",
|
"StructField%s%sHeadOmitEmpty%s",
|
||||||
ptrOrNot,
|
ptrOrNot,
|
||||||
headType,
|
headType,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
HeadToStringTagHead: func() string {
|
HeadToStringTagHead: func() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"StructField%s%sHeadStringTag%s%s",
|
"StructField%s%sHeadStringTag%s",
|
||||||
ptrOrNot,
|
ptrOrNot,
|
||||||
headType,
|
headType,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
HeadToOnlyHead: func() string {
|
|
||||||
switch typ {
|
|
||||||
case "", "Array", "Map", "MapLoad", "Slice",
|
|
||||||
"Struct", "Recursive", "MarshalJSON", "MarshalText",
|
|
||||||
"IntString", "UintString":
|
|
||||||
return op
|
|
||||||
}
|
|
||||||
return fmt.Sprintf(
|
|
||||||
"StructField%s%sHead%s%sOnly",
|
|
||||||
ptrOrNot,
|
|
||||||
headType,
|
|
||||||
opt,
|
|
||||||
typ,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
PtrHeadToHead: func() string {
|
PtrHeadToHead: func() string {
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
"StructField%sHead%s%s%s",
|
"StructField%sHead%s%s",
|
||||||
headType,
|
headType,
|
||||||
opt,
|
opt,
|
||||||
typ,
|
typ,
|
||||||
onlyOrNot,
|
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
FieldToEnd: func() string { return op },
|
FieldToEnd: func() string { return op },
|
||||||
|
@ -429,7 +387,6 @@ func (t opType) fieldToStringTagField() opType {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for _, typ := range append(primitiveTypesUpper, "") {
|
for _, typ := range append(primitiveTypesUpper, "") {
|
||||||
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
|
for _, opt := range []string{"", "OmitEmpty", "StringTag"} {
|
||||||
opt := opt
|
opt := opt
|
||||||
|
@ -448,7 +405,6 @@ func (t opType) fieldToStringTagField() opType {
|
||||||
HeadToAnonymousHead: func() string { return op },
|
HeadToAnonymousHead: func() string { return op },
|
||||||
HeadToOmitEmptyHead: func() string { return op },
|
HeadToOmitEmptyHead: func() string { return op },
|
||||||
HeadToStringTagHead: func() string { return op },
|
HeadToStringTagHead: func() string { return op },
|
||||||
HeadToOnlyHead: func() string { return op },
|
|
||||||
PtrHeadToHead: func() string { return op },
|
PtrHeadToHead: func() string { return op },
|
||||||
FieldToEnd: func() string {
|
FieldToEnd: func() string {
|
||||||
switch typ {
|
switch typ {
|
||||||
|
@ -494,7 +450,6 @@ func (t opType) fieldToStringTagField() opType {
|
||||||
HeadToAnonymousHead: func() string { return op },
|
HeadToAnonymousHead: func() string { return op },
|
||||||
HeadToOmitEmptyHead: func() string { return op },
|
HeadToOmitEmptyHead: func() string { return op },
|
||||||
HeadToStringTagHead: func() string { return op },
|
HeadToStringTagHead: func() string { return op },
|
||||||
HeadToOnlyHead: func() string { return op },
|
|
||||||
PtrHeadToHead: func() string { return op },
|
PtrHeadToHead: func() string { return op },
|
||||||
FieldToEnd: func() string { return op },
|
FieldToEnd: func() string { return op },
|
||||||
FieldToOmitEmptyField: func() string { return op },
|
FieldToOmitEmptyField: func() string { return op },
|
||||||
|
|
2702
encode_optype.go
2702
encode_optype.go
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue