blob: 9cf81ffa8702a0cc962b57cb7e402d4e9a0fc442 (
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
26
|
package org.zwobble.couscous.values;
import java.util.List;
import org.zwobble.couscous.interpreter.NoSuchMethod;
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 NoSuchMethod(methodName);
}
}
}
|