Line data Source code
1 : /* stringlib: count implementation */
2 :
3 : #ifndef STRINGLIB_COUNT_H
4 : #define STRINGLIB_COUNT_H
5 :
6 : #ifndef STRINGLIB_FASTSEARCH_H
7 : #error must include "stringlib/fastsearch.h" before including this module
8 : #endif
9 :
10 : Py_LOCAL_INLINE(Py_ssize_t)
11 0 : stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
12 : const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
13 : Py_ssize_t maxcount)
14 : {
15 : Py_ssize_t count;
16 :
17 0 : if (str_len < 0)
18 0 : return 0; /* start > len(str) */
19 0 : if (sub_len == 0)
20 0 : return (str_len < maxcount) ? str_len + 1 : maxcount;
21 :
22 0 : count = fastsearch(str, str_len, sub, sub_len, maxcount, FAST_COUNT);
23 :
24 0 : if (count < 0)
25 0 : return 0; /* no match */
26 :
27 0 : return count;
28 : }
29 :
30 : #endif
|