From d95ff1335169e200598ef99ff14cada31f5137ef Mon Sep 17 00:00:00 2001 From: Alfred Porter Date: Fri, 28 Feb 2020 16:32:17 +0100 Subject: [PATCH] Added %upper/%lower to built-in macro functions --- .../sourceforge/plantuml/tim/TContext.java | 4 ++ .../plantuml/tim/stdlib/Lower.java | 58 +++++++++++++++++++ .../plantuml/tim/stdlib/Upper.java | 58 +++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 src/net/sourceforge/plantuml/tim/stdlib/Lower.java create mode 100644 src/net/sourceforge/plantuml/tim/stdlib/Upper.java diff --git a/src/net/sourceforge/plantuml/tim/TContext.java b/src/net/sourceforge/plantuml/tim/TContext.java index 22f5b0cc7..33abb9d52 100644 --- a/src/net/sourceforge/plantuml/tim/TContext.java +++ b/src/net/sourceforge/plantuml/tim/TContext.java @@ -78,11 +78,13 @@ import net.sourceforge.plantuml.tim.stdlib.Getenv; import net.sourceforge.plantuml.tim.stdlib.IntVal; import net.sourceforge.plantuml.tim.stdlib.InvokeVoidFunction; import net.sourceforge.plantuml.tim.stdlib.LogicalNot; +import net.sourceforge.plantuml.tim.stdlib.Lower; import net.sourceforge.plantuml.tim.stdlib.RetrieveVoidFunction; import net.sourceforge.plantuml.tim.stdlib.SetVariableValue; import net.sourceforge.plantuml.tim.stdlib.Strlen; import net.sourceforge.plantuml.tim.stdlib.Strpos; import net.sourceforge.plantuml.tim.stdlib.Substr; +import net.sourceforge.plantuml.tim.stdlib.Upper; import net.sourceforge.plantuml.tim.stdlib.VariableExists; public class TContext { @@ -125,6 +127,8 @@ public class TContext { addFunction(new GetVariableValue()); addFunction(new IntVal()); addFunction(new GetVersion()); + addFunction(new Upper()); + addFunction(new Lower()); // !exit // !log // %min diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Lower.java b/src/net/sourceforge/plantuml/tim/stdlib/Lower.java new file mode 100644 index 000000000..7a2e6c58a --- /dev/null +++ b/src/net/sourceforge/plantuml/tim/stdlib/Lower.java @@ -0,0 +1,58 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * http://plantuml.com/patreon (only 1$ per month!) + * http://plantuml.com/paypal + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Original Author: Arnaud Roques + * + */ +package net.sourceforge.plantuml.tim.stdlib; + +import java.util.List; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.TContext; +import net.sourceforge.plantuml.tim.TFunctionSignature; +import net.sourceforge.plantuml.tim.TMemory; +import net.sourceforge.plantuml.tim.expression.TValue; + +public class Lower extends SimpleReturnFunction { + + public TFunctionSignature getSignature() { + return new TFunctionSignature("%lower", 3); + } + + public boolean canCover(int nbArg) { + return nbArg == 1; + } + + public TValue executeReturn(TContext context, TMemory memory, List args) throws EaterException { + return TValue.fromString(args.get(0).toString().toLowerCase()); + } +} diff --git a/src/net/sourceforge/plantuml/tim/stdlib/Upper.java b/src/net/sourceforge/plantuml/tim/stdlib/Upper.java new file mode 100644 index 000000000..a6ba86140 --- /dev/null +++ b/src/net/sourceforge/plantuml/tim/stdlib/Upper.java @@ -0,0 +1,58 @@ +/* ======================================================================== + * PlantUML : a free UML diagram generator + * ======================================================================== + * + * (C) Copyright 2009-2020, Arnaud Roques + * + * Project Info: http://plantuml.com + * + * If you like this project or if you find it useful, you can support us at: + * + * http://plantuml.com/patreon (only 1$ per month!) + * http://plantuml.com/paypal + * + * This file is part of PlantUML. + * + * PlantUML is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * PlantUML distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + * License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. + * + * + * Original Author: Arnaud Roques + * + */ +package net.sourceforge.plantuml.tim.stdlib; + +import java.util.List; + +import net.sourceforge.plantuml.tim.EaterException; +import net.sourceforge.plantuml.tim.TContext; +import net.sourceforge.plantuml.tim.TFunctionSignature; +import net.sourceforge.plantuml.tim.TMemory; +import net.sourceforge.plantuml.tim.expression.TValue; + +public class Upper extends SimpleReturnFunction { + + public TFunctionSignature getSignature() { + return new TFunctionSignature("%upper", 3); + } + + public boolean canCover(int nbArg) { + return nbArg == 1; + } + + public TValue executeReturn(TContext context, TMemory memory, List args) throws EaterException { + return TValue.fromString(args.get(0).toString().toUpperCase()); + } +}