Skip to content

Commit

Permalink
Added String isWhiteSpace, isLetter, isDigit
Browse files Browse the repository at this point in the history
- used by SomSom parser

Signed-off-by: Stefan Marr <[email protected]>
  • Loading branch information
smarr committed Mar 17, 2020
1 parent 0967fa0 commit ecdff3c
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/som/primitives/StringPrimitives.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
}
}

0 comments on commit ecdff3c

Please sign in to comment.