lines

package
v0.0.0-...-3bb151c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lines 提供按行表示文本以及生成行级 diff 的辅助能力。

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Diff

func Diff(oldLines Lines, newLines Lines) []byte

Diff 生成 oldLines 到 newLines 的逐行差异文本。

Example
package main

import (
	"fmt"

	"github.com/octohelm/x/testing/lines"
)

func main() {
	diff := lines.Diff(
		lines.Lines{"a", "b"},
		lines.Lines{"a", "c"},
	)

	fmt.Print(string(diff))
}
Output:

@@ -2,1 +2,1 @@
-b
+c

Types

type Differ

type Differ interface {
	Lines() Lines
}

Differ 表示可导出为 Lines 的对象。

type Lines

type Lines []string

Lines 表示按行拆分后的文本。

func FromBytes

func FromBytes(data []byte) Lines

FromBytes 将字节切片按行拆分为 Lines。

Example
package main

import (
	"fmt"

	"github.com/octohelm/x/testing/lines"
)

func main() {
	fmt.Println(lines.FromBytes([]byte("a\nb\n")))
}
Output:
[a b]

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL