mirror of
https://github.com/go-gitea/gitea.git
synced 2024-10-30 08:27:32 -04:00
56 lines
1.1 KiB
Go
Vendored
56 lines
1.1 KiB
Go
Vendored
// Copyright 2014-2021 Ulrich Kunitz. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package lzma
|
|
|
|
import (
|
|
"fmt"
|
|
"unicode"
|
|
)
|
|
|
|
// operation represents an operation on the dictionary during encoding or
|
|
// decoding.
|
|
type operation interface {
|
|
Len() int
|
|
}
|
|
|
|
// rep represents a repetition at the given distance and the given length
|
|
type match struct {
|
|
// supports all possible distance values, including the eos marker
|
|
distance int64
|
|
// length
|
|
n int
|
|
}
|
|
|
|
// Len returns the number of bytes matched.
|
|
func (m match) Len() int {
|
|
return m.n
|
|
}
|
|
|
|
// String returns a string representation for the repetition.
|
|
func (m match) String() string {
|
|
return fmt.Sprintf("M{%d,%d}", m.distance, m.n)
|
|
}
|
|
|
|
// lit represents a single byte literal.
|
|
type lit struct {
|
|
b byte
|
|
}
|
|
|
|
// Len returns 1 for the single byte literal.
|
|
func (l lit) Len() int {
|
|
return 1
|
|
}
|
|
|
|
// String returns a string representation for the literal.
|
|
func (l lit) String() string {
|
|
var c byte
|
|
if unicode.IsPrint(rune(l.b)) {
|
|
c = l.b
|
|
} else {
|
|
c = '.'
|
|
}
|
|
return fmt.Sprintf("L{%c/%02x}", c, l.b)
|
|
}
|