diff options
author | Paul Phillips <paulp@improving.org> | 2012-12-05 12:34:13 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-12-05 13:13:55 -0800 |
commit | c42c1742e26dc47f940e4003e4ca25e8c738796d (patch) | |
tree | 637acdd45dbf93ba87ae6cb67d4237da652ac8c1 /src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala | |
parent | 4b2330b3d3db4263a8b1e19b792596dd60d79045 (diff) | |
parent | b84ecc5d1afcb71dd4047de9f1cc49060835d3df (diff) | |
download | scala-c42c1742e26dc47f940e4003e4ca25e8c738796d.tar.gz scala-c42c1742e26dc47f940e4003e4ca25e8c738796d.tar.bz2 scala-c42c1742e26dc47f940e4003e4ca25e8c738796d.zip |
Merge branch 'merge-2.10-wip' into merge-2.10
* merge-2.10-wip:
Fixing OSGi distribution.
Fix for rangepos crasher.
SI-6685 fixes error handling in typedApply
Test cases for SI-5726, SI-5733, SI-6320, SI-6551, SI-6722.
Asserts about Tree qualifiers.
Fix for SI-6731, dropped trees in selectDynamic.
neg test added
SI-5753 macros cannot be loaded when inherited from a class or a trait
Take advantage of the margin stripping interpolator.
Adds a margin stripping string interpolator.
SI-6718 fixes a volatile test
Mark pattern matcher synthetics as SYNTHETIC.
Set symbol flags at creation.
Fix for SI-6687, wrong isVar logic.
Fix for SI-6706, Symbol breakage under GC.
findEntry implementation code more concise and DRYer.
Fix for SI-6357, cycle with value classes.
Refactoring of adaptMethod
SI-6677 Insert required cast in `new qual.foo.T`
Conflicts:
src/compiler/scala/tools/nsc/transform/Erasure.scala
src/compiler/scala/tools/nsc/typechecker/Typers.scala
src/reflect/scala/reflect/internal/SymbolTable.scala
src/reflect/scala/reflect/internal/util/package.scala
test/files/neg/gadts1.check
Diffstat (limited to 'src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala')
-rw-r--r-- | src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala b/src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala new file mode 100644 index 0000000000..e7579229b2 --- /dev/null +++ b/src/reflect/scala/reflect/internal/util/StripMarginInterpolator.scala @@ -0,0 +1,40 @@ +package scala.reflect +package internal +package util + +trait StripMarginInterpolator { + def stringContext: StringContext + + /** + * A safe combination of `[[scala.collection.immutable.StringLike#stripMargin]] + * and [[scala.StringContext#raw]]. + * + * The margin of each line is defined by whitespace leading up to a '|' character. + * This margin is stripped '''before''' the arguments are interpolated into to string. + * + * String escape sequences are '''not''' processed; this interpolater is designed to + * be used with triple quoted Strings. + * + * {{{ + * scala> val foo = "f|o|o" + * foo: String = f|o|o + * scala> sm"""|${foo} + * |""" + * res0: String = + * "f|o|o + * " + * }}} + */ + final def sm(args: Any*): String = { + def isLineBreak(c: Char) = c == '\n' || c == '\f' // compatible with StringLike#isLineBreak + def stripTrailingPart(s: String) = { + val (pre, post) = s.span(c => !isLineBreak(c)) + pre + post.stripMargin + } + val stripped: List[String] = stringContext.parts.toList match { + case head :: tail => head.stripMargin :: (tail map stripTrailingPart) + case Nil => Nil + } + new StringContext(stripped: _*).raw(args: _*) + } +} |