[autocomplete] 127/143: Factor HTML-stripping into a method. Can be optimized later. Should also replace &lt; with <, &nbsp; with space, etc.

Benjamin Mesing ben at alioth.debian.org
Sat Oct 19 12:53:30 UTC 2013


This is an automated email from the git hooks/post-receive script.

ben pushed a commit to branch master
in repository autocomplete.

commit 9554311def8272467a9dd8d2091528099d8511a4
Author: bobbylight <robert at fifesoft.com>
Date:   Tue Jan 22 01:02:09 2013 +0000

    Factor HTML-stripping into a method.  Can be optimized later.  Should also replace < with <,   with space, etc.
---
 .../fife/ui/autocomplete/AbstractCompletion.java    |    2 +-
 src/org/fife/ui/autocomplete/Util.java              |   19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/org/fife/ui/autocomplete/AbstractCompletion.java b/src/org/fife/ui/autocomplete/AbstractCompletion.java
index 4a10898..3a19e2f 100644
--- a/src/org/fife/ui/autocomplete/AbstractCompletion.java
+++ b/src/org/fife/ui/autocomplete/AbstractCompletion.java
@@ -21,7 +21,7 @@ import javax.swing.text.JTextComponent;
  *
  * This implementation assumes the input text and replacement text are the
  * same value.  It also returns the input text from its {@link #toString()}
- * method (which is what <tt>DefaultListCellRenderer</tt> uses to render
+ * method (which is what <code>DefaultListCellRenderer</code> uses to render
  * objects).  Subclasses that wish to override any of this behavior can simply
  * override the corresponding method(s) needed to do so.
  *
diff --git a/src/org/fife/ui/autocomplete/Util.java b/src/org/fife/ui/autocomplete/Util.java
index c994b60..8821aee 100644
--- a/src/org/fife/ui/autocomplete/Util.java
+++ b/src/org/fife/ui/autocomplete/Util.java
@@ -16,6 +16,7 @@ import java.awt.Rectangle;
 import java.lang.reflect.Method;
 import java.net.URI;
 import java.security.AccessControlException;
+import java.util.regex.Pattern;
 import javax.swing.JLabel;
 import javax.swing.UIManager;
 
@@ -60,6 +61,8 @@ public class Util {
 	 */
 	private static final Color LIGHT_HYPERLINK_FG = new Color(0xd8ffff);
 
+	private static final Pattern TAG_PATTERN = Pattern.compile("<[^>]*>");
+
 	private static final boolean useSubstanceRenderers;
 	private static boolean desktopCreationAttempted;
 	private static Object desktop;
@@ -296,6 +299,22 @@ public class Util {
 	}
 
 
+	/**
+	 * Strips any HTML from a string.  The string must start with
+	 * "<code><html></code>" for markup tags to be stripped.
+	 *
+	 * @param text The string.
+	 * @return The string, with any HTML stripped.
+	 */
+	public static String stripHtml(String text) {
+		if (text==null || !text.startsWith("<html>")) {
+			return text;
+		}
+		// TODO: Micro-optimize me, might be called in renderers and loops
+		return TAG_PATTERN.matcher(text).replaceAll("");
+	}
+
+
 	static {
 
 		boolean use = true;

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/autocomplete.git



More information about the pkg-java-commits mailing list