mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 04:20:14 +00:00
Original indention and text delimiter style retained when rendering #106
Now the original indention is captured and string delimiters are retained when rendering out documents. Signed-off-by: Dave Shanley <dave@quobix.com> # fixes 106
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -674,3 +675,19 @@ func CheckEnumForDuplicates(seq []*yaml.Node) []*yaml.Node {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// DetermineWhitespaceLength will determine the length of the whitespace for a JSON or YAML file.
|
||||
func DetermineWhitespaceLength(input string) int {
|
||||
exp := regexp.MustCompile(`\n( +)`)
|
||||
whiteSpace := exp.FindAllStringSubmatch(input, -1)
|
||||
var filtered []string
|
||||
for i := range whiteSpace {
|
||||
filtered = append(filtered, whiteSpace[i][1])
|
||||
}
|
||||
sort.Strings(filtered)
|
||||
if len(filtered) > 0 {
|
||||
return len(filtered[0])
|
||||
} else {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user