Commit c44dfc56 authored by Marius Wachtler's avatar Marius Wachtler

Implement string.split(None)

parent 7e056b83
...@@ -351,25 +351,25 @@ Box* strSplit1(BoxedString* self) { ...@@ -351,25 +351,25 @@ Box* strSplit1(BoxedString* self) {
Box* strSplit2(BoxedString* self, BoxedString* sep) { Box* strSplit2(BoxedString* self, BoxedString* sep) {
assert(self->cls == str_cls); assert(self->cls == str_cls);
BoxedList* rtn = new BoxedList();
if (sep->cls == str_cls) { if (sep->cls == str_cls) {
if (!sep->s.empty()) { if (!sep->s.empty()) {
llvm::SmallVector<llvm::StringRef, 16> parts; llvm::SmallVector<llvm::StringRef, 16> parts;
llvm::StringRef(self->s).split(parts, sep->s); llvm::StringRef(self->s).split(parts, sep->s);
BoxedList* rtn = new BoxedList();
for (const auto &s : parts) for (const auto &s : parts)
listAppendInternal(rtn, boxString(s.str())); listAppendInternal(rtn, boxString(s.str()));
return rtn;
} else { } else {
fprintf(stderr, "ValueError: empty separator\n"); fprintf(stderr, "ValueError: empty separator\n");
raiseExc(); raiseExc();
} }
} else if (sep->cls == none_cls) {
return strSplit1(self);
} else { } else {
fprintf(stderr, "TypeError: expected a character buffer object\n"); fprintf(stderr, "TypeError: expected a character buffer object\n");
raiseExc(); raiseExc();
} }
return rtn;
} }
......
...@@ -8,4 +8,5 @@ print repr("'\"") ...@@ -8,4 +8,5 @@ print repr("'\"")
print "hello world\tmore\nwords\va\fb\ao".split() print "hello world\tmore\nwords\va\fb\ao".split()
print " test ".split() print " test ".split()
print " test ".split(' ') print " test ".split(' ')
print " test ".split(None)
print "1<>2<>3".split('<>') print "1<>2<>3".split('<>')
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment