X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Fmisc%2FStringUtil.java;h=0e96f4ccb42224495a3a5ccffa1dc8a8afc6fdc2;hb=0ea8b821ae0f09a7638fe9e427654ddd395c48d8;hp=4315a45251eeebdb43b77b441aa35c4a8bf2f597;hpb=db974b09ac6b0b4e2f16f2cea8d2781ce820b83c;p=mir.git diff --git a/source/mir/misc/StringUtil.java b/source/mir/misc/StringUtil.java index 4315a452..0e96f4cc 100755 --- a/source/mir/misc/StringUtil.java +++ b/source/mir/misc/StringUtil.java @@ -40,7 +40,7 @@ import gnu.regexp.*; /** * Statische Hilfsmethoden zur Stringbehandlung * - * @version $Id: StringUtil.java,v 1.23.2.3 2002/12/09 06:23:38 mh Exp $ + * @version $Id: StringUtil.java,v 1.23.2.4 2002/12/10 09:07:50 mh Exp $ * @author rk, mir-coders group * */ @@ -413,6 +413,41 @@ public final class StringUtil { return buf.toString(); } + /* + * replaces characters that cannot appera in HTML with escaped equivalents. + */ + public static String encodeHTML(String aText) { + final char[] CHARACTERS_TO_ESCAPE = { '&', '<', '>', '"', '\'' }; + final String[] ESCAPE_CODES = { "&", "<", ">", """, "'" }; + + int position, nextPosition; + int i; + StringBuffer result = new StringBuffer(); + + position=0; + + do { + nextPosition = indexOfCharacters(aText, CHARACTERS_TO_ESCAPE, position); + + if (nextPosition<0) + nextPosition = aText.length(); + + result.append(aText.substring(position, nextPosition)); + + if (nextPositionelement im String-Array array + /** + * Finds element in String-Array array * @param array * @param element - * @return Fundstelle als int oder -1 + * @return Position where the element was found or -1 */ public static int indexOf(String[] array, String element) { if (array != null) @@ -632,6 +667,32 @@ public final class StringUtil { return -1; } + /** + * Finds position of first in aCharacters array in String + * aString starting from position aFrom + * + * @param aString + * @param aCharacters + * @param aFrom + * @return Position where the element was found or -1 + */ + public static int indexOfCharacters(String aString, char[] aCharacters, int aFrom) { + int i; + int result=-1; + int position; + + for (i=0; ielement in array * @param array String-Array @@ -677,6 +738,21 @@ public final class StringUtil { } } + public static String interpretAsString(Object aValue) throws Exception { + if (aValue instanceof String) + return (String) aValue; + + if (aValue instanceof Integer) + return ((Integer) aValue).toString(); + + if (aValue == null) + return ""; + + throw new Exception("String expected, "+aValue+" found"); + } + + + /** * Liefert Defaultwert def zurück, wenn s nicht zu einem float geparsed werden kann. * @param s @@ -823,6 +899,20 @@ public final class StringUtil { } } + /** + * deleteHTMLTableTags + * this method deletes all , and
-tags + */ + public static final String deleteHTMLTableTags(String haystack) { + try { + RE regex = new RE("",RE.REG_ICASE); + haystack = regex.substituteAll(haystack,""); + return haystack; + } catch(REException ex){ + return null; + } + } + /** * this method deletes all html tags */