~ubuntu-branches/debian/sid/gource/sid

« back to all changes in this revision

Viewing changes to src/core/regex.cpp

  • Committer: Package Import Robot
  • Author(s): Andrew Caudwell
  • Date: 2014-04-15 16:30:17 UTC
  • mfrom: (1.2.15)
  • Revision ID: package-import@ubuntu.com-20140415163017-ucdr2josj1spzrga
Tags: 0.41-1
* New upstream release
* Made VCS URIs canonical
* Changed watch file to look at Github for releases

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
 
139
139
bool Regex::matchAll(const std::string& str, std::vector<std::string>* results) {
140
140
   
141
 
    int offset = -1;
 
141
    int offset = 0;
 
142
    int match_count = 0;
142
143
    if(results != 0) results->clear();
143
 
    while((offset = matchOffset(str, results, offset+1)) != -1 && offset < str.size());
144
 
 
145
 
    return (offset != -1);
 
144
 
 
145
    int str_size = str.size();
 
146
    
 
147
    while((offset = matchOffset(str, results, offset)) != -1) {
 
148
        match_count++;
 
149
        if(offset >= str_size) break;
 
150
    }
 
151
 
 
152
    return match_count>0;
146
153
}
147
154
 
148
155
int Regex::matchOffset(const std::string& str, std::vector<std::string>* results, int offset) {
149
 
 
 
156
    
150
157
    int ovector[REGEX_MAX_MATCHES];
151
158
 
 
159
    if(offset >= str.size()) return -1;
 
160
    
 
161
    // To allow ^ to match the start of the remaining string
 
162
    // we offset the string before passing it to pcre_exec
 
163
    
152
164
    int rc = pcre_exec(
153
165
        re,
154
166
        0,
155
 
        str.c_str(),
156
 
        str.size(),
157
 
        offset,
 
167
        str.c_str() + offset,
 
168
        str.size()-offset,
 
169
        0,
158
170
        0,
159
171
        ovector,
160
172
        REGEX_MAX_MATCHES
174
186
            if(match_start == -1) {
175
187
                results->push_back(std::string(""));
176
188
            } else {
177
 
                std::string match(str, match_start, match_end-match_start);
 
189
                std::string match(str, match_start+offset, match_end-match_start);
178
190
                results->push_back(match);
179
191
            }
180
192
        }
181
193
    }
182
194
 
183
 
    return ovector[1];
 
195
    return ovector[1]+offset;
184
196
}
185
 
 
186