diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2015-08-14 20:00:22 +1200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2015-08-20 08:08:11 +1200 |
| commit | dc2544712c19720cd82f70461f6ad5525dc2db7e (patch) | |
| tree | 198a6c1162ffe5f85189b8c196447d776eac02ce /src/utils.rs | |
| parent | 8dbe2133fb342c0db21a583d10c2882a42f2e869 (diff) | |
Rewrite match expressions
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs index a57ffb008ea..f80e1185bae 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -82,6 +82,25 @@ pub fn format_mutability(mutability: ast::Mutability) -> &'static str { } } +// The width of the first line in s. +#[inline] +pub fn first_line_width(s: &str) -> usize { + match s.find('\n') { + Some(n) => n, + None => s.len(), + } +} + +// The width of the last line in s. +#[inline] +pub fn last_line_width(s: &str) -> usize { + match s.rfind('\n') { + Some(n) => s.len() - n, + None => s.len(), + } +} + +#[inline] fn is_skip(meta_item: &MetaItem) -> bool { match meta_item.node { MetaItem_::MetaWord(ref s) => *s == SKIP_ANNOTATION, @@ -95,6 +114,7 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool { } // Find the end of a TyParam +#[inline] pub fn end_typaram(typaram: &ast::TyParam) -> BytePos { typaram.bounds.last().map(|bound| match *bound { ast::RegionTyParamBound(ref lt) => lt.span, |
