aboutsummaryrefslogtreecommitdiff
path: root/crates/libsyntax2/src/text_utils.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2018-08-24 11:41:25 +0100
committerAleksey Kladov <[email protected]>2018-08-24 11:41:25 +0100
commit6cade3f6d8ad7bb5a11b1910689b25f709c12502 (patch)
tree96aea3209cc310462c37708d5623fe1f1d667634 /crates/libsyntax2/src/text_utils.rs
parent89e56c364f3d0a9d5a12ae488185abc1ea69df4a (diff)
Runnig tests somehow
Diffstat (limited to 'crates/libsyntax2/src/text_utils.rs')
-rw-r--r--crates/libsyntax2/src/text_utils.rs19
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 @@
1use {TextRange, TextUnit};
2
3pub fn contains_offset_nonstrict(range: TextRange, offset: TextUnit) -> bool {
4 range.start() <= offset && offset <= range.end()
5}
6
7pub fn is_subrange(range: TextRange, subrange: TextRange) -> bool {
8 range.start() <= subrange.start() && subrange.end() <= range.end()
9}
10
11pub 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}