-/*******************************************************************************\r
- * Copyright (c) 2016 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * THTH ry - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.debug.browser.utils;\r
-\r
-public class Escapes {\r
-\r
- public static String html(String s) {\r
- if (!containsAnyOf(s, HTML_CHARS_TO_ESCAPE))\r
- return s;\r
- return batchReplace(s, HTML_CHARS_TO_ESCAPE, HTML_CHAR_REPLACEMENTS);\r
- }\r
-\r
- private static final char[] HTML_CHARS_TO_ESCAPE = { '&', '<', '>', '\n' };\r
- private static final String[] HTML_CHAR_REPLACEMENTS = { "&", "<", ">", "<br/>" };\r
-\r
- private static boolean containsAnyOf(String s, char[] chars) {\r
- int l = s.length();\r
- for (int i = 0; i < l; ++i) {\r
- char p = s.charAt(i);\r
- for (char ch : chars)\r
- if (p == ch)\r
- return true;\r
- }\r
- return false;\r
- }\r
-\r
- private static String batchReplace(String s, char[] charsToReplace, String[] replacements) {\r
- int l = s.length();\r
- int rl = charsToReplace.length;\r
- StringBuilder sb = new StringBuilder(l*2);\r
- nextChar:\r
- for (int i = 0; i < l; ++i) {\r
- char p = s.charAt(i);\r
- for (int j = 0; j < rl; ++j) {\r
- if (p == charsToReplace[j]) {\r
- sb.append(replacements[j]);\r
- continue nextChar;\r
- }\r
- }\r
- sb.append(p);\r
- }\r
- return sb.toString();\r
- }\r
-\r
- public static void main(String[] args) {\r
- System.out.println(html("><&\nfoobar\n<>"));\r
- }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2016 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * THTH ry - initial API and implementation
+ *******************************************************************************/
+package org.simantics.debug.browser.utils;
+
+public class Escapes {
+
+ public static String html(String s) {
+ if (!containsAnyOf(s, HTML_CHARS_TO_ESCAPE))
+ return s;
+ return batchReplace(s, HTML_CHARS_TO_ESCAPE, HTML_CHAR_REPLACEMENTS);
+ }
+
+ private static final char[] HTML_CHARS_TO_ESCAPE = { '&', '<', '>', '\n' };
+ private static final String[] HTML_CHAR_REPLACEMENTS = { "&", "<", ">", "<br/>" };
+
+ private static boolean containsAnyOf(String s, char[] chars) {
+ int l = s.length();
+ for (int i = 0; i < l; ++i) {
+ char p = s.charAt(i);
+ for (char ch : chars)
+ if (p == ch)
+ return true;
+ }
+ return false;
+ }
+
+ private static String batchReplace(String s, char[] charsToReplace, String[] replacements) {
+ int l = s.length();
+ int rl = charsToReplace.length;
+ StringBuilder sb = new StringBuilder(l*2);
+ nextChar:
+ for (int i = 0; i < l; ++i) {
+ char p = s.charAt(i);
+ for (int j = 0; j < rl; ++j) {
+ if (p == charsToReplace[j]) {
+ sb.append(replacements[j]);
+ continue nextChar;
+ }
+ }
+ sb.append(p);
+ }
+ return sb.toString();
+ }
+
+ public static void main(String[] args) {
+ System.out.println(html("><&\nfoobar\n<>"));
+ }
+
+}