Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_diff.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
27
28#ifndef __N_DIFF_H
29#define __N_DIFF_H
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
60
61#include "nilorea/n_list.h"
62#include "nilorea/n_str.h"
63
65#define N_DIFF_COMMON 0
67#define N_DIFF_DELETE 1
69#define N_DIFF_INSERT 2
70
72#define N_DIFF_NO_LINE ((size_t)-1)
73
75#define N_DIFF_CONTEXT_FULL ((size_t)-1)
76
78#define N_DIFF_MAX_EDITS_DEFAULT 1000
79
82#define N_DIFF_MAX_EDITS_CEILING 4000
83
85typedef struct N_DIFF_LINE {
87 char* text;
89 size_t line_a;
91 size_t line_b;
93 int op;
95
110
121N_DIFF_RESULT* n_diff_lines(const char* text_a, const char* text_b, size_t max_edits);
122
125void n_diff_result_free(N_DIFF_RESULT** result);
126
136N_STR* n_diff_to_unified(const N_DIFF_RESULT* result, size_t context);
137
141
142#ifdef __cplusplus
143}
144#endif
145
146/* #ifndef __N_DIFF_H */
147#endif
Structure of a generic LIST container.
Definition n_list.h:59
size_t line_a
zero based position in the first text, or N_DIFF_NO_LINE
Definition n_diff.h:89
int truncated
1 when the edit limit was hit and the differing region was reported as one delete run followed by one...
Definition n_diff.h:108
size_t nb_deleted
number of N_DIFF_DELETE lines
Definition n_diff.h:103
size_t nb_inserted
number of N_DIFF_INSERT lines
Definition n_diff.h:105
size_t nb_common
number of N_DIFF_COMMON lines
Definition n_diff.h:101
int op
N_DIFF_COMMON, N_DIFF_DELETE or N_DIFF_INSERT.
Definition n_diff.h:93
char * text
line content, without its newline, owned by the result
Definition n_diff.h:87
size_t line_b
zero based position in the second text, or N_DIFF_NO_LINE
Definition n_diff.h:91
LIST * lines
LIST of N_DIFF_LINE*, in output order.
Definition n_diff.h:99
void n_diff_result_free(N_DIFF_RESULT **result)
Free an edit script and every line it holds.
Definition n_diff.c:333
N_DIFF_RESULT * n_diff_lines(const char *text_a, const char *text_b, size_t max_edits)
Compare two texts line by line.
Definition n_diff.c:252
N_STR * n_diff_to_unified(const N_DIFF_RESULT *result, size_t context)
Render an edit script as unified diff text.
Definition n_diff.c:391
one line of an edit script
Definition n_diff.h:85
edit script turning one text into another
Definition n_diff.h:97
A box including a string and his lenght.
Definition n_str.h:61
List structures and definitions.
N_STR and string function declaration.