File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change 87
87
(mut _index _startingIndex)
88
88
89
89
(let _end
90
- (if (> _length (len _string))
90
+ (if (>= _length (len _string))
91
91
(len _string)
92
92
(+ _index _length)))
93
93
183
183
"")))
184
184
(set _index (+ 1 _index)) })
185
185
_output }))
186
+
187
+ # @brief Strip the margin of a multiline string
188
+ # @param _str multiline string, margin is (space)*(|)
189
+ # =begin
190
+ # (let s "hello
191
+ # |abc
192
+ # |def")
193
+ # (string:stripMargin s)
194
+ # =end
195
+ (let stripMargin (fun (_str) {
196
+ (mut _output "")
197
+ (let _lines (split _str "\n"))
198
+ (let _line_count (len _lines))
199
+ (mut _index 0)
200
+
201
+ (while (< _index _line_count) {
202
+ (let _current (@ _lines _index))
203
+ (let _marker_pos (string:find _current "|"))
204
+ (if (= -1 _marker_pos)
205
+ (set _output (+ _output _current))
206
+ (set _output (+ _output (slice _current (+ 1 _marker_pos) (len _current)))))
207
+ (set _index (+ 1 _index))
208
+ (if (!= _index _line_count)
209
+ (set _output (+ _output "\n"))) })
210
+
211
+ _output }))
Original file line number Diff line number Diff line change 29
29
30
30
(test:eq "hello;3.14;true;world" (string:join ["hello" 3.14 true "world"] ";"))
31
31
(test:eq "hello" (string:join ["hello"] ";"))
32
- (test:eq "" (string:join [] ";;"))})
32
+ (test:eq "" (string:join [] ";;"))
33
+
34
+ (test:eq "" (string:stripMargin ""))
35
+ (test:eq " hello" (string:stripMargin " hello"))
36
+ (test:eq "hello" (string:stripMargin " |hello"))
37
+ (test:eq "hello\nabc"
38
+ (string:stripMargin " |hello
39
+ |abc"))
40
+ (test:eq "hello\nabc\nd"
41
+ (string:stripMargin "hello
42
+ |abc
43
+ |d"))
44
+ })
You can’t perform that action at this time.
0 commit comments