blob: eba37e9cc809de23101c3f27aa6fd73bf7f3962d [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
Amaury Forgeot d'Arcf2e93682008-09-26 22:48:41 +000016 if (str_len < 0)
17 return 0; /* start > len(str) */
18 if (sub_len == 0)
Thomas Wouters477c8d52006-05-27 19:21:47 +000019 return str_len + 1;
Thomas Wouters477c8d52006-05-27 19:21:47 +000020
21 count = fastsearch(str, str_len, sub, sub_len, FAST_COUNT);
22
23 if (count < 0)
24 count = 0; /* no match */
25
26 return count;
27}
28
29#endif
30
31/*
32Local variables:
33c-basic-offset: 4
34indent-tabs-mode: nil
35End:
36*/