@@ -6918,6 +6918,59 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
69186918 value.m_value = args[2 ].m_value ;
69196919 fn_args.push_back (al, value);
69206920 }
6921+ } else if (attr_name == " center" ) {
6922+ if (args.size () != 1 && args.size () != 2 ) {
6923+ throw SemanticError (" str.center() takes one or two argument" ,
6924+ loc);
6925+ }
6926+ ASR::expr_t *arg_value = args[0 ].m_value ;
6927+ ASR::ttype_t *arg_value_type = ASRUtils::expr_type (arg_value);
6928+ if (!ASRUtils::is_integer (*arg_value_type)) {
6929+ throw SemanticError (" str.center() argument 1 must be integer" , loc);
6930+ }
6931+
6932+ fn_call_name = " _lpython_str_center" ;
6933+ ASR::call_arg_t str;
6934+ str.loc = loc;
6935+ str.m_value = s_var;
6936+
6937+ ASR::call_arg_t value;
6938+ value.loc = loc;
6939+ value.m_value = args[0 ].m_value ;
6940+ fn_args.push_back (al, str);
6941+ fn_args.push_back (al, value);
6942+
6943+ if (args.size () == 2 ){
6944+ ASR::expr_t *arg_value = args[1 ].m_value ;
6945+ ASR::ttype_t *arg_value_type = ASRUtils::expr_type (arg_value);
6946+ if (!ASRUtils::is_character (*arg_value_type)) {
6947+ throw SemanticError (" str.center() argument 2 must be str" , loc);
6948+ }
6949+ value.m_value = args[1 ].m_value ;
6950+ fn_args.push_back (al, value);
6951+ }
6952+ } else if (attr_name == " expandtabs" ) {
6953+ if (args.size () > 1 ) {
6954+ throw SemanticError (" str.expandtabs() takes at most one argument." , loc);
6955+ }
6956+ fn_call_name = " _lpython_str_expandtabs" ;
6957+ ASR::call_arg_t str;
6958+ str.loc = loc;
6959+ str.m_value = s_var;
6960+ fn_args.push_back (al, str);
6961+
6962+ if (args.size () == 1 ){
6963+ ASR::expr_t *arg_value = args[0 ].m_value ;
6964+ ASR::ttype_t *arg_value_type = ASRUtils::expr_type (arg_value);
6965+ if (!ASRUtils::is_integer (*arg_value_type)) {
6966+ throw SemanticError (" str.expandtabs() argument must be integer" , loc);
6967+ }
6968+
6969+ ASR::call_arg_t value;
6970+ value.loc = loc;
6971+ value.m_value = args[0 ].m_value ;
6972+ fn_args.push_back (al, value);
6973+ }
69216974 } else if (attr_name.size () > 2 && attr_name[0 ] == ' i' && attr_name[1 ] == ' s' ) {
69226975 /*
69236976 String Validation Methods i.e all "is" based functions are handled here
0 commit comments