/* Function: tp_has * Checks if an object contains a key. * * Returns tp_True if self[k] exists, tp_False otherwise. */ tp_obj tp_has(TP,tp_obj self, tp_obj k) { int type = self.type; if (type == TP_DICT) { if (_tp_dict_find(tp,self.dict.val,k) != -1) { return tp_True; } return tp_False; } else if (type == TP_STRING && k.type == TP_STRING) { return tp_number(_tp_str_index(self,k)!=-1); } else if (type == TP_LIST) { return tp_number(_tp_list_find(tp,self.list.val,k)!=-1); } tp_raise(tp_None,tp_string("(tp_has) TypeError: iterable argument required")); }
tp_obj tp_has(tp_vm *tp, tp_obj self, tp_obj k) { int type = obj_type(self); if (type == TP_DICT) { if (_tp_dict_find(tp, tp_dict_val(self), k) != -1) { return True; } return False; } else if (type == TP_STRING && obj_type(k) == TP_STRING) { char *p = strstr(STR(self),STR(k)); return tp_number(tp, p != 0); } else if (type == TP_LIST) { return tp_number(tp, _tp_list_find(tp,tp_list_val(self),k)!=-1); } tp_raise(None,"tp_has(%s,%s)",STR(self),STR(k)); }
tp_obj tp_has(TP,tp_obj self, tp_obj k) { int type = self.type; if (type == TP_DICT) { if (_tp_dict_find(tp,self.dict.val,k) != -1) { return tp_True; } return tp_False; } else if (type == TP_STRING && k.type == TP_STRING) { char *p = strstr(TP_CSTR(self),TP_CSTR(k)); return tp_number(p != 0); } else if (type == TP_LIST) { return tp_number(_tp_list_find(tp,self.list.val,k)!=-1); } tp_raise(tp_None,"tp_has(%s,%s)",TP_CSTR(self),TP_CSTR(k)); }