mirror of
https://github.com/cheat/cheat.git
synced 2026-03-07 11:13:33 +01:00
chore: modernize CI and update Go toolchain
- Bump Go from 1.19 to 1.26 and update all dependencies - Rewrite CI workflow with matrix strategy (Linux, macOS, Windows) - Update GitHub Actions to current versions (checkout@v4, setup-go@v5) - Update CodeQL actions from v1 to v3 - Fix cross-platform bug in mock/path.go (path.Join -> filepath.Join) - Clean up dependabot config (weekly schedule, remove stale ignore) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
52
vendor/github.com/sergi/go-diff/diffmatchpatch/diff.go
generated
vendored
52
vendor/github.com/sergi/go-diff/diffmatchpatch/diff.go
generated
vendored
@@ -34,8 +34,6 @@ const (
|
||||
DiffInsert Operation = 1
|
||||
// DiffEqual item represents an equal diff.
|
||||
DiffEqual Operation = 0
|
||||
//IndexSeparator is used to seperate the array indexes in an index string
|
||||
IndexSeparator = ","
|
||||
)
|
||||
|
||||
// Diff represents one diff operation
|
||||
@@ -406,14 +404,11 @@ func (dmp *DiffMatchPatch) DiffLinesToRunes(text1, text2 string) ([]rune, []rune
|
||||
func (dmp *DiffMatchPatch) DiffCharsToLines(diffs []Diff, lineArray []string) []Diff {
|
||||
hydrated := make([]Diff, 0, len(diffs))
|
||||
for _, aDiff := range diffs {
|
||||
chars := strings.Split(aDiff.Text, IndexSeparator)
|
||||
text := make([]string, len(chars))
|
||||
runes := []rune(aDiff.Text)
|
||||
text := make([]string, len(runes))
|
||||
|
||||
for i, r := range chars {
|
||||
i1, err := strconv.Atoi(r)
|
||||
if err == nil {
|
||||
text[i] = lineArray[i1]
|
||||
}
|
||||
for i, r := range runes {
|
||||
text[i] = lineArray[runeToInt(r)]
|
||||
}
|
||||
|
||||
aDiff.Text = strings.Join(text, "")
|
||||
@@ -1151,13 +1146,28 @@ func (dmp *DiffMatchPatch) DiffPrettyText(diffs []Diff) string {
|
||||
|
||||
switch diff.Type {
|
||||
case DiffInsert:
|
||||
_, _ = buff.WriteString("\x1b[32m")
|
||||
_, _ = buff.WriteString(text)
|
||||
_, _ = buff.WriteString("\x1b[0m")
|
||||
lines := strings.Split(text, "\n")
|
||||
for i, line := range lines {
|
||||
_, _ = buff.WriteString("\x1b[32m")
|
||||
_, _ = buff.WriteString(line)
|
||||
if i < len(lines)-1 {
|
||||
_, _ = buff.WriteString("\x1b[0m\n")
|
||||
} else {
|
||||
_, _ = buff.WriteString("\x1b[0m")
|
||||
}
|
||||
}
|
||||
|
||||
case DiffDelete:
|
||||
_, _ = buff.WriteString("\x1b[31m")
|
||||
_, _ = buff.WriteString(text)
|
||||
_, _ = buff.WriteString("\x1b[0m")
|
||||
lines := strings.Split(text, "\n")
|
||||
for i, line := range lines {
|
||||
_, _ = buff.WriteString("\x1b[31m")
|
||||
_, _ = buff.WriteString(line)
|
||||
if i < len(lines)-1 {
|
||||
_, _ = buff.WriteString("\x1b[0m\n")
|
||||
} else {
|
||||
_, _ = buff.WriteString("\x1b[0m")
|
||||
}
|
||||
}
|
||||
case DiffEqual:
|
||||
_, _ = buff.WriteString(text)
|
||||
}
|
||||
@@ -1310,7 +1320,6 @@ func (dmp *DiffMatchPatch) DiffFromDelta(text1 string, delta string) (diffs []Di
|
||||
|
||||
// diffLinesToStrings splits two texts into a list of strings. Each string represents one line.
|
||||
func (dmp *DiffMatchPatch) diffLinesToStrings(text1, text2 string) (string, string, []string) {
|
||||
// '\x00' is a valid character, but various debuggers don't like it. So we'll insert a junk entry to avoid generating a null character.
|
||||
lineArray := []string{""} // e.g. lineArray[4] == 'Hello\n'
|
||||
|
||||
lineHash := make(map[string]int)
|
||||
@@ -1321,12 +1330,11 @@ func (dmp *DiffMatchPatch) diffLinesToStrings(text1, text2 string) (string, stri
|
||||
return intArrayToString(strIndexArray1), intArrayToString(strIndexArray2), lineArray
|
||||
}
|
||||
|
||||
// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []string.
|
||||
func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int) []uint32 {
|
||||
// Walk the text, pulling out a substring for each line. text.split('\n') would would temporarily double our memory footprint. Modifying text would create many large strings to garbage collect.
|
||||
// diffLinesToStringsMunge splits a text into an array of strings, and reduces the texts to a []index.
|
||||
func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]string, lineHash map[string]int) []index {
|
||||
lineStart := 0
|
||||
lineEnd := -1
|
||||
strs := []uint32{}
|
||||
strs := []index{}
|
||||
|
||||
for lineEnd < len(text)-1 {
|
||||
lineEnd = indexOf(text, "\n", lineStart)
|
||||
@@ -1340,11 +1348,11 @@ func (dmp *DiffMatchPatch) diffLinesToStringsMunge(text string, lineArray *[]str
|
||||
lineValue, ok := lineHash[line]
|
||||
|
||||
if ok {
|
||||
strs = append(strs, uint32(lineValue))
|
||||
strs = append(strs, index(lineValue))
|
||||
} else {
|
||||
*lineArray = append(*lineArray, line)
|
||||
lineHash[line] = len(*lineArray) - 1
|
||||
strs = append(strs, uint32(len(*lineArray)-1))
|
||||
strs = append(strs, index(len(*lineArray)-1))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
vendor/github.com/sergi/go-diff/diffmatchpatch/index.go
generated
vendored
Normal file
32
vendor/github.com/sergi/go-diff/diffmatchpatch/index.go
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
package diffmatchpatch
|
||||
|
||||
type index uint32
|
||||
|
||||
const runeSkipStart = 0xd800
|
||||
const runeSkipEnd = 0xdfff + 1
|
||||
const runeMax = 0x110000 // next invalid code point
|
||||
|
||||
func stringToIndex(text string) []index {
|
||||
runes := []rune(text)
|
||||
indexes := make([]index, len(runes))
|
||||
for i, r := range runes {
|
||||
if r < runeSkipEnd {
|
||||
indexes[i] = index(r)
|
||||
} else {
|
||||
indexes[i] = index(r) - (runeSkipEnd - runeSkipStart)
|
||||
}
|
||||
}
|
||||
return indexes
|
||||
}
|
||||
|
||||
func indexesToString(indexes []index) string {
|
||||
runes := make([]rune, len(indexes))
|
||||
for i, index := range indexes {
|
||||
if index < runeSkipStart {
|
||||
runes[i] = rune(index)
|
||||
} else {
|
||||
runes[i] = rune(index + (runeSkipEnd - runeSkipStart))
|
||||
}
|
||||
}
|
||||
return string(runes)
|
||||
}
|
||||
102
vendor/github.com/sergi/go-diff/diffmatchpatch/stringutil.go
generated
vendored
102
vendor/github.com/sergi/go-diff/diffmatchpatch/stringutil.go
generated
vendored
@@ -9,11 +9,16 @@
|
||||
package diffmatchpatch
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"fmt"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const UNICODE_INVALID_RANGE_START = 0xD800
|
||||
const UNICODE_INVALID_RANGE_END = 0xDFFF
|
||||
const UNICODE_INVALID_RANGE_DELTA = UNICODE_INVALID_RANGE_END - UNICODE_INVALID_RANGE_START + 1
|
||||
const UNICODE_RANGE_MAX = 0x10FFFF
|
||||
|
||||
// unescaper unescapes selected chars for compatibility with JavaScript's encodeURI.
|
||||
// In speed critical applications this could be dropped since the receiving application will certainly decode these fine. Note that this function is case-sensitive. Thus "%3F" would not be unescaped. But this is ok because it is only called with the output of HttpUtility.UrlEncode which returns lowercase hex. Example: "%3f" -> "?", "%24" -> "$", etc.
|
||||
var unescaper = strings.NewReplacer(
|
||||
@@ -88,19 +93,98 @@ func runesIndex(r1, r2 []rune) int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func intArrayToString(ns []uint32) string {
|
||||
func intArrayToString(ns []index) string {
|
||||
if len(ns) == 0 {
|
||||
return ""
|
||||
}
|
||||
|
||||
indexSeparator := IndexSeparator[0]
|
||||
|
||||
// Appr. 3 chars per num plus the comma.
|
||||
b := []byte{}
|
||||
b := []rune{}
|
||||
for _, n := range ns {
|
||||
b = strconv.AppendInt(b, int64(n), 10)
|
||||
b = append(b, indexSeparator)
|
||||
b = append(b, intToRune(uint32(n)))
|
||||
}
|
||||
b = b[:len(b)-1]
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// These constants define the number of bits representable
|
||||
// in 1,2,3,4 byte utf8 sequences, respectively.
|
||||
const ONE_BYTE_BITS = 7
|
||||
const TWO_BYTE_BITS = 11
|
||||
const THREE_BYTE_BITS = 16
|
||||
const FOUR_BYTE_BITS = 21
|
||||
|
||||
// Helper for getting a sequence of bits from an integer.
|
||||
func getBits(i uint32, cnt byte, from byte) byte {
|
||||
return byte((i >> from) & ((1 << cnt) - 1))
|
||||
}
|
||||
|
||||
// Converts an integer in the range 0~1112060 into a rune.
|
||||
// Based on the ranges table in https://en.wikipedia.org/wiki/UTF-8
|
||||
func intToRune(i uint32) rune {
|
||||
if i < (1 << ONE_BYTE_BITS) {
|
||||
return rune(i)
|
||||
}
|
||||
|
||||
if i < (1 << TWO_BYTE_BITS) {
|
||||
r, size := utf8.DecodeRune([]byte{0b11000000 | getBits(i, 5, 6), 0b10000000 | getBits(i, 6, 0)})
|
||||
if size != 2 || r == utf8.RuneError {
|
||||
panic(fmt.Sprintf("Error encoding an int %d with size 2, got rune %v and size %d", size, r, i))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
// Last -3 here needed because for some reason 3rd to last codepoint 65533 in this range
|
||||
// was returning utf8.RuneError during encoding.
|
||||
if i < ((1 << THREE_BYTE_BITS) - UNICODE_INVALID_RANGE_DELTA - 3) {
|
||||
if i >= UNICODE_INVALID_RANGE_START {
|
||||
i += UNICODE_INVALID_RANGE_DELTA
|
||||
}
|
||||
|
||||
r, size := utf8.DecodeRune([]byte{0b11100000 | getBits(i, 4, 12), 0b10000000 | getBits(i, 6, 6), 0b10000000 | getBits(i, 6, 0)})
|
||||
if size != 3 || r == utf8.RuneError {
|
||||
panic(fmt.Sprintf("Error encoding an int %d with size 3, got rune %v and size %d", size, r, i))
|
||||
}
|
||||
return r
|
||||
}
|
||||
|
||||
if i < (1<<FOUR_BYTE_BITS - UNICODE_INVALID_RANGE_DELTA - 3) {
|
||||
i += UNICODE_INVALID_RANGE_DELTA + 3
|
||||
r, size := utf8.DecodeRune([]byte{0b11110000 | getBits(i, 3, 18), 0b10000000 | getBits(i, 6, 12), 0b10000000 | getBits(i, 6, 6), 0b10000000 | getBits(i, 6, 0)})
|
||||
if size != 4 || r == utf8.RuneError {
|
||||
panic(fmt.Sprintf("Error encoding an int %d with size 4, got rune %v and size %d", size, r, i))
|
||||
}
|
||||
return r
|
||||
}
|
||||
panic(fmt.Sprintf("The integer %d is too large for runeToInt()", i))
|
||||
}
|
||||
|
||||
// Converts a rune generated by intToRune back to an integer
|
||||
func runeToInt(r rune) uint32 {
|
||||
i := uint32(r)
|
||||
if i < (1 << ONE_BYTE_BITS) {
|
||||
return i
|
||||
}
|
||||
|
||||
bytes := []byte{0, 0, 0, 0}
|
||||
|
||||
size := utf8.EncodeRune(bytes, r)
|
||||
|
||||
if size == 2 {
|
||||
return uint32(bytes[0]&0b11111)<<6 | uint32(bytes[1]&0b111111)
|
||||
}
|
||||
|
||||
if size == 3 {
|
||||
result := uint32(bytes[0]&0b1111)<<12 | uint32(bytes[1]&0b111111)<<6 | uint32(bytes[2]&0b111111)
|
||||
if result >= UNICODE_INVALID_RANGE_END {
|
||||
return result - UNICODE_INVALID_RANGE_DELTA
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
if size == 4 {
|
||||
result := uint32(bytes[0]&0b111)<<18 | uint32(bytes[1]&0b111111)<<12 | uint32(bytes[2]&0b111111)<<6 | uint32(bytes[3]&0b111111)
|
||||
return result - UNICODE_INVALID_RANGE_DELTA - 3
|
||||
}
|
||||
|
||||
panic(fmt.Sprintf("Unexpected state decoding rune=%v size=%d", r, size))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user