scala中的缩进保留字符串插值 [英] Indentation preserving string interpolation in scala

查看:53
本文介绍了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).

这篇关于scala中的缩进保留字符串插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆