difflib

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package difflib is a partial port of Python difflib module.

Copyright (c) 2013, Patrick Mezard

Redistributions of source code must retain the above copyright

notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright

notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

The names of its contributors may not be used to endorse or promote

products derived from this software without specific prior written permission.

GRAPHQL PACKAGE NOTICE This is a modified version of https://github.com/pmezard/go-difflib/blob/master/difflib/difflib.go that is simplified for the parrent package

It provides tools to compare sequences of strings and generate textual diffs. The following class and functions have been ported: - SequenceMatcher - unified_diff - context_diff Getting unified diffs was the main goal of the port. Keep in mind this code is mostly suitable to output text differences in a human friendly way, there are no guarantees generated diffs are consumable by patch(1).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetUnifiedDiffString

func GetUnifiedDiffString(a, b []string) (string, error)

GetUnifiedDiffString is Like WriteUnifiedDiff but returns the diff a string.

func SplitLines

func SplitLines(s string) []string

SplitLines Splits a string on "\n" while preserving them. The output can be used as input for UnifiedDiff and ContextDiff structures.

func WriteUnifiedDiff

func WriteUnifiedDiff(writer io.Writer, a, b []string) error

WriteUnifiedDiff Compares two sequences of lines; generate the delta as a unified diff.

Unified diffs are a compact way of showing line changes and a few lines of context. The number of context lines is set by 'n' which defaults to three.

By default, the diff control lines (those with ---, +++, or @@) are created with a trailing newline. This is helpful so that inputs created from file.readlines() result in diffs that are suitable for file.writelines() since both the inputs and outputs have trailing newlines.

For inputs that do not have trailing newlines, set the lineterm argument to "" so that the output will be uniformly newline free.

The unidiff format normally has a header for filenames and modification times. Any or all of these may be specified using strings for 'fromfile', 'tofile', 'fromfiledate', and 'tofiledate'. The modification times are normally expressed in the ISO 8601 format.

Types

This section is empty.

Jump to

Keyboard shortcuts

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