" ".trim()
This returns a (pointer to) a null string.
Here is a finite-state transducer with some labels left blank. The transducer must deal with input strings such as
" abc def "
which have white space
in the middle.
But without looking ahead, the transducer can't
tell if the current character is an internal space
(such as the one after c
) or an outside space
(such as the one after f
).
To deal with that problem, the transducer copies possible internal spaces to a buffer. This is done in the transition between state 0 and state 1, and also in the transition between state 2 and itself. When an ordinary character is encountered in state 2, the spaces in the buffer and the character are appended to the output string. If no ordinary character is encountered, the transducer remains in a final state and the buffer is discarded.
A few transitions remain unlabeled. Mentally label them
input character(s) : output characters(s)
Use white to mean a white space character and ord to mean an ordinary character. To indicate no output character use "epsilon".
What will be the output string for this input string:
" Friends, Romans, countrymen "