@@ -6793,7 +6793,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
67936793 /*
67946794 String Validation Methods i.e all "is" based functions are handled here
67956795 */
6796- std::vector<std::string> validation_methods{" lower" , " upper" , " decimal" , " ascii" , " space" , " alpha" , " title" }; // Database of validation methods supported
6796+ std::vector<std::string> validation_methods{" lower" , " upper" , " decimal" , " ascii" , " space" , " alpha" , " title" , " alnum " , " numeric " }; // Database of validation methods supported
67976797 std::string method_name = attr_name.substr (2 );
67986798
67996799 if (std::find (validation_methods.begin (),validation_methods.end (), method_name) == validation_methods.end ()) {
@@ -7096,7 +7096,7 @@ class BodyVisitor : public CommonVisitor<BodyVisitor> {
70967096 * islower() method is limited to English Alphabets currently
70977097 * TODO: We can support other characters from Unicode Library
70987098 */
7099- std::vector<std::string> validation_methods{" lower" , " upper" , " decimal" , " ascii" , " space" , " alpha" , " title" }; // Database of validation methods supported
7099+ std::vector<std::string> validation_methods{" lower" , " upper" , " decimal" , " ascii" , " space" , " alpha" , " title" , " alnum " , " numeric " }; // Database of validation methods supported
71007100 std::string method_name = attr_name.substr (2 );
71017101 if (std::find (validation_methods.begin (),validation_methods.end (), method_name) == validation_methods.end ()) {
71027102 throw SemanticError (" String method not implemented: " + attr_name, loc);
@@ -7210,6 +7210,38 @@ we will have to use something else.
72107210 tmp = ASR::make_LogicalConstant_t (al, loc, is_alpha,
72117211 ASRUtils::TYPE (ASR::make_Logical_t (al, loc, 4 )));
72127212 return ;
7213+ } else if (attr_name == " isalnum" ) {
7214+ /*
7215+ * Specification -
7216+ Return True if all characters in the string are alphabets or numbers,
7217+ and there is at least one character in the string.
7218+ */
7219+ bool is_alnum = (s_var.size () != 0 );
7220+ for (auto &i : s_var) {
7221+ if (!((i >= ' A' && i <= ' Z' ) || (i >= ' a' && i <= ' z' ) || (i >= ' 0' && i <= ' 9' ))) {
7222+ is_alnum = false ;
7223+ break ;
7224+ }
7225+ }
7226+ tmp = ASR::make_LogicalConstant_t (al, loc, is_alnum,
7227+ ASRUtils::TYPE (ASR::make_Logical_t (al, loc, 4 )));
7228+ return ;
7229+ } else if (attr_name == " isnumeric" ) {
7230+ /*
7231+ * Specification -
7232+ Return True if all characters in the string are numbers,
7233+ and there is at least one character in the string.
7234+ */
7235+ bool is_numeric = (s_var.size () != 0 );
7236+ for (auto &i : s_var) {
7237+ if (!(i >= ' 0' && i <= ' 9' )) {
7238+ is_numeric = false ;
7239+ break ;
7240+ }
7241+ }
7242+ tmp = ASR::make_LogicalConstant_t (al, loc, is_numeric,
7243+ ASRUtils::TYPE (ASR::make_Logical_t (al, loc, 4 )));
7244+ return ;
72137245 } else if (attr_name == " istitle" ) {
72147246 /*
72157247 * Specification -
0 commit comments