From 67ac8db190eb82a7758746fb021fa3014f4241b7 Mon Sep 17 00:00:00 2001
From: tobi <31960611+tsmethurst@users.noreply.github.com>
Date: Sun, 12 Dec 2021 15:47:51 +0100
Subject: Upstep Go dependencies (#340)
* Upstep Go dependencies
* tiny linter fix
* Tidy
---
vendor/github.com/go-xmlfmt/xmlfmt/README.md | 66 +++++++++++++++++++++++++++-
vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go | 31 ++++++++++---
2 files changed, 90 insertions(+), 7 deletions(-)
(limited to 'vendor/github.com/go-xmlfmt/xmlfmt')
diff --git a/vendor/github.com/go-xmlfmt/xmlfmt/README.md b/vendor/github.com/go-xmlfmt/xmlfmt/README.md
index 4eb6d69a0..da9aa0763 100644
--- a/vendor/github.com/go-xmlfmt/xmlfmt/README.md
+++ b/vendor/github.com/go-xmlfmt/xmlfmt/README.md
@@ -15,9 +15,19 @@ package main
import "github.com/go-xmlfmt/xmlfmt"
func main() {
- xml1 := `aSome org-or-otherWouldnt you like to knowPatCalifia`
+ xmlfmt.NL = "\n"
+ xml1 := `aSome org-or-otherWouldnt you like to knowPatCalifia`
x := xmlfmt.FormatXML(xml1, "\t", " ")
print(x)
+
+ // If the XML Comments have nested tags in them
+ xml1 = ` Fred
+
+ 23456 `
+ x = xmlfmt.FormatXML(xml1, "", " ", true)
+ print(x)
}
```
@@ -47,10 +57,25 @@ Output:
+
+
+
+ Fred
+
+
+ 23456
+
+
```
There is no XML decoding and encoding involved, only pure regular expression matching and replacing. So it is much faster than going through decoding and encoding procedures. Moreover, the exact XML source string is preserved, instead of being changed by the encoder. This is why this package exists in the first place.
+Note that
+
+- the XML is mainly used in Windows environments, thus the default line ending is in Windows' `CRLF` format. To change the default line ending, see the above sample code (first line).
+- the case of XML comments nested within XML comments is ***not*** supported. Please avoid them or use any other tools to correct them before using this package.
+- don't turn on the `nestedTagsInComments` parameter blindly, as the code has become 10+ times more complicated because of it.
+
## Command
To use it on command line, check out [xmlfmt](https://github.com/AntonioSun/xmlfmt):
@@ -59,7 +84,8 @@ To use it on command line, check out [xmlfmt](https://github.com/AntonioSun/xmlf
```
$ xmlfmt
XML Formatter
-built on 2019-12-08
+Version 1.1.0 built on 2021-12-06
+Copyright (C) 2021, Antonio Sun
The xmlfmt will format the XML string without rewriting the document
@@ -69,6 +95,42 @@ Options:
-f, --file *The xml file to read from (or stdin)
-p, --prefix each element begins on a new line and this prefix
-i, --indent[= ] indent string for nested elements
+ -n, --nested nested tags in comments
+
+$ xmlfmt -f https://pastebin.com/raw/z3euQ5PR
+
+
+
+ a
+
+
+
+
+
+ Some org-or-other
+
+ Wouldnt you like to know
+
+
+
+ Pat
+
+ Califia
+
+
+
+
+
+
+$ xmlfmt -f https://pastebin.com/raw/Zs0qy0qz -n
+
+
+ Fred
+
+
+ 23456
+
+
```
diff --git a/vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go b/vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go
index b744f5b35..8b5a9e422 100644
--- a/vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go
+++ b/vendor/github.com/go-xmlfmt/xmlfmt/xmlfmt.go
@@ -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
--
cgit v1.3