Optimized and refactored list2text, text2list, and replacetext.

See, https://github.com/tgstation/-tg-station/pull/2283