Skip to content

Commit

Permalink
text-util: introduce text_range_equal
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jul 28, 2015
1 parent 6d7aa20 commit f38ab16
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions text-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Filerange text_range_new(size_t a, size_t b) {
};
}

bool text_range_equal(Filerange *r1, Filerange *r2) {
if (!text_range_valid(r1) && !text_range_valid(r2))
return true;
return r1->start == r2->start && r1->end == r2->end;
}

bool text_range_overlap(Filerange *r1, Filerange *r2) {
if (!text_range_valid(r1) || !text_range_valid(r2))
return false;
Expand Down
2 changes: 2 additions & 0 deletions text-util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Filerange text_range_empty(void);
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);
/* test whether two ranges are equal */
bool text_range_equal(Filerange*, Filerange*);
/* test whether two ranges overlap */
bool text_range_overlap(Filerange*, Filerange*);
/* test whether a given position is within a certain range */
Expand Down

0 comments on commit f38ab16

Please sign in to comment.