当在缩进位置使用三重引号时,我也确保在输出js字符串中也获得缩进:
比较这两个嵌套的let
let input1 = "T1\nX55.555Y-44.444\nX52.324Y-40.386"
let input2 = """T1
X66.324Y-40.386
X52.324Y-40.386"""
给予
// single quotes with \n
"T1\x0aX55.555Y-44.444\x0aX52.324Y-40.386"
// triple quoted
"T1\x0a X66.324Y-40.386\x0a X52.324Y-40.386"
Scala中是否有达成共识的东西,例如stripMargin
,所以我可以使用它们而不必缩进顶层?
更新,只是为了澄清我的意思,我正在做:
describe "header" do
it "should parse example header" do
let input = """M48
;DRILL file {KiCad 4.0.7} date Wednesday, 31 January 2018 'AMt' 11:08:53
;FORMAT={-:-/ absolute / metric / decimal}
FMAT,2
METRIC,TZ
T1C0.300
T2C0.400
T3C0.600
T4C0.800
T5C1.000
T6C1.016
T7C3.400
%
"""
doesParse input header
describe "hole" do
it "should parse a simple hole" do
doesParse "X52.324Y-40.386" hole
更新:
我被要求澄清Scala的stripMargin。它的用法如下:
val speech = """T1
|X66.324Y-40.386
|X52.324Y-40.386""".stripMargin
然后删除前导空格。 stripMargin
可以使用任何分隔符,但默认为|。
更多示例:
铁锈有https://docs.rs/trim-margin/0.1.0/trim_margin/Kotlin在stdlib中具有:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/trim-margin.html
我想这听起来可能像是在请求左键盘(:),但是如果已经有东西了,我宁愿不要自己酿造……
对不起,您对此没有得到及时的答复,但是我已经实现了此功能here。如果拉取请求未合并,则此实现仅取决于purescript-strings
:
purescript-strings