/src/Python-3.8.3/Objects/stringlib/find.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* stringlib: find/index implementation */ |
2 | | |
3 | | #ifndef STRINGLIB_FASTSEARCH_H |
4 | | #error must include "stringlib/fastsearch.h" before including this module |
5 | | #endif |
6 | | |
7 | | Py_LOCAL_INLINE(Py_ssize_t) |
8 | | STRINGLIB(find)(const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
9 | | const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, |
10 | | Py_ssize_t offset) |
11 | 53 | { |
12 | 53 | Py_ssize_t pos; |
13 | | |
14 | 53 | assert(str_len >= 0); |
15 | 53 | if (sub_len == 0) |
16 | 0 | return offset; |
17 | | |
18 | 53 | pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH); |
19 | | |
20 | 53 | if (pos >= 0) |
21 | 18 | pos += offset; |
22 | | |
23 | 53 | return pos; |
24 | 53 | } Unexecuted instantiation: bytearrayobject.c:stringlib_find Unexecuted instantiation: bytesobject.c:stringlib_find unicodeobject.c:asciilib_find Line | Count | Source | 11 | 32 | { | 12 | 32 | Py_ssize_t pos; | 13 | | | 14 | 32 | assert(str_len >= 0); | 15 | 32 | if (sub_len == 0) | 16 | 0 | return offset; | 17 | | | 18 | 32 | pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH); | 19 | | | 20 | 32 | if (pos >= 0) | 21 | 18 | pos += offset; | 22 | | | 23 | 32 | return pos; | 24 | 32 | } |
unicodeobject.c:ucs1lib_find Line | Count | Source | 11 | 21 | { | 12 | 21 | Py_ssize_t pos; | 13 | | | 14 | 21 | assert(str_len >= 0); | 15 | 21 | if (sub_len == 0) | 16 | 0 | return offset; | 17 | | | 18 | 21 | pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_SEARCH); | 19 | | | 20 | 21 | if (pos >= 0) | 21 | 0 | pos += offset; | 22 | | | 23 | 21 | return pos; | 24 | 21 | } |
Unexecuted instantiation: unicodeobject.c:ucs2lib_find Unexecuted instantiation: unicodeobject.c:ucs4lib_find Unexecuted instantiation: unicodeobject.c:stringlib_find Unexecuted instantiation: bytes_methods.c:stringlib_find |
25 | | |
26 | | Py_LOCAL_INLINE(Py_ssize_t) |
27 | | STRINGLIB(rfind)(const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
28 | | const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, |
29 | | Py_ssize_t offset) |
30 | 0 | { |
31 | 0 | Py_ssize_t pos; |
32 | |
|
33 | 0 | assert(str_len >= 0); |
34 | 0 | if (sub_len == 0) |
35 | 0 | return str_len + offset; |
36 | | |
37 | 0 | pos = FASTSEARCH(str, str_len, sub, sub_len, -1, FAST_RSEARCH); |
38 | |
|
39 | 0 | if (pos >= 0) |
40 | 0 | pos += offset; |
41 | |
|
42 | 0 | return pos; |
43 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_rfind Unexecuted instantiation: bytesobject.c:stringlib_rfind Unexecuted instantiation: unicodeobject.c:asciilib_rfind Unexecuted instantiation: unicodeobject.c:ucs1lib_rfind Unexecuted instantiation: unicodeobject.c:ucs2lib_rfind Unexecuted instantiation: unicodeobject.c:ucs4lib_rfind Unexecuted instantiation: unicodeobject.c:stringlib_rfind Unexecuted instantiation: bytes_methods.c:stringlib_rfind |
44 | | |
45 | | Py_LOCAL_INLINE(Py_ssize_t) |
46 | | STRINGLIB(find_slice)(const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
47 | | const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, |
48 | | Py_ssize_t start, Py_ssize_t end) |
49 | 14 | { |
50 | 14 | return STRINGLIB(find)(str + start, end - start, sub, sub_len, start); |
51 | 14 | } Unexecuted instantiation: bytearrayobject.c:stringlib_find_slice Unexecuted instantiation: bytesobject.c:stringlib_find_slice unicodeobject.c:asciilib_find_slice Line | Count | Source | 49 | 14 | { | 50 | 14 | return STRINGLIB(find)(str + start, end - start, sub, sub_len, start); | 51 | 14 | } |
Unexecuted instantiation: unicodeobject.c:ucs1lib_find_slice Unexecuted instantiation: unicodeobject.c:ucs2lib_find_slice Unexecuted instantiation: unicodeobject.c:ucs4lib_find_slice Unexecuted instantiation: unicodeobject.c:stringlib_find_slice Unexecuted instantiation: bytes_methods.c:stringlib_find_slice |
52 | | |
53 | | Py_LOCAL_INLINE(Py_ssize_t) |
54 | | STRINGLIB(rfind_slice)(const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
55 | | const STRINGLIB_CHAR* sub, Py_ssize_t sub_len, |
56 | | Py_ssize_t start, Py_ssize_t end) |
57 | 0 | { |
58 | 0 | return STRINGLIB(rfind)(str + start, end - start, sub, sub_len, start); |
59 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_rfind_slice Unexecuted instantiation: bytesobject.c:stringlib_rfind_slice Unexecuted instantiation: unicodeobject.c:asciilib_rfind_slice Unexecuted instantiation: unicodeobject.c:ucs1lib_rfind_slice Unexecuted instantiation: unicodeobject.c:ucs2lib_rfind_slice Unexecuted instantiation: unicodeobject.c:ucs4lib_rfind_slice Unexecuted instantiation: unicodeobject.c:stringlib_rfind_slice Unexecuted instantiation: bytes_methods.c:stringlib_rfind_slice |
60 | | |
61 | | #ifdef STRINGLIB_WANT_CONTAINS_OBJ |
62 | | |
63 | | Py_LOCAL_INLINE(int) |
64 | | STRINGLIB(contains_obj)(PyObject* str, PyObject* sub) |
65 | 0 | { |
66 | 0 | return STRINGLIB(find)( |
67 | 0 | STRINGLIB_STR(str), STRINGLIB_LEN(str), |
68 | 0 | STRINGLIB_STR(sub), STRINGLIB_LEN(sub), 0 |
69 | 0 | ) != -1; |
70 | 0 | } |
71 | | |
72 | | #endif /* STRINGLIB_WANT_CONTAINS_OBJ */ |
73 | | |
74 | | /* |
75 | | This function is a helper for the "find" family (find, rfind, index, |
76 | | rindex) and for count, startswith and endswith, because they all have |
77 | | the same behaviour for the arguments. |
78 | | |
79 | | It does not touch the variables received until it knows everything |
80 | | is ok. |
81 | | */ |
82 | | |
83 | 2.23k | #define FORMAT_BUFFER_SIZE 50 |
84 | | |
85 | | Py_LOCAL_INLINE(int) |
86 | | STRINGLIB(parse_args_finds)(const char * function_name, PyObject *args, |
87 | | PyObject **subobj, |
88 | | Py_ssize_t *start, Py_ssize_t *end) |
89 | 1.11k | { |
90 | 1.11k | PyObject *tmp_subobj; |
91 | 1.11k | Py_ssize_t tmp_start = 0; |
92 | 1.11k | Py_ssize_t tmp_end = PY_SSIZE_T_MAX; |
93 | 1.11k | PyObject *obj_start=Py_None, *obj_end=Py_None; |
94 | 1.11k | char format[FORMAT_BUFFER_SIZE] = "O|OO:"; |
95 | 1.11k | size_t len = strlen(format); |
96 | | |
97 | 1.11k | strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1); |
98 | 1.11k | format[FORMAT_BUFFER_SIZE - 1] = '\0'; |
99 | | |
100 | 1.11k | if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end)) |
101 | 0 | return 0; |
102 | | |
103 | | /* To support None in "start" and "end" arguments, meaning |
104 | | the same as if they were not passed. |
105 | | */ |
106 | 1.11k | if (obj_start != Py_None) |
107 | 88 | if (!_PyEval_SliceIndex(obj_start, &tmp_start)) |
108 | 0 | return 0; |
109 | 1.11k | if (obj_end != Py_None) |
110 | 0 | if (!_PyEval_SliceIndex(obj_end, &tmp_end)) |
111 | 0 | return 0; |
112 | | |
113 | 1.11k | *start = tmp_start; |
114 | 1.11k | *end = tmp_end; |
115 | 1.11k | *subobj = tmp_subobj; |
116 | 1.11k | return 1; |
117 | 1.11k | } Unexecuted instantiation: bytearrayobject.c:stringlib_parse_args_finds Unexecuted instantiation: bytesobject.c:stringlib_parse_args_finds unicodeobject.c:stringlib_parse_args_finds Line | Count | Source | 89 | 1.02k | { | 90 | 1.02k | PyObject *tmp_subobj; | 91 | 1.02k | Py_ssize_t tmp_start = 0; | 92 | 1.02k | Py_ssize_t tmp_end = PY_SSIZE_T_MAX; | 93 | 1.02k | PyObject *obj_start=Py_None, *obj_end=Py_None; | 94 | 1.02k | char format[FORMAT_BUFFER_SIZE] = "O|OO:"; | 95 | 1.02k | size_t len = strlen(format); | 96 | | | 97 | 1.02k | strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1); | 98 | 1.02k | format[FORMAT_BUFFER_SIZE - 1] = '\0'; | 99 | | | 100 | 1.02k | if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end)) | 101 | 0 | return 0; | 102 | | | 103 | | /* To support None in "start" and "end" arguments, meaning | 104 | | the same as if they were not passed. | 105 | | */ | 106 | 1.02k | if (obj_start != Py_None) | 107 | 0 | if (!_PyEval_SliceIndex(obj_start, &tmp_start)) | 108 | 0 | return 0; | 109 | 1.02k | if (obj_end != Py_None) | 110 | 0 | if (!_PyEval_SliceIndex(obj_end, &tmp_end)) | 111 | 0 | return 0; | 112 | | | 113 | 1.02k | *start = tmp_start; | 114 | 1.02k | *end = tmp_end; | 115 | 1.02k | *subobj = tmp_subobj; | 116 | 1.02k | return 1; | 117 | 1.02k | } |
Unexecuted instantiation: unicodeobject.c:asciilib_parse_args_finds Unexecuted instantiation: unicodeobject.c:ucs1lib_parse_args_finds Unexecuted instantiation: unicodeobject.c:ucs2lib_parse_args_finds Unexecuted instantiation: unicodeobject.c:ucs4lib_parse_args_finds bytes_methods.c:stringlib_parse_args_finds Line | Count | Source | 89 | 89 | { | 90 | 89 | PyObject *tmp_subobj; | 91 | 89 | Py_ssize_t tmp_start = 0; | 92 | 89 | Py_ssize_t tmp_end = PY_SSIZE_T_MAX; | 93 | 89 | PyObject *obj_start=Py_None, *obj_end=Py_None; | 94 | 89 | char format[FORMAT_BUFFER_SIZE] = "O|OO:"; | 95 | 89 | size_t len = strlen(format); | 96 | | | 97 | 89 | strncpy(format + len, function_name, FORMAT_BUFFER_SIZE - len - 1); | 98 | 89 | format[FORMAT_BUFFER_SIZE - 1] = '\0'; | 99 | | | 100 | 89 | if (!PyArg_ParseTuple(args, format, &tmp_subobj, &obj_start, &obj_end)) | 101 | 0 | return 0; | 102 | | | 103 | | /* To support None in "start" and "end" arguments, meaning | 104 | | the same as if they were not passed. | 105 | | */ | 106 | 89 | if (obj_start != Py_None) | 107 | 88 | if (!_PyEval_SliceIndex(obj_start, &tmp_start)) | 108 | 0 | return 0; | 109 | 89 | if (obj_end != Py_None) | 110 | 0 | if (!_PyEval_SliceIndex(obj_end, &tmp_end)) | 111 | 0 | return 0; | 112 | | | 113 | 89 | *start = tmp_start; | 114 | 89 | *end = tmp_end; | 115 | 89 | *subobj = tmp_subobj; | 116 | 89 | return 1; | 117 | 89 | } |
|
118 | | |
119 | | #undef FORMAT_BUFFER_SIZE |