Skip to content

Commit 9521a85

Browse files
committed
Add docstrings
1 parent 787d610 commit 9521a85

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/BlockScalars.jl

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,42 @@ const ETX = '\x03' # ASCII control character: End of Text
66
const DEFAULT_STYLE = :folded
77
const DEFAULT_CHOMP = :strip
88

9+
"""
10+
block(str, style=$(repr(DEFAULT_STYLE)), chomp=$(repr(DEFAULT_CHOMP))) -> AbstractString
11+
12+
Revise a multiline string according to the provided `style` and `chomp`. Works similarly to
13+
YAML multiline strings (also known as block scalars).
14+
15+
# Arguments
16+
- `str::AbstractString`: The multiline string to be processed
17+
18+
# Keywords
19+
- `style::Symbol`: Replace newlines with spaces (`:folded`) or keep newlines (`:literal`)
20+
- `chomp::Symbol`: No newlines at the end (`:strip`), single newline at the end (`:clip`),
21+
or keep all newlines from the end (`:keep`)
22+
"""
923
function block(str::AbstractString; style=DEFAULT_STYLE, chomp=DEFAULT_CHOMP)
1024
block(str, style, chomp)
1125
end
1226

27+
"""
28+
block(str, indicators) -> AbstractString
29+
30+
Revise a multiline string according to the provided style and chomp encoded in the
31+
`indicators` string.
32+
33+
# Arguments
34+
- `str::AbstractString`: The multiline string to be processed
35+
- `indicators::AbstractString`: A terse string representing the style and chomp. Indicators
36+
can be either in letter-form or in YAML-form:
37+
38+
- "fs" / ">-": folded and strip
39+
- "fc" / ">": folded and clip
40+
- "fk" / ">+": folded and keep
41+
- "ls" / "|-": literal and strip
42+
- "lc" / "|": literal and clip
43+
- "lk" / "|+": literal and keep
44+
"""
1345
function block(str::AbstractString, indicators::AbstractString)
1446
indicators_len = length(indicators)
1547
indicators_len > 2 && throw(ArgumentError("Too many indicators provided"))
@@ -145,6 +177,20 @@ function block(str::AbstractString, style::Symbol, chomp::Symbol)
145177
return String(take!(out))
146178
end
147179

180+
"""
181+
@blk_str -> String
182+
183+
Construct a multiline string according to the indicators listed after the ending quote:
184+
185+
- `f` replace newlines with spaces (folded)
186+
- `l` keep newlines (literal)
187+
- `s` no newlines at the end (strip)
188+
- `c` single newline at the end (clip)
189+
- `k` keep all newlines from the end (keep)
190+
191+
Note string interpolation is still respected any newlines added from interpolation will be
192+
also be processed.
193+
"""
148194
macro blk_str(str::AbstractString, indicators::AbstractString="")
149195
parsed = interpolate(str)
150196

0 commit comments

Comments
 (0)