[TG] Optimized and refactored list2text, text2list, and replacetext.

By YotaXP: tgstation/-tg-station#2283