After reading one character from the source you have three different cases:
- The character is ' ' or '\n': Add the character to a temporary buffer
- The character is ',' or '.': Add the character to the destination and clear the buffer.
- Any other character: Add the buffer to the destination, add the character and clear the buffer.
I can't think of a solution without a temporary buffer which handles cases like
Code:
foo \n \n bar -> foo \n \n bar (no changes)
foo \n \n ,bar -> foo,bar
i.e. where you have mixed spaces and newlines before any other character.
Bye, Andreas