From be21d229b92a66c61feebc9a6f12c0957b0ba5c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Andr=C3=A9=20Tanner?= Date: Wed, 22 Jul 2015 08:45:02 +0200 Subject: text: introduce text_range_new --- text.c | 7 +++++++ text.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/text.c b/text.c index 5f516bc..ab8a846 100644 --- a/text.c +++ b/text.c @@ -1489,3 +1489,10 @@ Filerange text_range_union(Filerange *r1, Filerange *r2) { .end = MAX(r1->end, r2->end), }; } + +Filerange text_range_new(size_t a, size_t b) { + return (Filerange) { + .start = MIN(a, b), + .end = MAX(a, b), + }; +} diff --git a/text.h b/text.h index 89a5d9b..e5f1670 100644 --- a/text.h +++ b/text.h @@ -15,6 +15,7 @@ typedef struct { size_t start, end; /* range in bytes from start of the file */ } Filerange; + /* test whether the given range is valid (start <= end) */ bool text_range_valid(Filerange*); /* get the size of the range (end-start) or zero if invalid */ @@ -23,6 +24,8 @@ size_t text_range_size(Filerange*); Filerange text_range_empty(void); /* merge two ranges into a new one which contains both of them */ Filerange text_range_union(Filerange*, Filerange*); +/* create new range [min(a,b), max(a,b)] */ +Filerange text_range_new(size_t a, size_t b); typedef struct Text Text; typedef struct Piece Piece; -- cgit v1.2.3