I want to check if a specific String should be escaped before really performing any escaping mechanism.
for example:
if the String is "msg\t" so I want to escape it but if the String is "msg\\t" meaning it is already escaped or for example "msg" meaning no need to escape at all.
is there a way to check is easily?
Based on your description, this should work. It uses a map to map the actual value to the letter that represents it. Additional logic would need to be incorporated to escape backslashes since they serve a dual purpose which would need to be processed separately.
Prints