@@ -43,28 +43,47 @@ ReturnType KeyMatch2(Scope scope) {
4343 string key1 = GetString (scope, 0 );
4444 string key2 = GetString (scope, 1 );
4545
46- vector <size_t > indexes = FindAllOccurences (key2, " /*" );
47- for (int i = 0 ; i < indexes.size () ; i++) {
48- key1.replace (indexes[i], 2 , " /.*" );
49- }
50-
51- regex regex_s (" (.*):[^/]+(.*)" );
52- smatch match;
53-
54- while (true ) {
46+ vector<string> key1_arr = Split (key1, " /" );
47+ vector<string> key2_arr = Split (key2, " /" );
5548
56- if (key2.find (" /:" ) == string::npos)
49+ bool res = true ;
50+ for (int i=0 ;i<key2_arr.size ();i++){
51+ if (i >= key1_arr.size ()){
52+ res = false ;
5753 break ;
58-
59- if (regex_search (key2, match, regex_s)) {
60- for (int i=1 ; i<match.size (); i++)
61- key2 = key2.replace (match.position (i), match.str (i).length (), " $1[^/]+$2" );
6254 }
63-
55+ if (key1_arr[i] != key2_arr[i]){
56+ int index1 = key2_arr[i].find (" *" );
57+ int index2 = key2_arr[i].find (" :" );
58+ if (index1 != string::npos){
59+ if (index1==0 ){
60+ res = true ;
61+ break ;
62+ } else if (key1_arr[i].compare (key2_arr[i].substr (0 , index1))) {
63+ res = false ;
64+ break ;
65+ } else
66+ continue ;
67+ }
68+ if (index2==0 ){
69+ if (key1_arr[i]==" " || !key2_arr[i].substr (1 ).compare (" " )){
70+ res = false ;
71+ break ;
72+ }
73+ else
74+ continue ;
75+ }
76+ res = false ;
77+ break ;
78+ }else
79+ continue ;
6480 }
6581
66- regex regex_s1 (" ^" + key2 + " $" );
67- PushBooleanValue (scope, regex_match (key1, regex_s1));
82+ if (key2_arr.size () < key1_arr.size ())
83+ if (key2_arr[key2_arr.size ()-1 ] != " *" )
84+ res = false ;
85+
86+ PushBooleanValue (scope, res);
6887 return RETURN_RESULT;
6988}
7089
@@ -74,25 +93,48 @@ ReturnType KeyMatch3(Scope scope) {
7493 string key1 = GetString (scope, 0 );
7594 string key2 = GetString (scope, 1 );
7695
77- vector<size_t > indexes = FindAllOccurences (key2, " /*" );
78- for (int i = 0 ; i < indexes.size () ; i++)
79- key1.replace (indexes[i], 2 , " /.*" );
80-
81- regex regex_s (" (.*)\\ {[^/]+\\ }(.*)" );
82- smatch match;
96+ vector<string> key1_arr = Split (key1, " /" );
97+ vector<string> key2_arr = Split (key2, " /" );
8398
84- while (true ) {
85- if (key2.find (" /{" ) == string::npos)
99+ bool res = true ;
100+ for (int i=0 ;i<key2_arr.size ();i++){
101+ if (i >= key1_arr.size ()){
102+ res = false ;
86103 break ;
87-
88- if (regex_search (key2, match, regex_s)) {
89- for (int i=1 ; i<match.size (); i++)
90- key2 = key2.replace (match.position (i), match.str (i).length (), " $1[^/]+$2" );
91104 }
105+ if (key1_arr[i] != key2_arr[i]){
106+ int index1 = key2_arr[i].find (" *" );
107+ int index2 = key2_arr[i].find (" {" );
108+ int index3 = key2_arr[i].find (" }" );
109+ if (index1 != string::npos){
110+ if (index1==0 ){
111+ res = true ;
112+ break ;
113+ } else if (key1_arr[i].compare (key2_arr[i].substr (0 , index1))) {
114+ res = false ;
115+ break ;
116+ } else
117+ continue ;
118+ }
119+ if (index2==0 && index3 > 0 && index3 != string::npos){
120+ if (key1_arr[i]==" " || !key2_arr[i].substr (1 , key2_arr[i].length ()-2 ).compare (" " )){
121+ res = false ;
122+ break ;
123+ }
124+ else
125+ continue ;
126+ }
127+ res = false ;
128+ break ;
129+ }else
130+ continue ;
92131 }
93132
94- regex regex_s1 (" ^" +key2+" $" );
95- PushBooleanValue (scope, regex_match (key1, regex_s1));
133+ if (key2_arr.size () < key1_arr.size ())
134+ if (key2_arr[key2_arr.size ()-1 ] != " *" )
135+ res = false ;
136+
137+ PushBooleanValue (scope, res);
96138 return RETURN_RESULT;
97139}
98140
@@ -114,13 +156,13 @@ ReturnType IPMatch(Scope scope) {
114156
115157 IP objIP1 = parseIP (ip1);
116158 if (objIP1.isLegal == false )
117- IllegalArgumentException (" invalid argument: ip1 in IPMatch() function is not an IP address." );
159+ throw IllegalArgumentException (" invalid argument: ip1 in IPMatch() function is not an IP address." );
118160
119161 CIDR objCIDR = parseCIDR (ip2);
120162 if (objCIDR.ip .isLegal == false ) {
121163 IP objIP2 = parseIP (ip2);
122164 if (objIP2.isLegal == false )
123- IllegalArgumentException (" invalid argument: ip1 in IPMatch() function is not an IP address." );
165+ throw IllegalArgumentException (" invalid argument: ip1 in IPMatch() function is not an IP address." );
124166
125167 PushBooleanValue (scope, objIP1.Equal (objIP2));
126168 return RETURN_RESULT;
0 commit comments