Skip to content

Commit 987f6c7

Browse files
committed
Fix appending additional char
1 parent e704b3b commit 987f6c7

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/BlockScalars.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module BlockScalars
22

33
export @blk_str
44

5+
const ETX = '\x03' # ASCII control character: End of Text
56

67
const DEFAULT_STYLE = 'f'
78
const DEFAULT_CHOMP = 's'
@@ -23,8 +24,9 @@ function block(str::AbstractString, block_scalar::AbstractString="")
2324
DEFAULT_STYLE, DEFAULT_CHOMP
2425
end
2526

26-
# Append an additional character to force one more iteration of the style loop
27-
str *= '\0'
27+
# Append an additional, non-space, character to force one more iteration of the style
28+
# loop
29+
str *= ETX
2830

2931
out = IOBuffer()
3032
num_newlines = 0 # The number of newlines at the end of the string
@@ -40,7 +42,7 @@ function block(str::AbstractString, block_scalar::AbstractString="")
4042

4143
for next in str
4244
if curr == '\n'
43-
if !isspace(next)
45+
if !isspace(next) && next != ETX
4446
if prev == '\n'
4547
# Skip last newline in a sequence of sequential blank lines
4648
elseif !isspace(prev)

0 commit comments

Comments
 (0)