@@ -670,21 +670,21 @@ struct PythonIntrinsicProcedures {
670
670
671
671
static ASR::expr_t *eval__lpython_str_lower (Allocator &al, const Location &loc, Vec<ASR::expr_t *> &args) {
672
672
LFORTRAN_ASSERT (ASRUtils::all_args_evaluated (args));
673
- if (args.size () != 1 ) {
674
- throw SemanticError (" _lpython_str_lower() takes exactly one arguments (" +
675
- std::to_string (args.size ()) + " given)" , loc);
673
+ if (args.size () != 0 ) {
674
+ throw SemanticError (" str.lower() takes no arguments" , loc);
676
675
}
677
- ASR::expr_t *arg1 = args[0 ];
678
- ASR::ttype_t *arg1_type = ASRUtils::expr_type (arg1);
679
- if (ASRUtils::is_character (*arg1_type)) {
680
- std::string val = ASR::down_cast<ASR::StringConstant_t>(arg1)->m_s ;
681
- ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Character_t (al, loc,
682
- 1 , 1 , nullptr , nullptr , 0 ));
683
- ASR::ttype_t *res_type = ASRUtils::TYPE (ASR::make_StringConstant_t (al, loc, s2c (al, " " ), type));
684
- return ASR::down_cast<ASR::expr_t >(ASR::make_StringConstant_t (al, loc, s2c (al, val), res_type));
685
- } else {
686
- throw SemanticError (" Only string from arguments." , loc);
676
+ ASR::expr_t *arg = args[0 ];
677
+ ASR::ttype_t *arg_type = ASRUtils::expr_type (arg);
678
+ std::string val = ASR::down_cast<ASR::StringConstant_t>(arg)->m_s ;
679
+ for (auto &i: val) {
680
+ if (i >= ' A' && i <= ' Z' ) {
681
+ i = std::tolower (i);
682
+ }
687
683
}
684
+ ASR::ttype_t *type = ASRUtils::TYPE (ASR::make_Character_t (al, loc,
685
+ 1 , 1 , nullptr , nullptr , 0 ));
686
+ ASR::ttype_t *res_type = ASRUtils::TYPE (ASR::make_StringConstant_t (al, loc, s2c (al, " " ), type));
687
+ return ASR::down_cast<ASR::expr_t >(ASR::make_StringConstant_t (al, loc, s2c (al, val), res_type));
688
688
}
689
689
690
690
0 commit comments