|
1 |
| -# BlockScalars |
| 1 | +# MultilineStrings |
2 | 2 |
|
3 |
| -[](https://invenia.github.io/BlockScalars.jl/stable) |
4 |
| -[](https://invenia.github.io/BlockScalars.jl/dev) |
5 |
| -[](https://travis-ci.com/invenia/BlockScalars.jl) |
| 3 | +[](https://invenia.github.io/MultilineStrings.jl/stable) |
| 4 | +[](https://invenia.github.io/MultilineStrings.jl/dev) |
| 5 | +[](https://travis-ci.com/invenia/MultilineStrings.jl) |
6 | 6 | [](https://github.com/invenia/BlueStyle)
|
7 | 7 | [](https://github.com/SciML/ColPrac)
|
| 8 | + |
| 9 | +Tooling for manipulating multiline strings. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +The package features a multiline string literal (`@m_str`), inspired from [YAML's block scalars](https://yaml-multiline.info/), which provide options for manipulating multiline string literals 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 | +``` |
| 55 | + |
| 56 | +Take note that a Julia [triple-quoted string literal](https://docs.julialang.org/en/v1/manual/strings/#Triple-Quoted-String-Literals) will leave most newlines in place. |
0 commit comments