MCPcopy Create free account
hub / github.com/apache/cloudberry / find_Nth

Function find_Nth

gpcontrib/gpcloud/src/s3utils.cpp:86–104  ·  view source on GitHub ↗

* 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/ */

Source from the content-addressed store, hash-verified

84 * - http://stackoverflow.com/questions/20406744/
85 */
86size_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__)

Callers 3

TESTFunction · 0.85
extractEncodedPrefixMethod · 0.85
extractBucketMethod · 0.85

Calls 1

findMethod · 0.80

Tested by 1

TESTFunction · 0.68