diff options
author | Aleksey Kladov <[email protected]> | 2018-08-24 11:41:25 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-08-24 11:41:25 +0100 |
commit | 6cade3f6d8ad7bb5a11b1910689b25f709c12502 (patch) | |
tree | 96aea3209cc310462c37708d5623fe1f1d667634 /crates/libsyntax2/src/text_utils.rs | |
parent | 89e56c364f3d0a9d5a12ae488185abc1ea69df4a (diff) |
Runnig tests somehow
Diffstat (limited to 'crates/libsyntax2/src/text_utils.rs')
-rw-r--r-- | crates/libsyntax2/src/text_utils.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/crates/libsyntax2/src/text_utils.rs b/crates/libsyntax2/src/text_utils.rs new file mode 100644 index 000000000..e3d73888f --- /dev/null +++ b/crates/libsyntax2/src/text_utils.rs | |||
@@ -0,0 +1,19 @@ | |||
1 | use {TextRange, TextUnit}; | ||
2 | |||
3 | pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool { | ||
4 | range.start() <= offset && offset <= range.end() | ||
5 | } | ||
6 | |||
7 | pub fn is_subrange(range: TextRange, subrange: TextRange) -> bool { | ||
8 | range.start() <= subrange.start() && subrange.end() <= range.end() | ||
9 | } | ||
10 | |||
11 | pub fn intersect(r1: TextRange, r2: TextRange) -> Option<TextRange> { | ||
12 | let start = r1.start().max(r2.start()); | ||
13 | let end = r1.end().min(r2.end()); | ||
14 | if start <= end { | ||
15 | Some(TextRange::from_to(start, end)) | ||
16 | } else { | ||
17 | None | ||
18 | } | ||
19 | } | ||