Skip to content

Commit a494e11

Browse files
committed
Support YAML indicators
1 parent da4066c commit a494e11

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

src/BlockScalars.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,15 @@ function block(str::AbstractString, indicators::AbstractString)
1515
indicators_len > 2 && throw(ArgumentError("Too many indicators provided"))
1616

1717
# Note: Using '\0` to indicate undefined
18+
yaml_chomp = false
1819
style_char, chomp_char = if indicators_len == 2
1920
indicators
2021
elseif indicators_len == 1
2122
ind = indicators[1]
22-
if ind in "fl"
23+
if ind in ('f', 'l')
24+
ind, '\0'
25+
elseif ind in ('>', '|')
26+
yaml_chomp = true
2327
ind, '\0'
2428
else
2529
'\0', ind
@@ -28,21 +32,25 @@ function block(str::AbstractString, indicators::AbstractString)
2832
'\0', '\0'
2933
end
3034

31-
style = if style_char == 'f'
35+
if style_char != '\0' && chomp_char != '\0' && isletter(style_char) isletter(chomp_char)
36+
throw(ArgumentError("Can't mix YAML style block indicators with letter indicators"))
37+
end
38+
39+
style = if style_char == 'f' || style_char == '>'
3240
:folded
33-
elseif style_char == 'l'
41+
elseif style_char == 'l' || style_char == '|'
3442
:literal
3543
elseif style_char == '\0'
3644
DEFAULT_STYLE
3745
else
3846
throw(ArgumentError("Unknown block style indicator: $(repr(style_char))"))
3947
end
4048

41-
chomp = if chomp_char == 'c'
49+
chomp = if chomp_char == 'c' || yaml_chomp
4250
:clip
43-
elseif chomp_char == 's'
51+
elseif chomp_char == 's' || chomp_char == '-'
4452
:strip
45-
elseif chomp_char == 'k'
53+
elseif chomp_char == 'k' || chomp_char == '+'
4654
:keep
4755
elseif chomp_char == '\0'
4856
DEFAULT_CHOMP

test/runtests.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ end
5252
@test block(str, "lk") == expected_lk
5353
@test block(str, "lc") == expected_lc
5454
@test block(str, "ls") == expected_ls
55+
56+
@test block(str, "|+") == expected_lk
57+
@test block(str, "|-") == expected_ls
5558
end
5659

5760
@testset "folding" begin
@@ -66,6 +69,9 @@ end
6669
@test block(str, "fk") == expected_fk
6770
@test block(str, "fc") == expected_fc
6871
@test block(str, "fs") == expected_fs
72+
73+
@test block(str, ">+") == expected_fk
74+
@test block(str, ">-") == expected_fs
6975
end
7076

7177
@testset "default chomp" begin
@@ -77,6 +83,9 @@ end
7783

7884
@test block(str, "l") == expected_ls
7985
@test block(str, "f") == expected_fs
86+
87+
@test block(str, "|") == expected_lc
88+
@test block(str, ">") == expected_fc
8089
end
8190

8291
@testset "default style" begin
@@ -87,6 +96,9 @@ end
8796
@test block(str, "k") == expected_fk
8897
@test block(str, "c") == expected_fc
8998
@test block(str, "s") == expected_fs
99+
100+
@test block(str, "+") == expected_fk
101+
@test block(str, "-") == expected_fs
90102
end
91103

92104
@testset "default style/chomp" begin

0 commit comments

Comments
 (0)