refactor(pipes): remove LimitTo pipe in favor of slice pipe

This commit is contained in:
Lenny
2015-08-30 17:05:02 -07:00
committed by vsavkin
parent c2043ec681
commit d890c4f827
9 changed files with 22 additions and 144 deletions

View File

@ -95,11 +95,13 @@ class StringWrapper {
}
static String slice(String s, [int start = 0, int end]) {
start = _startOffset(s, start);
end = _endOffset(s, end);
//in JS if start > end an empty string is returned
if(end != null && start > end) {
return "";
}
return s.substring(_startOffset(s, start), _endOffset(s, end));
return s.substring(start, end);
}
static String substring(String s, int start, [int end]) {
@ -120,7 +122,7 @@ class StringWrapper {
// the end of the string
static int _startOffset(String s, int start) {
int len = s.length;
return start = start < 0 ? math.max(len + start, 0) : math.min(start, len);
return start < 0 ? math.max(len + start, 0) : math.min(start, len);
}
// JS slice function can take end < 0 which indicates a position relative to