scala中的缩进保留字符串插值
我想知道在 Scala 中进行字符串插值时是否有任何方法可以保留缩进.本质上,我想知道是否可以插入我自己的 StringContext.宏可以解决这个问题,但我想等到它们正式发布.
I was wondering if there is any way of preserving indentation while doing string interpolation in scala. Essentially, I was wondering if I could interpose my own StringContext. Macros would address this problem, but I'd like to wait until they are official.
这就是我想要的:
val x = "line1 \nline2"
val str = s"> ${x}"
str 应该评估为
> line1
line2
您可以编写自己的内插器,也可以使用自己的内插器遮蔽标准内插器.现在,我不知道您的示例背后的语义是什么,所以我什至不打算尝试.
You can write your own interpolators, and you can shadow the standard interpolators with your own. Now, I have no idea what's the semantic behind your example, so I'm not even going to try.
在 Slideshare 或 上查看我关于 Scala 2.10 的演示="https://speakerdeck.com/u/dcsobral/p/scala-2100-english-version" rel="noreferrer">SpeakerDeck,因为它们包含有关您可以编写的所有方式的示例/覆盖插值器.从第 40 张幻灯片开始(目前 - 演示文稿可能会更新到 2.10 最终发布).
Check out my presentation on Scala 2.10 on either Slideshare or SpeakerDeck, as they contain examples on all the manners in which you can write/override interpolators. Starts on slide 40 (for now -- the presentation might be updated until 2.10 is finally out).