Everybody loves golfing code. Code is written in English (eh...). Therefore, everybody loves golfing English!
Your task is to write a program or function that takes a string as input, and then returns or prints the golfed version. There will be no newlines or tabs in the input.
This is how you golf a string. The order matters!
Remove spaces directly before and after punctuation:
"Hey there", he said ; he ' s a cat. -> "Hey there",he said;he's a cat.The following count as punctuation:
he/she/it is, case insensitive, with
It is unfortunate that she is not coming ever. -> It's unfortunate that she's not coming ever.
Words that start with capital letters in a sentence can be moved against the preceding word (omitting the space):
The farmer told Fred that he should leave. -> The farmer toldFred that he should leave.
Trailing and leading spaces should be removed:
[ ]It's raining.[ ]-> It's raining.Ignore the brackets (annoying auto-formatting).
Remove repeated punctuation that is the same:
""Here''s the cake",, said Fred..! -> "Here's the cake",saidFred.!
If we were to golf the first paragraph of this challenge, the output would be:
Everybody loves golfing code.Code is written inEnglish(eh.).Therefore,everybody loves golfingEnglish!
This is code golf––or rather English golf––so shortest code in bytes wins!
Here is one all encompassing test case:
" You are crazy"",, , , she said. It is unfortunate that Margaret had to say that... she is a Martian!.
"You are crazy",she said.It's unfortunate thatMargaret had to say that.she's aMartian!.