mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2025-06-05 21:59:39 +02:00
Upstep Go dependencies (#340)
* Upstep Go dependencies * tiny linter fix * Tidy
This commit is contained in:
31
vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go
generated
vendored
31
vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go
generated
vendored
@ -1,12 +1,13 @@
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// Porgram: xmlfmt.go
|
||||
// Purpose: Go XML Beautify from XML string using pure string manipulation
|
||||
// Authors: Antonio Sun (c) 2016-2019, All rights reserved
|
||||
// Authors: Antonio Sun (c) 2016-2021, All rights reserved
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package xmlfmt
|
||||
|
||||
import (
|
||||
"html"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
@ -17,12 +18,32 @@ var (
|
||||
NL = "\r\n"
|
||||
)
|
||||
|
||||
// FormatXML will (purly) reformat the XML string in a readable way, without any rewriting/altering the structure
|
||||
func FormatXML(xmls, prefix, indent string) string {
|
||||
// FormatXML will (purly) reformat the XML string in a readable way, without any rewriting/altering the structure.
|
||||
// If your XML Comments have nested tags in them, or you're not 100% sure otherwise, pass `true` as the third parameter to this function. But don't turn it on blindly, as the code has become ten times more complicated because of it.
|
||||
func FormatXML(xmls, prefix, indent string, nestedTagsInComments ...bool) string {
|
||||
nestedTagsInComment := false
|
||||
if len(nestedTagsInComments) > 0 {
|
||||
nestedTagsInComment = nestedTagsInComments[0]
|
||||
}
|
||||
reXmlComments := regexp.MustCompile(`(?s)(<!--)(.*?)(-->)`)
|
||||
src := regexp.MustCompile(`(?s)>\s+<`).ReplaceAllString(xmls, "><")
|
||||
|
||||
if nestedTagsInComment {
|
||||
src = reXmlComments.ReplaceAllStringFunc(src, func(m string) string {
|
||||
parts := reXmlComments.FindStringSubmatch(m)
|
||||
p2 := regexp.MustCompile(`\r*\n`).ReplaceAllString(parts[2], " ")
|
||||
return parts[1] + html.EscapeString(p2) + parts[3]
|
||||
})
|
||||
}
|
||||
rf := replaceTag(prefix, indent)
|
||||
return (prefix + reg.ReplaceAllStringFunc(src, rf))
|
||||
r := prefix + reg.ReplaceAllStringFunc(src, rf)
|
||||
if nestedTagsInComment {
|
||||
r = reXmlComments.ReplaceAllStringFunc(r, func(m string) string {
|
||||
parts := reXmlComments.FindStringSubmatch(m)
|
||||
return parts[1] + html.UnescapeString(parts[2]) + parts[3]
|
||||
})
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// replaceTag returns a closure function to do 's/(?<=>)\s+(?=<)//g; s(<(/?)([^>]+?)(/?)>)($indent+=$3?0:$1?-1:1;"<$1$2$3>"."\n".(" "x$indent))ge' as in Perl
|
||||
|
Reference in New Issue
Block a user