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) {
BoxedList* list = static_cast<BoxedList*>(rhs);
std::ostringstream os; std::ostringstream os;
for (int i = 0; i < list->size; i++) { int i = 0;
for (Box* e : rhs->pyElements()) {
if (i > 0) if (i > 0)
os << self->s; os << self->s;
BoxedString* elt_str = str(list->elts->elts[i]); os << str(e)->s;
os << elt_str->s; ++i;
} }
return boxString(os.str()); return boxString(os.str());
} else {
raiseExcHelper(TypeError, "");
}
} }
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