From ecdff3ca1a14c3b838b3991591c04bc4ea8e77c5 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Mon, 16 Mar 2020 12:01:27 +0000 Subject: [PATCH] Added String isWhiteSpace, isLetter, isDigit - used by SomSom parser Signed-off-by: Stefan Marr --- src/som/primitives/StringPrimitives.java | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/som/primitives/StringPrimitives.java b/src/som/primitives/StringPrimitives.java index a5e34fe..f05af02 100644 --- a/src/som/primitives/StringPrimitives.java +++ b/src/som/primitives/StringPrimitives.java @@ -118,5 +118,43 @@ public void invoke(final Frame frame, final Interpreter interpreter) { } }); + installInstancePrimitive(new SPrimitive("isWhiteSpace", universe) { + + @Override + public void invoke(final Frame frame, final Interpreter interpreter) { + SString self = (SString) frame.pop(); + if (Character.isWhitespace(self.getEmbeddedString().charAt(0))) { + frame.push(universe.trueObject); + } else { + frame.push(universe.falseObject); + } + } + }); + + installInstancePrimitive(new SPrimitive("isLetter", universe) { + + @Override + public void invoke(final Frame frame, final Interpreter interpreter) { + SString self = (SString) frame.pop(); + if (Character.isLetter(self.getEmbeddedString().charAt(0))) { + frame.push(universe.trueObject); + } else { + frame.push(universe.falseObject); + } + } + }); + + installInstancePrimitive(new SPrimitive("isDigit", universe) { + + @Override + public void invoke(final Frame frame, final Interpreter interpreter) { + SString self = (SString) frame.pop(); + if (Character.isDigit(self.getEmbeddedString().charAt(0))) { + frame.push(universe.trueObject); + } else { + frame.push(universe.falseObject); + } + } + }); } }