I noticed that in Microsoft Word, single quotations are either
’, but not in Notepad. Your task today is: given a string
q, convert all the
' characters (only) to
’, according to these rules, and then output it:
- If the character before the quote is a space, and after it comes a character, it becomes
- If the character before the quote is a letter, and after it is a space, it becomes
- If the character before and after the quote is a letter, it becomes
- If the character before and after the quote is a space, it becomes
- If the quote comes at the beginning it will be
‘, if it comes at the end it becomes
- If consecutive quotes come one after another, the first 2 become
‘’and remaining ones become
'Hello'= ‘Hello’ (rules 1 and 2) '=‘ (rule 5) H'h=H’h (rule 3) ' = ‘ (rule 4) '' = ‘’ (rule 6) a'''b=a‘’’b (overriding by rule 6)
I'm keeping it this because although it is confusing, it is what the output should be, so if I had to make it more clearer, it will come at the expense of understanding it.
You can assume
q contains only upper and lowercase letters, spaces, and quotation marks.
This is code-golf, so shortest answer wins!
EDIT: Although in MS Word rule 6 does not override all the other rules, since answers have already been posted that assume this case, I will keep it this way