Strings with Context
For the purposes of this challenge, a string with context is a triple of strings, called the left context, the data part, and the right context. It represents a substring of a longer string. We use the vertical pipe |
as a separator, so an example of a string with context is cod|e-go|lf
, where the left context is cod
, the data is e-go
, and the right context is lf
. This example represents the substring e-go
of code-golf
.
Now, to concatenate two strings with context, we proceed as follows, using aa|bcc|dee
and cc|de|eee
as examples. We align the strings as in the diagram
a a|b c c|d e e
c c|d e|e e e
so that their data parts are adjacent. The data part of the concatenation is the concatenation of the data parts, in this case bccde
. The left context is the part that extends the furthers to the left of the first data part, in this case aa
. Similarly, the right context is eee
, so the concatenation is the string with context aa|bccde|eee
. For a second example, consider a|bb|cd
and aabb|cd|
, where the second word has a empty right context. The alignment diagram is
a|b b|c d
a a b b|c d|
where the left context of the second word extends further than that of the first. The concatenation is aa|bbcd|
.
But wait, there's a gotcha: if the letters of the alignment diagram don't match, the concatenation doesn't exist! As an example, the diagram of aa|bb|cc
and c|c|c
is
a a|b b|c c
c|c|c
where the b
and c
on the fourth column disagree, so they cannot be concatenated.
The Task
Your job is to write a program that takes in two strings with context whose parts are separated by |
as above, and outputs their concatenation if it exists, and something else if not. The "something else" can be any value, including no output, as long as it's not a valid string with context, and it is the same in all cases. However, throwing an error is not acceptable. You can give either a STDIN-to-STDOUT program or a function, and anonymous functions are accepted as well. The smallest byte count wins, and standard loopholes are disallowed.
Test Cases
aa|bcc|dee cc|de|eee -> aa|bccde|eee
a|bb|cd aabb|cd| -> aa|bbcd|
a|b|cccd aab|cc|c -> aa|bcc|cd
a|b|c b||cd -> a|b|cd
aa|bb|cc c|c|c -> None
aaa|b|c abb|cd|d -> None
|bb|cd abb|c|ed -> None
a|b|c a||cd -> None