ASCII art is fun. Modern text editors are very good at manipulating text. Are modern programming languages up to the task?
One common task in ASCII art manipulation is to crop text to a rectangle between two characters. This is the task you must implement in this challenge.
Details
Your program will take 3 inputs:
- the first is the 'start' character of the block - marking the top-left corner
- the second is the 'end' character of the block - marking the bottom-right corner
- the third is some form of multiline text, either a string, or list of strings, or filename, or whatever
The result will be multiline text (again, in any of the above formats) cropped to the rectangle between the given inputs. Note that the first two inputs may not be unique.
Edge cases
Boxes must always have volume at least 2. Thus these:
() (
)
are boxes but these:
)( ) (
( )
are not (with start=(
and end=)
).
The input will only contain one box. Thus the start and end characters must only occur once, unless they are the same character in which case they must occur exactly twice.
Additionally each line in the input must be at least as long as the distance from the start of a line to the right edge of the box in the input.
Your program does not need to handle invalid inputs; they may result in undefined behavior.
Rules
Typical code-golf rules apply. Shortest code wins.
Examples
Sunny-day: start: ( end: ) input:
This is some text
. (but this text
is in a box ).
So only it is important.
Output:
(but this text
is in a box )
Note the stripping of horizontal space as well. ASCII art crops are 2d.
Rainy-day: start: ( end: ) input:
This is some text (
But is that even )
really a box?
Output:
(
)
Same start/end: start: / end: / input:
Oh, I get how this could be useful
/----------------------------\
| All this text is in a box! |
\----------------------------/
Output:
/----------------------------\
| All this text is in a box! |
\----------------------------/
Invalid input: start: ( end: ) input:
Boxes are rectangular ( so this has
0 volume ) which is illegal.
Invalid input 2: start: ( end: ) input:
(The lines must already be square
so this line that is too short
relative to this end, is illegal)