This function removes each occurrence of the flag and returns the last one (i.e., the dominant flag in GCC)
| 2279 | // This function removes each occurrence of the flag and returns the last one |
| 2280 | // (i.e., the dominant flag in GCC) |
| 2281 | std::string cmGlobalXCodeGenerator::ExtractFlag(char const* flag, |
| 2282 | std::string& flags) |
| 2283 | { |
| 2284 | std::string retFlag; |
| 2285 | std::string::size_type lastOccurrencePos = flags.rfind(flag); |
| 2286 | bool saved = false; |
| 2287 | while (lastOccurrencePos != std::string::npos) { |
| 2288 | // increment pos, we use lastOccurrencePos to reduce search space on next |
| 2289 | // inc |
| 2290 | std::string::size_type pos = lastOccurrencePos; |
| 2291 | if (pos == 0 || flags[pos - 1] == ' ') { |
| 2292 | while (pos < flags.size() && flags[pos] != ' ') { |
| 2293 | if (!saved) { |
| 2294 | retFlag += flags[pos]; |
| 2295 | } |
| 2296 | flags[pos] = ' '; |
| 2297 | pos++; |
| 2298 | } |
| 2299 | saved = true; |
| 2300 | } |
| 2301 | // decrement lastOccurrencePos while making sure we don't loop around |
| 2302 | // and become a very large positive number since size_type is unsigned |
| 2303 | lastOccurrencePos = lastOccurrencePos == 0 ? 0 : lastOccurrencePos - 1; |
| 2304 | lastOccurrencePos = flags.rfind(flag, lastOccurrencePos); |
| 2305 | } |
| 2306 | return retFlag; |
| 2307 | } |
| 2308 | |
| 2309 | // This function removes each matching occurrence of the expression and |
| 2310 | // returns the last one (i.e., the dominant flag in GCC) |
no test coverage detected