OLD | NEW |
| (Empty) |
1 // Copyright 2005-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 | |
17 #include "omaha/base/atl_regexp.h" | |
18 | |
19 namespace omaha { | |
20 | |
21 const int kMaxArgs = 16; | |
22 | |
23 AtlRE::AtlRE(const TCHAR* pattern, bool case_sensitive) { | |
24 ASSERT(pattern, (L"")); | |
25 REParseError status = re_.Parse(pattern, case_sensitive); | |
26 ASSERT(status == REPARSE_ERROR_OK, (L"")); | |
27 } | |
28 | |
29 AtlRE::~AtlRE() { | |
30 } | |
31 | |
32 bool AtlRE::DoMatchImpl(const TCHAR* text, | |
33 CString* args[], | |
34 int n, | |
35 const TCHAR** match_end) const { | |
36 // text may be NULL. | |
37 ASSERT(args, (L"")); | |
38 | |
39 if (!text) { | |
40 return false; | |
41 } | |
42 | |
43 AtlMatchContext matches; | |
44 BOOL b = re_.Match(text, &matches, match_end); | |
45 if (!b || matches.m_uNumGroups < static_cast<uint32>(n)) { | |
46 return false; | |
47 } | |
48 | |
49 // Oddly enough, the Match call will make match_end | |
50 // point off the end of the string if the result is at the | |
51 // end of the string. We check this and handle it. | |
52 if (match_end) { | |
53 if ((*match_end - text) >= lstrlen(text)) { | |
54 *match_end = NULL; | |
55 } | |
56 } | |
57 | |
58 const TCHAR* start = 0; | |
59 const TCHAR* end = 0; | |
60 for (int i = 0; i < n; ++i) { | |
61 matches.GetMatch(i, &start, &end); | |
62 ptrdiff_t len = end - start; | |
63 ASSERT(args[i], (L"")); | |
64 // len+1 for the NULL character that's placed by lstrlen | |
65 VERIFY1(lstrcpyn(args[i]->GetBufferSetLength(len), start, len + 1) != NULL); | |
66 } | |
67 return true; | |
68 } | |
69 | |
70 } // namespace omaha | |
OLD | NEW |