slice can accept negative indices

This commit is contained in:
gnembon committed 2020-12-25 04:55:32 -04:00
1 parent 386afc1079
commit 7ad6de64ff
4 files changed
+37 -45

No files matched your search

+5 -7
View File
@@ -178,16 +178,14 @@ public abstract class Value implements Comparable<Value>, Cloneable
return getString().length();
}
public Value slice(long from, long to)
public Value slice(long fromDesc, long toDesc)
{
String value = this.getString();
int size = value.length();
if (to > size) to = -1;
if (from < 0) from = 0;
if (from > size) from = size;
if (to>=0)
return new StringValue(value.substring((int)from, (int)to));
return new StringValue(value.substring((int)from));
int from = ListValue.normalizeIndex(fromDesc, size);
int to = ListValue.normalizeIndex(toDesc, size);
if (from > to) return StringValue.EMPTY;
return new StringValue(value.substring(from, to));
}
public double readDoubleNumber()
{