| 232 | } |
| 233 | |
| 234 | Int SpectrumLookup::extractScanNumber(const String& native_id, |
| 235 | const boost::regex& scan_regexp, |
| 236 | bool no_error) |
| 237 | { |
| 238 | vector<string> matches; |
| 239 | boost::sregex_token_iterator current_begin(native_id.begin(), native_id.end(), scan_regexp, 1); |
| 240 | boost::sregex_token_iterator current_end(native_id.end(), native_id.end(), scan_regexp, 1); |
| 241 | matches.insert(matches.end(), current_begin, current_end); |
| 242 | if (!matches.empty()) |
| 243 | { |
| 244 | // always use the last possible matching subgroup |
| 245 | String last_value = String(matches.back()); |
| 246 | try |
| 247 | { |
| 248 | return last_value.toInt(); |
| 249 | } |
| 250 | catch (Exception::ConversionError&) |
| 251 | { |
| 252 | } |
| 253 | } |
| 254 | if (!no_error) |
| 255 | { |
| 256 | throw Exception::ParseError(__FILE__, __LINE__, OPENMS_PRETTY_FUNCTION, |
| 257 | native_id, "Could not extract scan number"); |
| 258 | } |
| 259 | return -1; |
| 260 | } |
| 261 | |
| 262 | Int SpectrumLookup::extractScanNumber(const String& native_id, |
| 263 | const String& native_id_type_accession) |