@@ -0,0 +1,2382 @@
+/*%0A * This file is part of Mapyrus, software for plotting maps.%0A * Copyright (C) 2003 Simon Chenery.%0A *%0A * Mapyrus is free software; you can redistribute it and/or modify%0A * it under the terms of the GNU Lesser General Public License as published by%0A * the Free Software Foundation; either version 2 of the License, or%0A * (at your option) any later version.%0A *%0A * Mapyrus is distributed in the hope that it will be useful,%0A * but WITHOUT ANY WARRANTY; without even the implied warranty of%0A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the%0A * GNU Lesser General Public License for more details.%0A *%0A * You should have received a copy of the GNU Lesser General Public License%0A * along with Mapyrus; if not, write to the Free Software%0A * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA%0A */%0A%0A/*%0A * @(#) $Id$%0A */%0Apackage org.mapyrus.function;%0A%0Aimport java.util.regex.Matcher;%0Aimport java.util.regex.Pattern;%0A%0Aimport org.mapyrus.Argument;%0Aimport org.mapyrus.ContextStack;%0Aimport org.mapyrus.MapyrusException;%0A%0A/**%0A * Function replacing all instances of a regular expression in a string with another string.%0A * For example, replace('foobar', 'o+', '_') = 'f_bar'.%0A */%0Apublic class Replace extends Function%0A%7B%0A%09/**%0A%09 * @see org.mapyrus.function.Function#evaluate(org.mapyrus.ContextStack,%0A%09 * %09org.mapyrus.Argument, org.mapyrus.Argument, org.mapyrus.Argument)%0A%09 */%0A%09public Argument evaluate(ContextStack context, Argument arg1, Argument arg2, Argument arg3)%0A%09%09throws MapyrusException%0A%09%7B%0A%09%09Argument retval;%0A%0A%09%09/*%0A%09%09 * Replace all occurrences of pattern given in second string%0A%09%09 * with the third string.%0A%09%09 */%0A%09%09Pattern pattern = Match.compileRegex(arg2.toString());%0A%09%09Matcher matcher = pattern.matcher(arg1.toString());%0A%09%09if (matcher.find())%0A%09%09%7B%0A%09%09%09/*%0A%09%09%09 * Replace all matching patterns.%0A%09%09%09 */%0A%09%09%09retval = new Argument(Argument.STRING, matcher.replaceAll(arg3.toString()));%0A%09%09%7D%0A%09%09else%0A%09%09%7B%0A%09%09%09/*%0A%09%09%09 * No match so return original string.%0A%09%09%09 */%0A%09%09%09retval = arg1;%0A%09%09%7D%0A%09%09return(retval);%0A%09%7D%0A%0A%09/**%0A%09 * @see org.mapyrus.function.Function#getMaxArgumentCount()%0A%09 */%0A%09public int getMaxArgumentCount()%0A%09%7B%0A%09%09return(3);%0A%09%7D%0A%0A%09/**%0A%09 * @see org.mapyrus.function.Function#getMinArgumentCount()%0A%09 */%0A%09public int getMinArgumentCount()%0A%09%7B%0A%09%09return(3);%0A%09%7D%0A%0A%09/**%0A%09 * @see org.mapyrus.function.Function#getName()%0A%09 */%0A%09public String getName()%0A%09%7B%0A%09%09return(%22replace%22);%0A%09%7D%0A%7D%0A

Split functions out from Expression.java into separate classes.