diff options
| author | Marc André Tanner <mat@brain-dump.org> | 2017-06-14 14:03:22 +0200 |
|---|---|---|
| committer | Marc André Tanner <mat@brain-dump.org> | 2017-06-15 15:51:43 +0200 |
| commit | 4f0c14bd3f4600930a3ebad8a2ee82b6ca2c89d4 (patch) | |
| tree | 91cb8fb7b62fe8d85b648376e539c32cee49c629 /text-util.c | |
| parent | 8a1fcdfd93c162af9aa3446849d2c4320c44c7a5 (diff) | |
| download | vis-4f0c14bd3f4600930a3ebad8a2ee82b6ca2c89d4.tar.gz vis-4f0c14bd3f4600930a3ebad8a2ee82b6ca2c89d4.tar.xz | |
text-util: add text_range_intersect utility function
Diffstat (limited to 'text-util.c')
| -rw-r--r-- | text-util.c | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/text-util.c b/text-util.c index f198d81..4936d92 100644 --- a/text-util.c +++ b/text-util.c @@ -27,6 +27,12 @@ Filerange text_range_union(const Filerange *r1, const Filerange *r2) { }; } +Filerange text_range_intersect(const Filerange *r1, const Filerange *r2) { + if (!text_range_overlap(r1, r2)) + return text_range_empty(); + return text_range_new(MAX(r1->start, r2->start), MIN(r1->end, r2->end)); +} + Filerange text_range_new(size_t a, size_t b) { return (Filerange) { .start = MIN(a, b), |
