X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=source%2Fmir%2Futil%2FStringParseRoutines.java;h=04bbc72a37d234e0ac1aa35fb2a4ae3c9a0a33bd;hb=63e0ee1fb8038eb6d8f0190cf38c3b3ab2727216;hp=ee08f219e541e6b5da83c9e8a430d467f3d62fbf;hpb=8b91e8d8bf4a31a88440a404e83238dcf32f8f4a;p=mir.git diff --git a/source/mir/util/StringParseRoutines.java b/source/mir/util/StringParseRoutines.java index ee08f219..04bbc72a 100755 --- a/source/mir/util/StringParseRoutines.java +++ b/source/mir/util/StringParseRoutines.java @@ -18,13 +18,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * In addition, as a special exception, The Mir-coders gives permission to link - * the code of this program with any library licensed under the Apache Software License, - * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library - * (or with modified versions of the above that use the same license as the above), - * and distribute linked combinations including the two. You must obey the - * GNU General Public License in all respects for all of the code used other than - * the above mentioned libraries. If you modify this file, you may extend this - * exception to your version of the file, but you are not obligated to do so. + * the code of this program with any library licensed under the Apache Software License, + * The Sun (tm) Java Advanced Imaging library (JAI), The Sun JIMI library + * (or with modified versions of the above that use the same license as the above), + * and distribute linked combinations including the two. You must obey the + * GNU General Public License in all respects for all of the code used other than + * the above mentioned libraries. If you modify this file, you may extend this + * exception to your version of the file, but you are not obligated to do so. * If you do not wish to do so, delete this exception statement from your version. */ @@ -32,6 +32,8 @@ package mir.util; import java.util.HashMap; import java.util.Map; +import java.util.List; +import java.util.ArrayList; public class StringParseRoutines { @@ -41,8 +43,9 @@ public class StringParseRoutines { private final static String VALUE = "[^;]*"; private final static String SEMICOLON = ";"; - // a=sdfb; c=d; e=f - + /** + * Parses an expression of the form " a = b ; c = d" into a map + */ public static Map parseValueList(String anExpression) throws SimpleParser.SimpleParserFailure, SimpleParser.SimpleParserExc { String key; String value; @@ -67,4 +70,58 @@ public class StringParseRoutines { return result; } + + /** + * Utility function for {@link #parseBracketedExpression}: + * Adds a single part of a bracketed expression by looking for a + * terminator. + */ + private static int findNextBracketedPart(String anExpression, int aStartingPosition, char anEscape, String aTerminator, List aResult) { + int position = aStartingPosition; + StringBuffer result = new StringBuffer(); + + while (position"some string {some expression} some string". + * { here starts a bracket, } ends one. + */ + public static List parseBracketedExpression(String anExpression, char anEscape, + String anOpeningBracket, String aClosingBracket) { + List result = new ArrayList(); + int position = 0; + + do { + position = findNextBracketedPart(anExpression, position, anEscape, anOpeningBracket, result); + if (position>=0) { + position+=anOpeningBracket.length(); + position = findNextBracketedPart(anExpression, position, anEscape, aClosingBracket, result); + if (position>0) { + position+=aClosingBracket.length(); + } + } + } while (position>=0); + + return result; + } } \ No newline at end of file