OCTOBER 22 IS INTERNATIONAL CAPS LOCK DAY! UNFORTUNATELY, SOME DO NOT RECOGNIZE THE GLORY OF THE ALMIGHTY CAPS LOCK. THEY SAY IT SEEMS "OBNOXIOUS" OR "LIKE SHOUTING" OR SOME NONSENSE. IN ORDER TO CONFORM TO THESE OBVIOUSLY ILLOGICAL AND INANE COMPLAINTS, PLEASE WRITE ME A PROGRAM THAT TURNS NORMAL TEXT INTO "SENSIBLE" OR "REASONABLE" TEXT TO MAKE PEOPLE STOP COMPLAINING.
Description
The input and output for your solution will both be strings that contain only printable ASCII characters.
The input string will contain zero or more caps lock runs. A caps lock run (or CLR for short) is defined as the following:
The CLR must contain no lowercase letters (
a-z
), except as the first character of a word.- A word, for the purposes of this challenge, is a sequence of non-spaces. So,
PPCG
,correcthorsebatterystaple
, andjkl#@_>00()@#__f-023\f[
are all considered words.
- A word, for the purposes of this challenge, is a sequence of non-spaces. So,
The CLR must also contain at least one space; hence, it must be at least two words.
Each of the words in the CLR must contain at least two letters (
A-Za-z
).- Note that this refers to the CLR taken by itself, without any surrounding characters that may not have been included in the CLR. For example,
foO Bar
is not a CLR because the stringO B
by itself has words with less than two letters.
- Note that this refers to the CLR taken by itself, without any surrounding characters that may not have been included in the CLR. For example,
CLRs should be parsed "greedily"—that is, you should always find the longest CLRs possible.
Once you have identified all of the CLRs in the input string, swap the case of all letters inside of the CLRs and output the resulting string.
Test cases
The first line is input, and the second is output. Bolded portions of the input are substrings that are considered CLRs.
CAPS LOCK IS THE BEST!
caps lock is the best!
I really LOVE pROGRAMMING pUZZLES AND cOde Golf!
I really love Programming Puzzles and Code Golf!
This is a challenge on PPCG. This is a test CASE. TEST
This is a challenge on PPCG. This is a test case. test
LorEM iPSUM DOLoR sIT amet, conSECTETur ADIPISciNG eLIT. MAECENAS iD orci
Lorem Ipsum doloR sIT amet, conSECTETur ADIPIScing Elit. maecenas Id orci
;'>}{/[]'"A*(389971(*(#$&B#@*(% c'>#{@D#$! :,>/;[e.[{$893F
;'>}{/[]'"a*(389971(*(#$&b#@*(% C'>#{@d#$! :,>/;[e.[{$893F
iT'S cAPS lOCK DAY!!! cELebraTE THis WONDERFUL key
It's Caps Lock day!!! Celebrate this WONDERFUL key
aBcDE fGHIj KLmNO pQrST (uVwXY) ZZ___Zz__Z
aBcde Fghij KLmno PqrST (uVwxy) zz___zz__Z
#aA# aA
#aA# aA
Rules
You may assume that the input will never contain two or more spaces in a row, and that it will never contain a leading or trailing space.
20% bonus (multiply your code length by .8) if your entire code is a CLR. ;) (mostly just for fun, since it's unlikely that the winning submission will have this bonus)
This is code-golf, so the shortest code in bytes wins.
PPCG. T
contains a space) \$\endgroup\$