(file) Return to CQLRegularExpression.cpp CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / CQL

  1 karl  1.5 //%2006////////////////////////////////////////////////////////////////////////
  2 chuck 1.2 //
  3 karl  1.3 // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
  4           // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
  5           // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L.P.;
  6 chuck 1.2 // IBM Corp.; EMC Corporation, The Open Group.
  7 karl  1.3 // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
  8           // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
  9           // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 10           // EMC Corporation; VERITAS Software Corporation; The Open Group.
 11 karl  1.5 // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
 12           // EMC Corporation; Symantec Corporation; The Open Group.
 13 chuck 1.2 //
 14           // Permission is hereby granted, free of charge, to any person obtaining a copy
 15           // of this software and associated documentation files (the "Software"), to
 16           // deal in the Software without restriction, including without limitation the
 17           // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
 18           // sell copies of the Software, and to permit persons to whom the Software is
 19           // furnished to do so, subject to the following conditions:
 20 karl  1.3 // 
 21 chuck 1.2 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
 22           // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
 23           // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
 24           // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 25           // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 26           // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 27           // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 28           // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 29           //
 30           //==============================================================================
 31 karl  1.3 
 32 chuck 1.2 //
 33           // Author: Dan Gorey (djgorey@us.ibm.com)
 34           //
 35           // Modified By:
 36           //
 37           //%/////////////////////////////////////////////////////////////////////////////
 38           
 39           
 40           
 41           #include "CQLRegularExpression.h"
 42           #include <Pegasus/Common/Char16.h>
 43           #include <Pegasus/Common/CommonUTF.h>
 44           
 45           PEGASUS_NAMESPACE_BEGIN
 46           
 47           CQLRegularExpression::CQLRegularExpression()
 48           {
 49           }
 50           
 51           CQLRegularExpression::~CQLRegularExpression()
 52           {
 53 chuck 1.2 }
 54           
 55           
 56           Boolean CQLRegularExpression::match(const String& string, const String& pattern)
 57           {
 58               Uint32 patIndex = 0;
 59               Uint32 strIndex = 0;
 60           
 61               // if either pattern or string are "EMPTY" you have an invalid String
 62               if (pattern == String::EMPTY) {
 63                   return false;
 64               }
 65           
 66               if (string == String::EMPTY) {
 67                   return false;
 68               }
 69           
 70               while (true) {
 71                   if ( (string.size() == strIndex) && (pattern.size() == patIndex)) {
 72                       return true;
 73                   } else if ((string.size() == strIndex) || (pattern.size() == patIndex)) {
 74 chuck 1.2             return false;
 75                   }
 76           
 77                   //  Check if pattern equal to  '.'
 78                   if (pattern[patIndex] == '.') {
 79                       //assumes a valid multi-byte pair has been passed
 80                       if ((((Uint16)pattern[patIndex] >= FIRST_HIGH_SURROGATE) && 
 81                            ((Uint16)pattern[patIndex] <= LAST_HIGH_SURROGATE)) ||
 82                           (((Uint16)pattern[patIndex] >= FIRST_LOW_SURROGATE) && 
 83                            ((Uint16)pattern[patIndex] <= LAST_LOW_SURROGATE))) {
 84                           patIndex ++;
 85                           strIndex ++;
 86                       }
 87           
 88                       strIndex ++;
 89                       patIndex ++;
 90           
 91                       // Check if pattern equal to '*'
 92                   } else if (pattern[patIndex] == '*') {
 93           	    if(patIndex == 0)
 94           	        return false;
 95 chuck 1.2             if (pattern[patIndex-1] == '.') {
 96                           if ((patIndex > 1) && pattern[patIndex-2] =='\\') {
 97                               if (string[strIndex] != '.') {
 98                                   return false;
 99                               }
100                           } else if (pattern.size()-1 == patIndex) {
101                               return true;
102                           } else if (string.size()-1 == strIndex) {
103                               return false;
104                           }
105                       } else if (pattern[patIndex-1] == '\\') {
106                           if (pattern[patIndex-2] == '.') {
107                               if (string[strIndex] != '*') {
108                                   return false;
109                               }
110                           }
111                       } else if ((((Uint16)pattern[patIndex-2] >= FIRST_HIGH_SURROGATE) && 
112                                   ((Uint16)pattern[patIndex-2] <= LAST_HIGH_SURROGATE)) ||
113                                  (((Uint16)pattern[patIndex-2] >= FIRST_LOW_SURROGATE) && 
114                                   ((Uint16)pattern[patIndex-2] <= LAST_LOW_SURROGATE))) {
115           
116 chuck 1.2                 if (pattern[patIndex-2] != string[strIndex]) {
117                               return false;
118                           } else if (pattern[patIndex-1] != string[strIndex+1]) {
119                               return false;
120                           } else {
121                               strIndex ++;
122                           }
123                       } else if (pattern[patIndex-1] != string[strIndex]) {
124                           return false;
125                       }
126                       while (true) {
127                           strIndex ++;
128           
129                           if (pattern[patIndex-1] == '.') {
130                               if ((patIndex > 1) && (pattern[patIndex-2] =='\\')) {
131                                   if (string[strIndex] != '.') {
132                                       patIndex ++;
133                                       break;
134                                   }
135                               } else if (pattern[patIndex+1] == string[strIndex]) {
136                                   //make copies of the indexes in case you do not reach
137 chuck 1.2                         //the end of the string
138                                   int stringOrig = strIndex;
139                                   int patternOrig = patIndex;
140                                   patIndex++;
141           
142                                   if (strIndex == string.size()-1 && patIndex == pattern.size()-1) {
143                                       return true;
144                                   }
145                                   while (true) {
146                                       strIndex++;
147                                       patIndex ++;
148                                       if (pattern[patIndex] != string[strIndex]) {
149                                           strIndex = stringOrig + 1;
150                                           patIndex = patternOrig;
151                                           break;
152                                       } else if (strIndex == string.size()-1 && 
153                                                  patIndex == pattern.size()-1) {
154                                           break;
155                                       }
156                                       patIndex++;
157                                   }
158 chuck 1.2                     }
159                           } else if (pattern[patIndex-1] == '\\') {
160                               if (pattern[patIndex-2] == '.') {
161                                   if (string[strIndex] != '*') {
162                                       patIndex ++;
163                                       break;
164                                   }
165                                   if (strIndex == string.size()-1 && patIndex == pattern.size()-1) {
166                                       return true;
167                                   }
168                                   while (true) {
169                                       strIndex ++;
170                                       if (string[strIndex] != '*') {
171                                           patIndex ++;
172                                           break;
173                                       }
174                                       if (strIndex == string.size()-1 && 
175                                           patIndex == pattern.size()-1) {
176                                           return true;
177                                       }
178                                   }
179 chuck 1.2                     }
180                           } else if ((((Uint16)pattern[patIndex-2] >= FIRST_HIGH_SURROGATE) && 
181                                       ((Uint16)pattern[patIndex-2] <= LAST_HIGH_SURROGATE)) ||
182                                      (((Uint16)pattern[patIndex-2] >= FIRST_LOW_SURROGATE) && 
183                                       ((Uint16)pattern[patIndex-2] <= LAST_LOW_SURROGATE))) {
184           
185                               if (pattern[patIndex-2] != string[strIndex]) {
186                                   patIndex ++;
187                                   break;
188                               } else if (pattern[patIndex-1] != string[strIndex+1]) {
189                                   patIndex ++;
190                                   break;
191                               } else {
192                                   strIndex ++;
193                               }
194                           } else if (pattern[patIndex-1] != string[strIndex]) {
195                               patIndex ++;
196                               break;
197                           }
198           
199                           if (strIndex == string.size()-1 && patIndex == pattern.size()-1) {
200 chuck 1.2                     return true;
201                           } else if (strIndex == string.size()-1) {
202                               return false;
203           
204                           }
205           
206                       }
207                       // check if pattern equal to '\'
208                   } else if (pattern[patIndex] == '\\') {
209                       patIndex ++;
210                       if ((((Uint16)pattern[patIndex] >= FIRST_HIGH_SURROGATE) && 
211                            ((Uint16)pattern[patIndex] <= LAST_HIGH_SURROGATE)) ||
212                           (((Uint16)pattern[patIndex] >= FIRST_LOW_SURROGATE) && 
213                            ((Uint16)pattern[patIndex] <= LAST_LOW_SURROGATE))) {
214           
215                           if (pattern[patIndex] != string[strIndex]) {
216                               return false;
217                           } else if (pattern[patIndex+1] != string[strIndex+1]) {
218                               return false;
219                           } else {
220                               patIndex ++;
221 chuck 1.2                     strIndex ++;
222                           }
223                       } else {
224                           if (pattern[patIndex] != string[strIndex]) {
225                               return false;
226                           }
227                           if (strIndex == string.size()-1 && patIndex == pattern.size()-1) {
228                               return true;
229                           }
230                           strIndex ++;
231                           patIndex ++;
232           
233                       }  
234           
235                       //default 
236                   } else {
237                       if ((((Uint16)pattern[patIndex] >= FIRST_HIGH_SURROGATE) && 
238                            ((Uint16)pattern[patIndex] <= LAST_HIGH_SURROGATE)) ||
239                           (((Uint16)pattern[patIndex] >= FIRST_LOW_SURROGATE) && 
240                            ((Uint16)pattern[patIndex] <= LAST_LOW_SURROGATE))) {
241           
242 chuck 1.2                 if (pattern[patIndex] != string[strIndex]) {
243                               return false;
244                           } else if (pattern[patIndex+1] != string[strIndex+1]) {
245                               return false;
246                           } else {
247                               patIndex ++;
248                               strIndex ++;
249                           }
250                       } else if (pattern[patIndex] != string[strIndex]) {
251                           return false;
252                       }
253                       patIndex ++;
254                       strIndex ++;
255                   }
256               }
257 carson.hovey 1.4     PEGASUS_UNREACHABLE( return false; )
258 chuck        1.2 }
259                  
260                  PEGASUS_NAMESPACE_END
261                  
262                  
263                  

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2