fixing incorrect default upper bound for slice. Fixes #657
This commit is contained in:
1 parent
eac4eb0537
commit
f3f8c689a8
6 files changed
+10
-7
No files matched your search
@@ -87,7 +87,7 @@ public class DataStructures {
|
|||||||
throw new InternalExpressionException("'slice' takes 2 or 3 arguments");
|
throw new InternalExpressionException("'slice' takes 2 or 3 arguments");
|
||||||
Value hwat = lv.get(0);
|
Value hwat = lv.get(0);
|
||||||
long from = NumericValue.asNumber(lv.get(1)).getLong();
|
long from = NumericValue.asNumber(lv.get(1)).getLong();
|
||||||
long to = -1;
|
Long to = null;
|
||||||
if (lv.size()== 3)
|
if (lv.size()== 3)
|
||||||
to = NumericValue.asNumber(lv.get(2)).getLong();
|
to = NumericValue.asNumber(lv.get(2)).getLong();
|
||||||
return hwat.slice(from, to);
|
return hwat.slice(from, to);
|
||||||
|
|||||||
@@ -133,7 +133,7 @@ public class FunctionValue extends Value implements Fluff.ILazyFunction
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value slice(long from, long to)
|
public Value slice(long from, Long to)
|
||||||
{
|
{
|
||||||
throw new InternalExpressionException("Cannot slice a function");
|
throw new InternalExpressionException("Cannot slice a function");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,9 +129,9 @@ public abstract class LazyListValue extends AbstractListValue implements Iterato
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value slice(long from, long to)
|
public Value slice(long from, Long to)
|
||||||
{
|
{
|
||||||
if (to < 0) to = Integer.MAX_VALUE;
|
if (to == null || to < 0) to = (long) Integer.MAX_VALUE;
|
||||||
if (from < 0) from = 0;
|
if (from < 0) from = 0;
|
||||||
if (from > to)
|
if (from > to)
|
||||||
return ListValue.of();
|
return ListValue.of();
|
||||||
|
|||||||
@@ -334,11 +334,13 @@ public class ListValue extends AbstractListValue implements ContainerValueInterf
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value slice(long fromDesc, long toDesc)
|
public Value slice(long fromDesc, Long toDesc)
|
||||||
{
|
{
|
||||||
List<Value> items = getItems();
|
List<Value> items = getItems();
|
||||||
int size = items.size();
|
int size = items.size();
|
||||||
int from = normalizeIndex(fromDesc, size);
|
int from = normalizeIndex(fromDesc, size);
|
||||||
|
if (toDesc == null)
|
||||||
|
return new ListValue((Collection<? extends Value>) getItems().subList(from, size));
|
||||||
int to = normalizeIndex(toDesc, size);
|
int to = normalizeIndex(toDesc, size);
|
||||||
if (from > to)
|
if (from > to)
|
||||||
return ListValue.of();
|
return ListValue.of();
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ public class MapValue extends AbstractListValue implements ContainerValueInterfa
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Value slice(long from, long to)
|
public Value slice(long from, Long to)
|
||||||
{
|
{
|
||||||
throw new InternalExpressionException("Cannot slice a map value");
|
throw new InternalExpressionException("Cannot slice a map value");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -178,11 +178,12 @@ public abstract class Value implements Comparable<Value>, Cloneable
|
|||||||
return getString().length();
|
return getString().length();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Value slice(long fromDesc, long toDesc)
|
public Value slice(long fromDesc, Long toDesc)
|
||||||
{
|
{
|
||||||
String value = this.getString();
|
String value = this.getString();
|
||||||
int size = value.length();
|
int size = value.length();
|
||||||
int from = ListValue.normalizeIndex(fromDesc, size);
|
int from = ListValue.normalizeIndex(fromDesc, size);
|
||||||
|
if (toDesc == null) return new StringValue(value.substring(from));
|
||||||
int to = ListValue.normalizeIndex(toDesc, size);
|
int to = ListValue.normalizeIndex(toDesc, size);
|
||||||
if (from > to) return StringValue.EMPTY;
|
if (from > to) return StringValue.EMPTY;
|
||||||
return new StringValue(value.substring(from, to));
|
return new StringValue(value.substring(from, to));
|
||||||
|
|||||||
Reference in new issue
Block a user