@@ -655,21 +655,17 @@ struct PythonIntrinsicProcedures {
655
655
656
656
static ASR::expr_t *eval__lpython_str_capitalize (Allocator &al, const Location &loc, Vec<ASR::expr_t *> &args) {
657
657
LFORTRAN_ASSERT (ASRUtils::all_args_evaluated (args));
658
- if (args.size () != 1 ) {
659
- throw SemanticError (" _lpython_str_capitalize() takes exactly one arguments (" +
660
- std::to_string (args.size ()) + " given)" , loc);
661
- }
662
- ASR::expr_t *arg1 = args[0 ];
663
- ASR::ttype_t *arg1_type = ASRUtils::expr_type (arg1);
664
- if (ASRUtils::is_character (*arg1_type)) {
665
- std::string val = ASR::down_cast<ASR::StringConstant_t>(arg1)->m_s ;
666
- ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Character_t (al, loc,
667
- 1 , 1 , nullptr , nullptr , 0 ));
668
- ASR::ttype_t *res_type = ASRUtils::TYPE (ASR::make_StringConstant_t (al, loc, s2c (al, " " ), type));
669
- return ASR::down_cast<ASR::expr_t >(ASR::make_StringConstant_t (al, loc, s2c (al, val), res_type));
670
- } else {
671
- throw SemanticError (" Only string from arguments." , loc);
672
- }
658
+ if (args.size () != 0 ) {
659
+ throw SemanticError (" str.capitalize() takes no arguments" , loc);
660
+ }
661
+ ASR::expr_t *arg = args[0 ];
662
+ ASR::ttype_t *arg_type = ASRUtils::expr_type (arg);
663
+ std::string val = ASR::down_cast<ASR::StringConstant_t>(arg)->m_s ;
664
+ val = std::toupper (val[0 ]);
665
+ ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Character_t (al, loc,
666
+ 1 , 1 , nullptr , nullptr , 0 ));
667
+ ASR::ttype_t *res_type = ASRUtils::TYPE (ASR::make_StringConstant_t (al, loc, s2c (al, " " ), type));
668
+ return ASR::down_cast<ASR::expr_t >(ASR::make_StringConstant_t (al, loc, s2c (al, val), res_type));
673
669
}
674
670
675
671
static ASR::expr_t *eval__lpython_str_lower (Allocator &al, const Location &loc, Vec<ASR::expr_t *> &args) {
0 commit comments