Minor bug fixes.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@46 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-02-05 08:56:44 +00:00
parent 8444136be1
commit 3ea230b11c
2 changed files with 12 additions and 9 deletions

View File

@ -30,21 +30,24 @@ public class Get implements Function {
start = Math.min(a.length, Math.max(0, start));
if (to == null) {
return a[start];
return start < a.length ? a[start] : null;
} else {
int end = to != null && to instanceof Number ?
((Number) to).intValue() : a.length;
if (end < 0) {
end = a.length - end;
end = a.length + end;
}
end = Math.min(a.length, Math.max(start, end));
if (end > start) {
Object[] a2 = new Object[end - start];
System.arraycopy(a, start, a2, 0, end - start);
return a2;
}
}
} else {
String s = (v instanceof String ? (String) v : v.toString());
@ -57,7 +60,7 @@ public class Get implements Function {
if (to != null && to instanceof Number) {
int end = ((Number) to).intValue();
if (end < 0) {
end = s.length() - end;
end = s.length() + end;
}
end = Math.min(s.length(), Math.max(start, end));

View File

@ -26,7 +26,7 @@ public class Slice implements Function {
start = Math.min(a.length, Math.max(0, start));
if (end < 0) {
end = a.length - end;
end = a.length + end;
}
end = Math.min(a.length, Math.max(start, end));
@ -46,7 +46,7 @@ public class Slice implements Function {
if (to != null && to instanceof Number) {
int end = ((Number) to).intValue();
if (end < 0) {
end = s.length() - end;
end = s.length() + end;
}
end = Math.min(s.length(), Math.max(start, end));