blob: 367a15c51a5d4872214b3e78682d96da403665ea [file] [log] [blame]
Thomas Wouters477c8d52006-05-27 19:21:47 +00001/* 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
10Py_LOCAL_INLINE(Py_ssize_t)
11stringlib_count(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
12 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len)
13{
14 Py_ssize_t count;
15
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000016 if (sub_len == 0) {
17 if (str_len < 0)
18 return 0; /* start > len(str) */
Thomas Wouters477c8d52006-05-27 19:21:47 +000019 return str_len + 1;
Thomas Wouters4d70c3d2006-06-08 14:42:34 +000020 }
Thomas Wouters477c8d52006-05-27 19:21:47 +000021
22 count = fastsearch(str, str_len, sub, sub_len, FAST_COUNT);
23
24 if (count < 0)
25 count = 0; /* no match */
26
27 return count;
28}
29
30#endif
31
32/*
33Local variables:
34c-basic-offset: 4
35indent-tabs-mode: nil
36End:
37*/