start a oneof() format
This commit is contained in:
parent
8471b3e683
commit
c52d8ea9a8
|
@ -312,6 +312,21 @@ func formatEnum(curmsg *FormatMsg) []string {
|
||||||
return newmsg
|
return newmsg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func formatOneof(curmsg *FormatMsg) []string {
|
||||||
|
// curmsg.formatStandardSizes()
|
||||||
|
|
||||||
|
var newmsg []string
|
||||||
|
newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Header, "oneof header"))
|
||||||
|
|
||||||
|
for _, line := range curmsg.Lines {
|
||||||
|
// func (msg *FormatMsg) formatMsgLine(line string, dbg string) string {
|
||||||
|
newmsg = append(newmsg, curmsg.formatMsgLine(line, "oneof"))
|
||||||
|
}
|
||||||
|
|
||||||
|
newmsg = append(newmsg, curmsg.formatLineBase(curmsg.Footer, "oneof header"))
|
||||||
|
return newmsg
|
||||||
|
}
|
||||||
|
|
||||||
// set all children to have the same max sizes
|
// set all children to have the same max sizes
|
||||||
func (parent *FormatMsg) formatStandardSizes() {
|
func (parent *FormatMsg) formatStandardSizes() {
|
||||||
var bigType int64
|
var bigType int64
|
||||||
|
@ -321,6 +336,15 @@ func (parent *FormatMsg) formatStandardSizes() {
|
||||||
for _, child := range parent.Msgs {
|
for _, child := range parent.Msgs {
|
||||||
switch child.Type {
|
switch child.Type {
|
||||||
case FormatMsg_ENUM:
|
case FormatMsg_ENUM:
|
||||||
|
case FormatMsg_ONEOF:
|
||||||
|
// find the max length of varname and vartype
|
||||||
|
setMaxSizes(child)
|
||||||
|
if bigType < child.MaxVartype {
|
||||||
|
bigType = child.MaxVartype
|
||||||
|
}
|
||||||
|
if bigName < child.MaxVarname {
|
||||||
|
bigName = child.MaxVarname
|
||||||
|
}
|
||||||
case FormatMsg_MESSAGE:
|
case FormatMsg_MESSAGE:
|
||||||
// find the max length of varname and vartype
|
// find the max length of varname and vartype
|
||||||
setMaxSizes(child)
|
setMaxSizes(child)
|
||||||
|
@ -338,6 +362,9 @@ func (parent *FormatMsg) formatStandardSizes() {
|
||||||
for _, child := range parent.Msgs {
|
for _, child := range parent.Msgs {
|
||||||
switch child.Type {
|
switch child.Type {
|
||||||
case FormatMsg_ENUM:
|
case FormatMsg_ENUM:
|
||||||
|
case FormatMsg_ONEOF:
|
||||||
|
child.MaxVartype = bigType
|
||||||
|
child.MaxVarname = bigName
|
||||||
case FormatMsg_MESSAGE:
|
case FormatMsg_MESSAGE:
|
||||||
child.MaxVartype = bigType
|
child.MaxVartype = bigType
|
||||||
child.MaxVarname = bigName
|
child.MaxVarname = bigName
|
||||||
|
@ -353,7 +380,7 @@ func (parent *FormatMsg) format() []string {
|
||||||
case FormatMsg_ENUM:
|
case FormatMsg_ENUM:
|
||||||
return formatEnum(parent)
|
return formatEnum(parent)
|
||||||
case FormatMsg_ONEOF:
|
case FormatMsg_ONEOF:
|
||||||
return formatEnum(parent)
|
return formatOneof(parent)
|
||||||
case FormatMsg_MESSAGE:
|
case FormatMsg_MESSAGE:
|
||||||
return formatMessage(parent)
|
return formatMessage(parent)
|
||||||
default:
|
default:
|
||||||
|
@ -403,11 +430,26 @@ func (msg *FormatMsg) formatVarLine(line string, dbg string) string {
|
||||||
newline = strings.TrimRight(newline, " ")
|
newline = strings.TrimRight(newline, " ")
|
||||||
|
|
||||||
if argv.Debug {
|
if argv.Debug {
|
||||||
return fmt.Sprintf("/*a*/%s/*b*/%s // %s depth=%d", msg.pad(), newline, dbg, msg.Depth)
|
return fmt.Sprintf("/*a*/%s/*b*/%s // %s depth=%d (%d,%d)", msg.pad(), newline, dbg, msg.Depth, msg.MaxVartype, msg.MaxVarname)
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s%s", msg.pad(), newline)
|
return fmt.Sprintf("%s%s", msg.pad(), newline)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (msg *FormatMsg) formatMsgLine(line string, dbg string) string {
|
||||||
|
line = strings.TrimSpace(line)
|
||||||
|
if line == "" {
|
||||||
|
if argv.Debug {
|
||||||
|
return "// empty line " + msg.Header + " empty line end"
|
||||||
|
} else {
|
||||||
|
return line
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(line, "//") {
|
||||||
|
return msg.formatComment(line, "comment")
|
||||||
|
}
|
||||||
|
return msg.formatVarLine(line, "var "+dbg)
|
||||||
|
}
|
||||||
|
|
||||||
func trimLines(lines []string) []string {
|
func trimLines(lines []string) []string {
|
||||||
return strings.Split(strings.TrimSuffix(strings.Join(lines, "\n"), "\n"), "\n")
|
return strings.Split(strings.TrimSuffix(strings.Join(lines, "\n"), "\n"), "\n")
|
||||||
}
|
}
|
||||||
|
@ -439,9 +481,9 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
hmm := "%s %" + pad + "s %s"
|
hmm := "%s %" + pad + "s %s"
|
||||||
line = fmt.Sprintf(hmm, start, " ", end)
|
line = fmt.Sprintf(hmm, start, " ", end)
|
||||||
}
|
}
|
||||||
newmsg = append(newmsg, line) // " //header")
|
newmsg = append(newmsg, line) // +"// header")
|
||||||
} else {
|
} else {
|
||||||
newmsg = append(newmsg, line) // " //header")
|
newmsg = append(newmsg, line) // +"// header")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if curmsg.Depth != 0 {
|
if curmsg.Depth != 0 {
|
||||||
|
@ -456,7 +498,7 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
newmsg = append(newmsg, line)
|
newmsg = append(newmsg, line)
|
||||||
}
|
}
|
||||||
case FormatMsg_ONEOF:
|
case FormatMsg_ONEOF:
|
||||||
for _, line := range formatEnum(msg) {
|
for _, line := range formatOneof(msg) {
|
||||||
newmsg = append(newmsg, line)
|
newmsg = append(newmsg, line)
|
||||||
}
|
}
|
||||||
case FormatMsg_MESSAGE:
|
case FormatMsg_MESSAGE:
|
||||||
|
@ -468,11 +510,26 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// trim curmsg.Lines
|
||||||
|
// if curmsg.Lines is empty, don't do anything
|
||||||
|
dump := strings.Join(curmsg.Lines, "\n")
|
||||||
|
dump = strings.TrimSpace(dump)
|
||||||
|
|
||||||
|
if dump == "" {
|
||||||
|
// do nothing
|
||||||
|
} else {
|
||||||
|
// print the lines
|
||||||
|
curmsg.Lines = strings.Split(dump, "\n")
|
||||||
|
// newmsg = append(newmsg, "// dump "+dump+"dump end\n")
|
||||||
|
|
||||||
for _, line := range curmsg.Lines {
|
for _, line := range curmsg.Lines {
|
||||||
line = strings.TrimSpace(line)
|
line = strings.TrimSpace(line)
|
||||||
if line == "" {
|
if line == "" {
|
||||||
// newmsg = append(newmsg, line)
|
if argv.Debug {
|
||||||
newmsg = append(newmsg, "\n")
|
newmsg = append(newmsg, "// empty line "+curmsg.Header+" empty line end")
|
||||||
|
} else {
|
||||||
|
newmsg = append(newmsg, line)
|
||||||
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(line, "//") {
|
if strings.HasPrefix(line, "//") {
|
||||||
|
@ -486,26 +543,7 @@ func formatMessage(curmsg *FormatMsg) []string {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
newmsg = append(newmsg, curmsg.formatVarLine(line, "var"))
|
newmsg = append(newmsg, curmsg.formatVarLine(line, "var"))
|
||||||
continue
|
|
||||||
/*
|
|
||||||
mt := fmt.Sprintf("%d", curmsg.MaxVartype)
|
|
||||||
mv := fmt.Sprintf("%d", curmsg.MaxVarname)
|
|
||||||
|
|
||||||
hmm := "%s%-" + mt + "s %-" + mv + "s = %-3s %s"
|
|
||||||
|
|
||||||
vartype, varname, id, end := tokenMsgVar(line)
|
|
||||||
end = strings.TrimSpace(end)
|
|
||||||
id = id + ";"
|
|
||||||
|
|
||||||
var newline string
|
|
||||||
if argv.Debug {
|
|
||||||
newline = fmt.Sprintf(hmm+" //depth=%d", curmsg.padding(0), vartype, varname, id, end, curmsg.Depth)
|
|
||||||
} else {
|
|
||||||
newline = fmt.Sprintf(hmm, curmsg.padding(0), vartype, varname, id, end)
|
|
||||||
}
|
}
|
||||||
newline = strings.TrimRight(newline, " ")
|
|
||||||
newmsg = append(newmsg, newline)
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if curmsg.Footer == "" {
|
if curmsg.Footer == "" {
|
||||||
|
|
Loading…
Reference in New Issue