Commit 4597b228 authored by Kevin Modzelewski's avatar Kevin Modzelewski

Guess we need to support the 2-arg form of str.translate() as well

parent 2fa59346
...@@ -1374,7 +1374,8 @@ public: ...@@ -1374,7 +1374,8 @@ public:
return NULL; return NULL;
RELEASE_ASSERT(cl->num_args == cl->numReceivedArgs(), ""); RELEASE_ASSERT(cl->num_args == cl->numReceivedArgs(), "");
RELEASE_ASSERT(args.size() + 1 >= cl->num_args - cl->num_defaults && args.size() + 1 <= cl->num_args, ""); RELEASE_ASSERT(args.size() + 1 >= cl->num_args - cl->num_defaults && args.size() + 1 <= cl->num_args, "%d",
info.unw_info.current_stmt->lineno);
CompiledFunction* cf = NULL; CompiledFunction* cf = NULL;
bool found = false; bool found = false;
......
...@@ -754,10 +754,12 @@ Box* strTitle(BoxedString* self) { ...@@ -754,10 +754,12 @@ Box* strTitle(BoxedString* self) {
return boxString(s); return boxString(s);
} }
// TODO implement "deletechars". can also pass deletechars or None for 'table' Box* strTranslate(BoxedString* self, BoxedString* table, BoxedString* delete_chars) {
Box* strTranslate(BoxedString* self, BoxedString* table) {
RELEASE_ASSERT(self->cls == str_cls, ""); RELEASE_ASSERT(self->cls == str_cls, "");
RELEASE_ASSERT(table->cls == str_cls, ""); RELEASE_ASSERT(table->cls == str_cls, "");
RELEASE_ASSERT(delete_chars == NULL || delete_chars->cls == str_cls, "");
RELEASE_ASSERT(delete_chars == NULL || delete_chars->s.size() == 0, "delete_chars not supported yet");
std::ostringstream oss; std::ostringstream oss;
...@@ -1071,7 +1073,8 @@ void setupStr() { ...@@ -1071,7 +1073,8 @@ void setupStr() {
str_cls->giveAttr("capitalize", new BoxedFunction(boxRTFunction((void*)strCapitalize, STR, 1))); str_cls->giveAttr("capitalize", new BoxedFunction(boxRTFunction((void*)strCapitalize, STR, 1)));
str_cls->giveAttr("title", new BoxedFunction(boxRTFunction((void*)strTitle, STR, 1))); str_cls->giveAttr("title", new BoxedFunction(boxRTFunction((void*)strTitle, STR, 1)));
str_cls->giveAttr("translate", new BoxedFunction(boxRTFunction((void*)strTranslate, STR, 2))); str_cls->giveAttr("translate",
new BoxedFunction(boxRTFunction((void*)strTranslate, STR, 3, 1, false, false), { NULL }));
str_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)strContains, BOXED_BOOL, 2))); str_cls->giveAttr("__contains__", new BoxedFunction(boxRTFunction((void*)strContains, BOXED_BOOL, 2)));
......
...@@ -68,3 +68,4 @@ for c in "aeiou": ...@@ -68,3 +68,4 @@ for c in "aeiou":
translation_map[ord(c)] = c.upper() translation_map[ord(c)] = c.upper()
translation_map = ''.join(translation_map) translation_map = ''.join(translation_map)
print "hello world".translate(translation_map) print "hello world".translate(translation_map)
print "hello world".translate(translation_map, "")
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