A line-oriented textual difference implementation. More...
Classes | |
| struct | sourcemeta::core::Diff |
Functions | |
| SOURCEMETA_CORE_DIFF_EXPORT auto | sourcemeta::core::diff (const std::string_view original, const std::string_view modified, const Diff::Mode mode, const Diff::Algorithm algorithm) -> Diff |
| SOURCEMETA_CORE_DIFF_EXPORT auto | sourcemeta::core::stringify (const Diff &document, std::ostream &stream, const Diff::Format format, const Diff::FormatOptions &options={}) -> void |
A line-oriented textual difference implementation.
This functionality is included as follows:
| struct sourcemeta::core::Diff |
The result of comparing two inputs, holding the tokens of each alongside the operations that relate them, plus the vocabulary that describes how a comparison is performed and rendered.
The tokens are views into the inputs that were compared, which must outlive this result.
Public Types | |
| enum class | Mode : std::uint8_t { Line } |
| The granularity at which inputs are compared. More... | |
| enum class | Algorithm : std::uint8_t { Myers } |
| The strategy used to locate the common subsequences of two inputs. More... | |
| enum class | Format : std::uint8_t { Unified } |
| The textual serialisation used to render a set of differences. More... | |
Public Attributes | |
| std::vector< std::string_view > | original |
| The tokens of the original input. | |
| std::vector< std::string_view > | modified |
| The tokens of the modified input. | |
| std::vector< Operation > | operations |
| The transformations that turn the original input into the modified one. | |
| bool | original_ends_with_newline {true} |
| Whether the original input ended with a line terminator. | |
| bool | modified_ends_with_newline {true} |
| Whether the modified input ended with a line terminator. | |
|
strong |
The strategy used to locate the common subsequences of two inputs.
| Enumerator | |
|---|---|
| Myers | A greedy shortest edit script search over the edit graph, as described by Eugene W. Myers in "An O(ND) Difference Algorithm and Its Variations", Algorithmica Vol. 1, 1986, pp. 251-266 (http://www.xmailserver.org/diff2.pdf) |
|
strong |
The textual serialisation used to render a set of differences.
| Enumerator | |
|---|---|
| Unified | The unified format, as standardised by POSIX in IEEE Std 1003.1-2024 (https://pubs.opengroup.org/onlinepubs/9799919799/utilities/diff.html) |
|
strong |
| SOURCEMETA_CORE_DIFF_EXPORT auto sourcemeta::core::diff | ( | const std::string_view | original, |
| const std::string_view | modified, | ||
| const Diff::Mode | mode, | ||
| const Diff::Algorithm | algorithm ) -> Diff |
Compute the differences between two inputs. For example:
The tokens of the result are views into the given inputs, which must outlive it.
| SOURCEMETA_CORE_DIFF_EXPORT auto sourcemeta::core::stringify | ( | const Diff & | document, |
| std::ostream & | stream, | ||
| const Diff::Format | format, | ||
| const Diff::FormatOptions & | options = {} ) -> void |
Render a set of differences into a given C++ standard output stream. For example: