Skip to content

Commit

Permalink
text: add text_range_overlap
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Jul 24, 2015
1 parent 0329e4a commit e57b57e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
6 changes: 6 additions & 0 deletions text.c
Original file line number Diff line number Diff line change
Expand Up @@ -1496,3 +1496,9 @@ Filerange text_range_new(size_t a, size_t b) {
.end = MAX(a, b),
};
}

bool text_range_overlap(Filerange *r1, Filerange *r2) {
if (!text_range_valid(r1) || !text_range_valid(r2))
return false;
return r1->start <= r2->end && r2->start <= r1->end;
}
2 changes: 2 additions & 0 deletions text.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,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 overlap */
bool text_range_overlap(Filerange*, Filerange*);

typedef struct Text Text;
typedef struct Piece Piece;
Expand Down

0 comments on commit e57b57e

Please sign in to comment.