"); + private static final Pattern DOLLAR = Pattern.compile("\\$"); + private static final Pattern TILDE = Pattern.compile("~"); public String format(String inField) { if (inField.isEmpty()) { @@ -14,8 +24,10 @@ public String format(String inField) { } int i; // TODO: document what does this do - String field = inField.replaceAll("&|\\\\&", "&").replaceAll("[\\n]{1,}", "
").replace("\\$", "$") // Replace \$ with $ - .replaceAll("\\$([^\\$]*)\\$", "\\{$1\\}"); + String field = AMP_LATEX.matcher(inField).replaceAll("&"); + field = P_LATEX.matcher(field).replaceAll("
"); + field = DOLLAR_LATEX.matcher(field).replaceAll("$"); + field = DOLLARS_LATEX.matcher(field).replaceAll("\\{$1\\}"); StringBuilder sb = new StringBuilder(); StringBuilder currentCommand = null; @@ -187,8 +199,11 @@ public String format(String inField) { } } - return sb.toString().replace("&", "&").replace("
", "\n").replace("$", "$").replace("~", - "\u00A0"); + String result = AMP.matcher(sb.toString()).replaceAll("&"); + result = P.matcher(result).replaceAll("\n"); + result = DOLLAR.matcher(result).replaceAll("\\$"); + result = TILDE.matcher(result).replaceAll("\u00A0"); + return result; } }