Commit 4afb0656 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Merge pull request #297 from undingen/strJoin

Implement str.join(iterable)
parents 056cf471 05c71b31
...@@ -1311,19 +1311,15 @@ Box* strIsTitle(BoxedString* self) { ...@@ -1311,19 +1311,15 @@ Box* strIsTitle(BoxedString* self) {
Box* strJoin(BoxedString* self, Box* rhs) { Box* strJoin(BoxedString* self, Box* rhs) {
assert(self->cls == str_cls); assert(self->cls == str_cls);
if (rhs->cls == list_cls) { std::ostringstream os;
BoxedList* list = static_cast<BoxedList*>(rhs); int i = 0;
std::ostringstream os; for (Box* e : rhs->pyElements()) {
for (int i = 0; i < list->size; i++) { if (i > 0)
if (i > 0) os << self->s;
os << self->s; os << str(e)->s;
BoxedString* elt_str = str(list->elts->elts[i]); ++i;
os << elt_str->s;
}
return boxString(os.str());
} else {
raiseExcHelper(TypeError, "");
} }
return boxString(os.str());
} }
Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) { Box* strReplace(Box* _self, Box* _old, Box* _new, Box** _args) {
......
print "-".join(["hello", "world"]) print "-".join(["hello", "world"])
print "-".join(("hello", "world"))
print repr(chr(0) + chr(180)) print repr(chr(0) + chr(180))
print repr('"') print repr('"')
......
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