1
0
Fork 0
forked from forgejo/forgejo

Vendor Update Go Libs (#13166)

* update github.com/alecthomas/chroma v0.8.0 -> v0.8.1

* github.com/blevesearch/bleve v1.0.10 -> v1.0.12

* editorconfig-core-go v2.1.1 -> v2.3.7

* github.com/gliderlabs/ssh v0.2.2 -> v0.3.1

* migrate editorconfig.ParseBytes to Parse

* github.com/shurcooL/vfsgen to 0d455de96546

* github.com/go-git/go-git/v5 v5.1.0 -> v5.2.0

* github.com/google/uuid v1.1.1 -> v1.1.2

* github.com/huandu/xstrings v1.3.0 -> v1.3.2

* github.com/klauspost/compress v1.10.11 -> v1.11.1

* github.com/markbates/goth v1.61.2 -> v1.65.0

* github.com/mattn/go-sqlite3 v1.14.0 -> v1.14.4

* github.com/mholt/archiver v3.3.0 -> v3.3.2

* github.com/microcosm-cc/bluemonday 4f7140c49acb -> v1.0.4

* github.com/minio/minio-go v7.0.4 -> v7.0.5

* github.com/olivere/elastic v7.0.9 -> v7.0.20

* github.com/urfave/cli v1.20.0 -> v1.22.4

* github.com/prometheus/client_golang v1.1.0 -> v1.8.0

* github.com/xanzy/go-gitlab v0.37.0 -> v0.38.1

* mvdan.cc/xurls v2.1.0 -> v2.2.0

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
6543 2020-10-16 07:06:27 +02:00 committed by GitHub
parent 91f2afdb54
commit 12a1f914f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
656 changed files with 52967 additions and 25229 deletions

View file

@ -3,15 +3,11 @@
package xstrings
import (
"bytes"
)
const bufferMaxInitGrowSize = 2048
// Lazy initialize a buffer.
func allocBuffer(orig, cur string) *bytes.Buffer {
output := &bytes.Buffer{}
func allocBuffer(orig, cur string) *stringBuilder {
output := &stringBuilder{}
maxSize := len(orig) * 4
// Avoid to reserve too much memory at once.

View file

@ -4,7 +4,6 @@
package xstrings
import (
"bytes"
"math/rand"
"unicode"
"unicode/utf8"
@ -23,7 +22,7 @@ func ToCamelCase(str string) string {
return ""
}
buf := &bytes.Buffer{}
buf := &stringBuilder{}
var r0, r1 rune
var size int
@ -75,15 +74,16 @@ func ToCamelCase(str string) string {
// snake case format.
//
// Some samples.
// "FirstName" => "first_name"
// "HTTPServer" => "http_server"
// "NoHTTPS" => "no_https"
// "GO_PATH" => "go_path"
// "GO PATH" => "go_path" // space is converted to underscore.
// "GO-PATH" => "go_path" // hyphen is converted to underscore.
// "HTTP2XX" => "http_2xx" // insert an underscore before a number and after an alphabet.
// "http2xx" => "http_2xx"
// "HTTP20xOK" => "http_20x_ok"
// "FirstName" => "first_name"
// "HTTPServer" => "http_server"
// "NoHTTPS" => "no_https"
// "GO_PATH" => "go_path"
// "GO PATH" => "go_path" // space is converted to underscore.
// "GO-PATH" => "go_path" // hyphen is converted to underscore.
// "http2xx" => "http_2xx" // insert an underscore before a number and after an alphabet.
// "HTTP20xOK" => "http_20x_ok"
// "Duration2m3s" => "duration_2m3s"
// "Bld4Floor3rd" => "bld4_floor_3rd"
func ToSnakeCase(str string) string {
return camelCaseToLowerCase(str, '_')
}
@ -92,15 +92,16 @@ func ToSnakeCase(str string) string {
// kebab case format.
//
// Some samples.
// "FirstName" => "first-name"
// "HTTPServer" => "http-server"
// "NoHTTPS" => "no-https"
// "GO_PATH" => "go-path"
// "GO PATH" => "go-path" // space is converted to '-'.
// "GO-PATH" => "go-path" // hyphen is converted to '-'.
// "HTTP2XX" => "http-2xx" // insert a '-' before a number and after an alphabet.
// "http2xx" => "http-2xx"
// "HTTP20xOK" => "http-20x-ok"
// "FirstName" => "first-name"
// "HTTPServer" => "http-server"
// "NoHTTPS" => "no-https"
// "GO_PATH" => "go-path"
// "GO PATH" => "go-path" // space is converted to '-'.
// "GO-PATH" => "go-path" // hyphen is converted to '-'.
// "http2xx" => "http-2xx" // insert an underscore before a number and after an alphabet.
// "HTTP20xOK" => "http-20x-ok"
// "Duration2m3s" => "duration-2m3s"
// "Bld4Floor3rd" => "bld4-floor-3rd"
func ToKebabCase(str string) string {
return camelCaseToLowerCase(str, '-')
}
@ -110,98 +111,81 @@ func camelCaseToLowerCase(str string, connector rune) string {
return ""
}
buf := &bytes.Buffer{}
var prev, r0, r1 rune
var size int
buf := &stringBuilder{}
wt, word, remaining := nextWord(str)
r0 = connector
for len(remaining) > 0 {
if wt != connectorWord {
toLower(buf, wt, word, connector)
}
for len(str) > 0 {
prev = r0
r0, size = utf8.DecodeRuneInString(str)
str = str[size:]
prev := wt
last := word
wt, word, remaining = nextWord(remaining)
switch {
case r0 == utf8.RuneError:
buf.WriteRune(r0)
switch prev {
case numberWord:
for wt == alphabetWord || wt == numberWord {
toLower(buf, wt, word, connector)
wt, word, remaining = nextWord(remaining)
}
case unicode.IsUpper(r0):
if prev != connector && !unicode.IsNumber(prev) {
if wt != invalidWord && wt != punctWord {
buf.WriteRune(connector)
}
buf.WriteRune(unicode.ToLower(r0))
case connectorWord:
toLower(buf, prev, last, connector)
if len(str) == 0 {
break
}
r0, size = utf8.DecodeRuneInString(str)
str = str[size:]
if !unicode.IsUpper(r0) {
buf.WriteRune(r0)
break
}
// find next non-upper-case character and insert connector properly.
// it's designed to convert `HTTPServer` to `http_server`.
// if there are more than 2 adjacent upper case characters in a word,
// treat them as an abbreviation plus a normal word.
for len(str) > 0 {
r1 = r0
r0, size = utf8.DecodeRuneInString(str)
str = str[size:]
if r0 == utf8.RuneError {
buf.WriteRune(unicode.ToLower(r1))
buf.WriteRune(r0)
break
}
if !unicode.IsUpper(r0) {
if isConnector(r0) {
r0 = connector
buf.WriteRune(unicode.ToLower(r1))
} else if unicode.IsNumber(r0) {
// treat a number as an upper case rune
// so that both `http2xx` and `HTTP2XX` can be converted to `http_2xx`.
buf.WriteRune(unicode.ToLower(r1))
buf.WriteRune(connector)
buf.WriteRune(r0)
} else {
buf.WriteRune(connector)
buf.WriteRune(unicode.ToLower(r1))
buf.WriteRune(r0)
}
break
}
buf.WriteRune(unicode.ToLower(r1))
}
if len(str) == 0 || r0 == connector {
buf.WriteRune(unicode.ToLower(r0))
}
case unicode.IsNumber(r0):
if prev != connector && !unicode.IsNumber(prev) {
buf.WriteRune(connector)
}
buf.WriteRune(r0)
case punctWord:
// nothing.
default:
if isConnector(r0) {
r0 = connector
if wt != numberWord {
if wt != connectorWord && wt != punctWord {
buf.WriteRune(connector)
}
break
}
buf.WriteRune(r0)
if len(remaining) == 0 {
break
}
last := word
wt, word, remaining = nextWord(remaining)
// consider number as a part of previous word.
// e.g. "Bld4Floor" => "bld4_floor"
if wt != alphabetWord {
toLower(buf, numberWord, last, connector)
if wt != connectorWord && wt != punctWord {
buf.WriteRune(connector)
}
break
}
// if there are some lower case letters following a number,
// add connector before the number.
// e.g. "HTTP2xx" => "http_2xx"
buf.WriteRune(connector)
toLower(buf, numberWord, last, connector)
for wt == alphabetWord || wt == numberWord {
toLower(buf, wt, word, connector)
wt, word, remaining = nextWord(remaining)
}
if wt != invalidWord && wt != connectorWord && wt != punctWord {
buf.WriteRune(connector)
}
}
}
toLower(buf, wt, word, connector)
return buf.String()
}
@ -209,12 +193,214 @@ func isConnector(r rune) bool {
return r == '-' || r == '_' || unicode.IsSpace(r)
}
type wordType int
const (
invalidWord wordType = iota
numberWord
upperCaseWord
alphabetWord
connectorWord
punctWord
otherWord
)
func nextWord(str string) (wt wordType, word, remaining string) {
if len(str) == 0 {
return
}
var offset int
remaining = str
r, size := nextValidRune(remaining, utf8.RuneError)
offset += size
if r == utf8.RuneError {
wt = invalidWord
word = str[:offset]
remaining = str[offset:]
return
}
switch {
case isConnector(r):
wt = connectorWord
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if !isConnector(r) {
break
}
offset += size
remaining = remaining[size:]
}
case unicode.IsPunct(r):
wt = punctWord
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if !unicode.IsPunct(r) {
break
}
offset += size
remaining = remaining[size:]
}
case unicode.IsUpper(r):
wt = upperCaseWord
remaining = remaining[size:]
if len(remaining) == 0 {
break
}
r, size = nextValidRune(remaining, r)
switch {
case unicode.IsUpper(r):
prevSize := size
offset += size
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if !unicode.IsUpper(r) {
break
}
prevSize = size
offset += size
remaining = remaining[size:]
}
// it's a bit complex when dealing with a case like "HTTPStatus".
// it's expected to be splitted into "HTTP" and "Status".
// Therefore "S" should be in remaining instead of word.
if len(remaining) > 0 && isAlphabet(r) {
offset -= prevSize
remaining = str[offset:]
}
case isAlphabet(r):
offset += size
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if !isAlphabet(r) || unicode.IsUpper(r) {
break
}
offset += size
remaining = remaining[size:]
}
}
case isAlphabet(r):
wt = alphabetWord
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if !isAlphabet(r) || unicode.IsUpper(r) {
break
}
offset += size
remaining = remaining[size:]
}
case unicode.IsNumber(r):
wt = numberWord
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if !unicode.IsNumber(r) {
break
}
offset += size
remaining = remaining[size:]
}
default:
wt = otherWord
remaining = remaining[size:]
for len(remaining) > 0 {
r, size = nextValidRune(remaining, r)
if size == 0 || isConnector(r) || isAlphabet(r) || unicode.IsNumber(r) || unicode.IsPunct(r) {
break
}
offset += size
remaining = remaining[size:]
}
}
word = str[:offset]
return
}
func nextValidRune(str string, prev rune) (r rune, size int) {
var sz int
for len(str) > 0 {
r, sz = utf8.DecodeRuneInString(str)
size += sz
if r != utf8.RuneError {
return
}
str = str[sz:]
}
r = prev
return
}
func toLower(buf *stringBuilder, wt wordType, str string, connector rune) {
buf.Grow(buf.Len() + len(str))
if wt != upperCaseWord && wt != connectorWord {
buf.WriteString(str)
return
}
for len(str) > 0 {
r, size := utf8.DecodeRuneInString(str)
str = str[size:]
if isConnector(r) {
buf.WriteRune(connector)
} else if unicode.IsUpper(r) {
buf.WriteRune(unicode.ToLower(r))
} else {
buf.WriteRune(r)
}
}
}
// SwapCase will swap characters case from upper to lower or lower to upper.
func SwapCase(str string) string {
var r rune
var size int
buf := &bytes.Buffer{}
buf := &stringBuilder{}
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
@ -248,7 +434,7 @@ func FirstRuneToUpper(str string) string {
return str
}
buf := &bytes.Buffer{}
buf := &stringBuilder{}
buf.WriteRune(unicode.ToUpper(r))
buf.WriteString(str[size:])
return buf.String()
@ -266,7 +452,7 @@ func FirstRuneToLower(str string) string {
return str
}
buf := &bytes.Buffer{}
buf := &stringBuilder{}
buf.WriteRune(unicode.ToLower(r))
buf.WriteString(str[size:])
return buf.String()
@ -379,7 +565,7 @@ func Successor(str string) string {
// Needs to add one character for carry.
if i < 0 && carry != ' ' {
buf := &bytes.Buffer{}
buf := &stringBuilder{}
buf.Grow(l + 4) // Reserve enough space for write.
if lastAlphanumeric != 0 {

View file

@ -4,7 +4,6 @@
package xstrings
import (
"bytes"
"unicode/utf8"
)
@ -28,7 +27,7 @@ func ExpandTabs(str string, tabSize int) string {
var r rune
var i, size, column, expand int
var output *bytes.Buffer
var output *stringBuilder
orig := str
@ -43,7 +42,7 @@ func ExpandTabs(str string, tabSize int) string {
}
for i = 0; i < expand; i++ {
output.WriteByte(byte(' '))
output.WriteRune(' ')
}
column += expand
@ -88,7 +87,7 @@ func LeftJustify(str string, length int, pad string) string {
remains := length - l
padLen := Len(pad)
output := &bytes.Buffer{}
output := &stringBuilder{}
output.Grow(len(str) + (remains/padLen+1)*len(pad))
output.WriteString(str)
writePadString(output, pad, padLen, remains)
@ -114,7 +113,7 @@ func RightJustify(str string, length int, pad string) string {
remains := length - l
padLen := Len(pad)
output := &bytes.Buffer{}
output := &stringBuilder{}
output.Grow(len(str) + (remains/padLen+1)*len(pad))
writePadString(output, pad, padLen, remains)
output.WriteString(str)
@ -140,7 +139,7 @@ func Center(str string, length int, pad string) string {
remains := length - l
padLen := Len(pad)
output := &bytes.Buffer{}
output := &stringBuilder{}
output.Grow(len(str) + (remains/padLen+1)*len(pad))
writePadString(output, pad, padLen, remains/2)
output.WriteString(str)
@ -148,7 +147,7 @@ func Center(str string, length int, pad string) string {
return output.String()
}
func writePadString(output *bytes.Buffer, pad string, padLen, remains int) {
func writePadString(output *stringBuilder, pad string, padLen, remains int) {
var r rune
var size int

View file

@ -4,7 +4,6 @@
package xstrings
import (
"bytes"
"strings"
"unicode/utf8"
)
@ -131,7 +130,7 @@ func Insert(dst, src string, index int) string {
// Scrub scrubs invalid utf8 bytes with repl string.
// Adjacent invalid bytes are replaced only once.
func Scrub(str, repl string) string {
var buf *bytes.Buffer
var buf *stringBuilder
var r rune
var size, pos int
var hasError bool
@ -144,7 +143,7 @@ func Scrub(str, repl string) string {
if r == utf8.RuneError {
if !hasError {
if buf == nil {
buf = &bytes.Buffer{}
buf = &stringBuilder{}
}
buf.WriteString(origin[:pos])

7
vendor/github.com/huandu/xstrings/stringbuilder.go generated vendored Normal file
View file

@ -0,0 +1,7 @@
//+build go1.10
package xstrings
import "strings"
type stringBuilder = strings.Builder

View file

@ -0,0 +1,9 @@
//+build !go1.10
package xstrings
import "bytes"
type stringBuilder struct {
bytes.Buffer
}

View file

@ -4,7 +4,6 @@
package xstrings
import (
"bytes"
"unicode"
"unicode/utf8"
)
@ -152,12 +151,12 @@ func NewTranslator(from, to string) *Translator {
continue
}
fromStart, toStart = tr.addRuneRange(fromStart, fromEnd, toStart, toStart, singleRunes)
_, toStart = tr.addRuneRange(fromStart, fromEnd, toStart, toStart, singleRunes)
fromEnd = utf8.RuneError
}
if fromEnd != utf8.RuneError {
singleRunes = tr.addRune(fromEnd, toStart, singleRunes)
tr.addRune(fromEnd, toStart, singleRunes)
}
tr.reverted = reverted
@ -303,7 +302,7 @@ func (tr *Translator) Translate(str string) string {
orig := str
var output *bytes.Buffer
var output *stringBuilder
for len(str) > 0 {
r, size = utf8.DecodeRuneInString(str)
@ -500,7 +499,7 @@ func Squeeze(str, pattern string) string {
var size int
var skipSqueeze, matched bool
var tr *Translator
var output *bytes.Buffer
var output *stringBuilder
orig := str
last = -1