File tree Expand file tree Collapse file tree 1 file changed +34
-13
lines changed Expand file tree Collapse file tree 1 file changed +34
-13
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ function block(str::AbstractString, block_scalar::AbstractString="")
24
24
end
25
25
26
26
out = IOBuffer ()
27
- ending = IOBuffer ()
27
+ num_newlines = 0
28
28
29
29
if style == ' f'
30
30
# The code below is equivalent to these two regexes:
@@ -43,14 +43,16 @@ function block(str::AbstractString, block_scalar::AbstractString="")
43
43
elseif ! isspace (prev)
44
44
write (out, ' ' )
45
45
else
46
- write (ending, ' \n ' )
46
+ num_newlines += 1
47
47
end
48
48
else
49
- write (ending, ' \n ' )
49
+ num_newlines += 1
50
50
end
51
51
elseif curr != ' \0 '
52
- write (out, take! (ending))
53
- ending = IOBuffer ()
52
+ if num_newlines > 0
53
+ write (out, " \n " ^ num_newlines)
54
+ num_newlines = 0
55
+ end
54
56
55
57
write (out, curr)
56
58
end
@@ -59,32 +61,51 @@ function block(str::AbstractString, block_scalar::AbstractString="")
59
61
curr = next
60
62
end
61
63
62
- write (out, curr)
64
+ if curr == ' \n '
65
+ num_newlines += 1
66
+ elseif curr != ' \0 '
67
+ if num_newlines > 0
68
+ write (out, " \n " ^ num_newlines)
69
+ num_newlines = 0
70
+ end
71
+
72
+ write (out, curr)
73
+ end
63
74
elseif style == ' l'
64
75
curr = ' \0 '
65
76
for next in str
66
77
if curr == ' \n '
67
- write (ending, ' \n ' )
78
+ num_newlines += 1
68
79
elseif curr != ' \0 '
69
- write (out, take! (ending))
70
- ending = IOBuffer ()
80
+ if num_newlines > 0
81
+ write (out, " \n " ^ num_newlines)
82
+ num_newlines = 0
83
+ end
71
84
72
85
write (out, curr)
73
86
end
74
87
75
88
curr = next
76
89
end
77
90
78
- write (out, curr)
91
+ if curr == ' \n '
92
+ num_newlines += 1
93
+ elseif curr != ' \0 '
94
+ if num_newlines > 0
95
+ write (out, " \n " ^ num_newlines)
96
+ num_newlines = 0
97
+ end
98
+
99
+ write (out, curr)
100
+ end
79
101
else
80
102
throw (ArgumentError (" Unknown block style indicator: $(repr (style)) " ))
81
103
end
82
104
83
- seekstart (ending)
84
105
if chomp == ' c'
85
- ! eof (ending) && write (out, read (ending, Char) )
106
+ num_newlines > 0 && write (out, ' \n ' )
86
107
elseif chomp == ' k'
87
- write (out, ending )
108
+ write (out, " \n " ^ num_newlines )
88
109
elseif chomp != ' s'
89
110
throw (ArgumentError (" Unknown block chomping indicator: $(repr (chomp)) " ))
90
111
end
You can’t perform that action at this time.
0 commit comments