blob: 3a1a13debcf4e27ab69e4512622353015484e095 (
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
|
package org.zwobble.couscous.values;
import java.util.List;
import lombok.Value;
import lombok.val;
@Value
public class StringValue implements InterpreterValue {
String value;
@Override
public InterpreterValue callMethod(String methodName, List<InterpreterValue> arguments) {
if (methodName == "length") {
return new IntegerValue(value.length());
} else if (methodName == "substring") {
val startIndex = (IntegerValue)arguments.get(0);
val endIndex = (IntegerValue)arguments.get(1);
return new StringValue(value.substring(startIndex.getValue(), endIndex.getValue()));
} else {
throw new UnsupportedOperationException();
}
}
}
|