* It would be more efficient to use a variation of KMP to * benefit from the failure function. * - Algorithm inspired by James Kanze. * - http://stackoverflow.com/questions/20406744/ */
| 84 | * - http://stackoverflow.com/questions/20406744/ |
| 85 | */ |
| 86 | size_t find_Nth(const string &str, // where to work |
| 87 | unsigned N, // N'th occurrence |
| 88 | const string &find // what to 'find' |
| 89 | ) { |
| 90 | if (0 == N) { |
| 91 | return string::npos; |
| 92 | } |
| 93 | size_t pos, from = 0; |
| 94 | unsigned i = 0; |
| 95 | while (i < N) { |
| 96 | pos = str.find(find, from); |
| 97 | if (string::npos == pos) { |
| 98 | break; |
| 99 | } |
| 100 | from = pos + 1; // from = pos + find.size(); |
| 101 | ++i; |
| 102 | } |
| 103 | return pos; |
| 104 | } |
| 105 | |
| 106 | #// Suppress deprecation warnings for MD5 functions on OpenSSL >= 3.0 |
| 107 | #if defined(__clang__) |