Skip to content

Commit 393d0d7

Browse files
committed
Write README
1 parent db34ce0 commit 393d0d7

File tree

2 files changed

+66
-6
lines changed

2 files changed

+66
-6
lines changed

README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,50 @@
55
[![Build Status](https://travis-ci.com/invenia/MultilineStrings.jl.svg?branch=master)](https://travis-ci.com/invenia/MultilineStrings.jl)
66
[![Code Style: Blue](https://img.shields.io/badge/code%20style-blue-4495d1.svg)](https://github.com/invenia/BlueStyle)
77
[![ColPrac: Contributor's Guide on Collaborative Practices for Community Packages](https://img.shields.io/badge/ColPrac-Contributor's%20Guide-blueviolet)](https://github.com/SciML/ColPrac)
8+
9+
Tooling for manipulating multiline strings.
10+
11+
## Features
12+
13+
The package features the `@m_str` macro, inspired from [YAML's block scalars](https://yaml-multiline.info/), which provide options for manipulating multiline strings via a style and chomp indicator:
14+
15+
- Style indicator:
16+
- `f` replace newlines with spaces (folded)
17+
- `l` keep newlines (literal)
18+
- Chomp indicator:
19+
- `s` no newlines at the end (strip)
20+
- `c` single newline at the end (clip)
21+
- `k` keep all newlines from the end (keep)
22+
23+
The indicators are provided after the ending quote of the string (e.g. `m"hello\nworld!"fc`).
24+
If no indicators are provided the default behaviour is folded/strip.
25+
26+
## Example
27+
28+
When writing a long string literal you may want to break the string up over multiple lines in the code, to make it easier to read, but have the string be printed as a single line.
29+
Specifically, when writing an long error message you may want to break up the string over multiple lines:
30+
31+
```julia
32+
"An unexpected error has occurred which really shouldn't have happened but somehow did. Please check that the inputs to this function doesn't contain magic that may interfere with with the non-magical computation occurring on this device."
33+
```
34+
35+
Alternatively written over multiple lines:
36+
37+
```julia
38+
"An unexpected error has occurred which really shouldn't " *
39+
"have happened but somehow did. Please check that the inputs " *
40+
"to this function doesn't contain magic that may interfere with " *
41+
"with the non-magical computation occurring on this device."
42+
```
43+
44+
Writing strings this way can be cumbersome as you need to remember to add spaces between each line.
45+
The MultilineStrings package provides an alternative way of writing this using the multiline string macro:
46+
47+
```julia
48+
m"""
49+
An unexpected error has occurred which really shouldn't
50+
have happened but somehow did. Please check that the inputs
51+
to this function doesn't contain magic that may interfere with
52+
with the non-magical computation occurring on this device.
53+
"""
54+
```

src/MultilineStrings.jl

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -180,16 +180,29 @@ end
180180
"""
181181
@m_str -> String
182182
183-
Construct a multiline string according to the indicators listed after the ending quote:
183+
Construct a multiline string according to a style and chomp indicators (provided after the
184+
ending quote):
184185
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)
186+
- Style indicator:
187+
- `f` replace newlines with spaces (folded)
188+
- `l` keep newlines (literal)
189+
- Chomp indicator:
190+
- `s` no newlines at the end (strip)
191+
- `c` single newline at the end (clip)
192+
- `k` keep all newlines from the end (keep)
190193
191194
Note string interpolation is still respected any newlines added from interpolation will be
192195
also be processed.
196+
197+
# Examples
198+
199+
```jldoctest; setup = :(using MultilineStrings)
200+
julia> m\"\"\"
201+
A string written
202+
over multiple lines
203+
\"\"\"
204+
"A string written over multiple lines"
205+
```
193206
"""
194207
macro m_str(str::AbstractString, indicators::AbstractString="")
195208
parsed = interpolate(str)

0 commit comments

Comments
 (0)