From 00d7fb6fb0e0f2438da3c11f6fbfb2fe9bf52c4d Mon Sep 17 00:00:00 2001 From: msojocs Date: Wed, 21 Jun 2023 15:51:09 +0800 Subject: [PATCH] feat: IsValidVariableName --- src/include/wxml.h | 4 ++++ src/wxml/dom_lib/token.cpp | 41 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/include/wxml.h b/src/include/wxml.h index 098bda1..75a98a7 100644 --- a/src/include/wxml.h +++ b/src/include/wxml.h @@ -108,6 +108,10 @@ namespace WXML * 返回值类型string */ std::string ToAttrContent(); + + /** + * 变量名是否有效 + */ bool IsValidVariableName(std::string const&); bool IsMatch(char const*); /** diff --git a/src/wxml/dom_lib/token.cpp b/src/wxml/dom_lib/token.cpp index 0dc7909..d05c418 100644 --- a/src/wxml/dom_lib/token.cpp +++ b/src/wxml/dom_lib/token.cpp @@ -78,6 +78,47 @@ namespace WXML { return ""; } + bool Token::IsValidVariableName(std::string const& a1) + { + char v1 = a1[0]; + int v2; + + if ( v1 == '_'/*95*/ || v1 == '$'/*36*/ || (v2 = (v1 & 0xDF) - 'A'/*65*/, v2 <= 0x19u) ) // 0x19u 25 + { + for (int i = 0; ; i++) + { + if (a1.length() <= i) + return true; + char v5 = a1[i]; + int v6; + if ( v5 <= '`'/*96*/ ) + { + if ( v5 > '@'/*64*/ ) + { + if ( v5 <= 'Z'/*90*/ ) + continue; + if ( v5 != '_' ) + return 0; + } + if ( v5 <= '/'/*47*/ ) + { + if ( v5 != '$' ) + return 0; + continue; + } + v6 = v5 <= '9'/*57*/; + } + else + { + v6 = v5 <= 'z'/*122*/; + } + if ( !v6 ) + return false; + } + + } + return false; + } std::string Token::ToString() { std::string v4 = this->offset_32;