" You use both "platform specific line-ending" and "network line-ending." Is the use of two different phrases accidental or purposeful?"
Very purposeful.
The sub will receive strings for transmission across the network. The caller may have terminated the string with "\n" (which will be the platform-sepecific line-ending dependant upon what the current platform is), or they may not have done so.
Before transmission, I need to:
- Add a network-specific line-ending (\015\012) if no line-ending is present.
- Convert whatever (platform-specific) line-ending is present, to the network line-ending is a line-ending, if one is present.
- Leave the string alone, if the correct line-ending is already present.
It seems like a single regex that used look-behind assertions properly would be able to do this, thereby avoiding messy conditional logic. It also seems like this is an oft-called for requirement and a well tried solution is probably already known.
I've had a couple of attempts at constructing the regex, but in each case, it falls over in one of the above three cases. Either adding an extra, unnecessary line-ending or omitting to add one.
I hoped someone in the know would point me at the correct regex to use?
|