From 52f5911c177720830ca21e04a4e06c1dfa7c0125 Mon Sep 17 00:00:00 2001 From: Mat Ryer Date: Sun, 4 Aug 2024 20:24:46 +0100 Subject: [PATCH] ditto --- parser/parser.go | 9 +++++++-- render/split.go | 50 ++++++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index f861df5..2846db8 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -177,6 +177,9 @@ type Parser struct { // objects marks object names. objects map[string]struct{} + // SuppressErrorField suppresses the Error field in output objects. + SuppressErrorField bool + // docs are the docs for extracting comments. docs *doc.Package } @@ -255,8 +258,10 @@ func (p *Parser) Parse() (Definition, error) { sort.Slice(p.def.Objects, func(i, j int) bool { return p.def.Objects[i].Name < p.def.Objects[j].Name }) - if err := p.addOutputFields(); err != nil { - return p.def, err + if !p.SuppressErrorField { + if err := p.addOutputFields(); err != nil { + return p.def, err + } } return p.def, nil } diff --git a/render/split.go b/render/split.go index c8beefe..d4b7534 100644 --- a/render/split.go +++ b/render/split.go @@ -18,37 +18,37 @@ import ( // // Examples // -// "" => [""] -// "lowercase" => ["lowercase"] -// "Class" => ["Class"] -// "MyClass" => ["My", "Class"] -// "MyC" => ["My", "C"] -// "HTML" => ["HTML"] -// "PDFLoader" => ["PDF", "Loader"] -// "AString" => ["A", "String"] -// "SimpleXMLParser" => ["Simple", "XML", "Parser"] -// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] -// "GL11Version" => ["GL", "11", "Version"] -// "99Bottles" => ["99", "Bottles"] -// "May5" => ["May", "5"] -// "BFG9000" => ["BFG", "9000"] -// "BöseÜberraschung" => ["Böse", "Überraschung"] -// "Two spaces" => ["Two", " ", "spaces"] -// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] +// "" => [""] +// "lowercase" => ["lowercase"] +// "Class" => ["Class"] +// "MyClass" => ["My", "Class"] +// "MyC" => ["My", "C"] +// "HTML" => ["HTML"] +// "PDFLoader" => ["PDF", "Loader"] +// "AString" => ["A", "String"] +// "SimpleXMLParser" => ["Simple", "XML", "Parser"] +// "vimRPCPlugin" => ["vim", "RPC", "Plugin"] +// "GL11Version" => ["GL", "11", "Version"] +// "99Bottles" => ["99", "Bottles"] +// "May5" => ["May", "5"] +// "BFG9000" => ["BFG", "9000"] +// "BöseÜberraschung" => ["Böse", "Überraschung"] +// "Two spaces" => ["Two", " ", "spaces"] +// "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"] // // Splitting rules // -// 1) If string is not valid UTF-8, return it without splitting as +// 1. If string is not valid UTF-8, return it without splitting as // single item array. -// 2) Assign all unicode characters into one of 4 sets: lower case +// 2. Assign all unicode characters into one of 4 sets: lower case // letters, upper case letters, numbers, and all other characters. -// 3) Iterate through characters of string, introducing splits +// 3. Iterate through characters of string, introducing splits // between adjacent characters that belong to different sets. -// 4) Iterate through array of split strings, and if a given string +// 4. Iterate through array of split strings, and if a given string // is upper case: -// if subsequent string is lower case: -// move last character of upper case string to beginning of -// lower case string +// if subsequent string is lower case: +// move last character of upper case string to beginning of +// lower case string func Split(src string) (entries []string) { // don't split invalid utf8 if !utf8.ValidString(src) { @@ -155,7 +155,7 @@ func camelizeUp(word string) string { func isAcronym(word string) bool { for _, ac := range baseAcronyms { - if strings.ToUpper(ac) == strings.ToUpper(word) { + if strings.EqualFold(ac, word) { return true } }