code: public static String escape(String input)
      {
          if (input.isEmpty())
              return input;
  
          String res = input.replaceAll(":", "\\\\:");
          char last = res.charAt(res.length() - 1);
          return last == '\\' || last == '!' ? res + '!' : res;
      }
docs: /*
  Escapes all occurences of the ':' character from the input, replacing them by "\:".
  Furthermore, if the last character is '\' or '!', a '!' is appended.