blob: da45f024ca8d32c90a46f5123364e72a1c516127 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
package org.zwobble.couscous.values;
import lombok.Value;
import lombok.val;
@Value
public class StringValue implements InterpreterValue {
private static final ConcreteType<?> TYPE = ConcreteType.<StringValue>builder()
.method("length", (receiver, arguments) -> new IntegerValue(receiver.value.length()))
.method("substring", (receiver, arguments) -> {
val startIndex = arguments.pop(IntegerValue.class);
val endIndex = arguments.pop(IntegerValue.class);
return new StringValue(receiver.value.substring(startIndex.getValue(), endIndex.getValue()));
})
.build();
String value;
@Override
public ConcreteType<?> getType() {
return TYPE;
}
}
|