From 41bca58100260323e54ff83e5bc74dd920beabcd Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Fri, 14 Aug 2015 14:09:19 +0200 Subject: Format paths --- src/utils.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/utils.rs') diff --git a/src/utils.rs b/src/utils.rs index 3ff30da9784..59f85b3ad27 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -15,6 +15,16 @@ use comment::FindUncommented; use SKIP_ANNOTATION; +// Computes the length of a string's last line, minus offset. +#[inline] +pub fn extra_offset(text: &str, offset: usize) -> usize { + match text.rfind('\n') { + // 1 for newline character + Some(idx) => text.len() - idx - 1 - offset, + None => text.len() + } +} + #[inline] pub fn span_after(original: Span, needle: &str, codemap: &CodeMap) -> BytePos { let snippet = codemap.span_to_snippet(original).unwrap(); -- cgit 1.4.1-3-g733a5