main
Raw Download raw file
 1// Copyright 2014-2022 Ulrich Kunitz. All rights reserved.
 2// Use of this source code is governed by a BSD-style
 3// license that can be found in the LICENSE file.
 4
 5package lzma
 6
 7import (
 8	"fmt"
 9	"unicode"
10)
11
12// operation represents an operation on the dictionary during encoding or
13// decoding.
14type operation interface {
15	Len() int
16}
17
18// rep represents a repetition at the given distance and the given length
19type match struct {
20	// supports all possible distance values, including the eos marker
21	distance int64
22	// length
23	n int
24}
25
26// Len returns the number of bytes matched.
27func (m match) Len() int {
28	return m.n
29}
30
31// String returns a string representation for the repetition.
32func (m match) String() string {
33	return fmt.Sprintf("M{%d,%d}", m.distance, m.n)
34}
35
36// lit represents a single byte literal.
37type lit struct {
38	b byte
39}
40
41// Len returns 1 for the single byte literal.
42func (l lit) Len() int {
43	return 1
44}
45
46// String returns a string representation for the literal.
47func (l lit) String() string {
48	var c byte
49	if unicode.IsPrint(rune(l.b)) {
50		c = l.b
51	} else {
52		c = '.'
53	}
54	return fmt.Sprintf("L{%c/%02x}", c, l.b)
55}