/src/Python-3.8.3/Objects/stringlib/partition.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* stringlib: partition 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(PyObject*) |
8 | | STRINGLIB(partition)(PyObject* str_obj, |
9 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
10 | | PyObject* sep_obj, |
11 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
12 | 0 | { |
13 | 0 | PyObject* out; |
14 | 0 | Py_ssize_t pos; |
15 | |
|
16 | 0 | if (sep_len == 0) { |
17 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
18 | 0 | return NULL; |
19 | 0 | } |
20 | | |
21 | 0 | out = PyTuple_New(3); |
22 | 0 | if (!out) |
23 | 0 | return NULL; |
24 | | |
25 | 0 | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_SEARCH); |
26 | |
|
27 | 0 | if (pos < 0) { |
28 | | #if STRINGLIB_MUTABLE |
29 | 0 | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, str_len)); |
30 | 0 | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
31 | 0 | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(NULL, 0)); |
32 | | |
33 | 0 | if (PyErr_Occurred()) { |
34 | 0 | Py_DECREF(out); |
35 | 0 | return NULL; |
36 | 0 | } |
37 | | #else |
38 | 0 | Py_INCREF(str_obj); |
39 | 0 | PyTuple_SET_ITEM(out, 0, (PyObject*) str_obj); |
40 | 0 | Py_INCREF(STRINGLIB_EMPTY); |
41 | 0 | PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); |
42 | 0 | Py_INCREF(STRINGLIB_EMPTY); |
43 | 0 | PyTuple_SET_ITEM(out, 2, (PyObject*) STRINGLIB_EMPTY); |
44 | | #endif |
45 | 0 | return out; |
46 | 0 | } |
47 | | |
48 | 0 | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
49 | 0 | Py_INCREF(sep_obj); |
50 | 0 | PyTuple_SET_ITEM(out, 1, sep_obj); |
51 | 0 | pos += sep_len; |
52 | 0 | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
53 | |
|
54 | 0 | if (PyErr_Occurred()) { |
55 | 0 | Py_DECREF(out); |
56 | 0 | return NULL; |
57 | 0 | } |
58 | | |
59 | 0 | return out; |
60 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_partition Unexecuted instantiation: bytesobject.c:stringlib_partition Unexecuted instantiation: unicodeobject.c:asciilib_partition Unexecuted instantiation: unicodeobject.c:ucs1lib_partition Unexecuted instantiation: unicodeobject.c:ucs2lib_partition Unexecuted instantiation: unicodeobject.c:ucs4lib_partition |
61 | | |
62 | | Py_LOCAL_INLINE(PyObject*) |
63 | | STRINGLIB(rpartition)(PyObject* str_obj, |
64 | | const STRINGLIB_CHAR* str, Py_ssize_t str_len, |
65 | | PyObject* sep_obj, |
66 | | const STRINGLIB_CHAR* sep, Py_ssize_t sep_len) |
67 | 2.20k | { |
68 | 2.20k | PyObject* out; |
69 | 2.20k | Py_ssize_t pos; |
70 | | |
71 | 2.20k | if (sep_len == 0) { |
72 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); |
73 | 0 | return NULL; |
74 | 0 | } |
75 | | |
76 | 2.20k | out = PyTuple_New(3); |
77 | 2.20k | if (!out) |
78 | 0 | return NULL; |
79 | | |
80 | 2.20k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); |
81 | | |
82 | 2.20k | if (pos < 0) { |
83 | | #if STRINGLIB_MUTABLE |
84 | 0 | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0)); |
85 | 0 | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); |
86 | 0 | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len)); |
87 | | |
88 | 0 | if (PyErr_Occurred()) { |
89 | 0 | Py_DECREF(out); |
90 | 0 | return NULL; |
91 | 0 | } |
92 | | #else |
93 | 940 | Py_INCREF(STRINGLIB_EMPTY); |
94 | 940 | PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); |
95 | 940 | Py_INCREF(STRINGLIB_EMPTY); |
96 | 940 | PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); |
97 | 940 | Py_INCREF(str_obj); |
98 | 940 | PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); |
99 | | #endif |
100 | 0 | return out; |
101 | 940 | } |
102 | | |
103 | 1.26k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); |
104 | 1.26k | Py_INCREF(sep_obj); |
105 | 1.26k | PyTuple_SET_ITEM(out, 1, sep_obj); |
106 | 1.26k | pos += sep_len; |
107 | 1.26k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); |
108 | | |
109 | 1.26k | if (PyErr_Occurred()) { |
110 | 0 | Py_DECREF(out); |
111 | 0 | return NULL; |
112 | 0 | } |
113 | | |
114 | 1.26k | return out; |
115 | 1.26k | } Unexecuted instantiation: bytearrayobject.c:stringlib_rpartition Unexecuted instantiation: bytesobject.c:stringlib_rpartition unicodeobject.c:asciilib_rpartition Line | Count | Source | 67 | 2.20k | { | 68 | 2.20k | PyObject* out; | 69 | 2.20k | Py_ssize_t pos; | 70 | | | 71 | 2.20k | if (sep_len == 0) { | 72 | 0 | PyErr_SetString(PyExc_ValueError, "empty separator"); | 73 | 0 | return NULL; | 74 | 0 | } | 75 | | | 76 | 2.20k | out = PyTuple_New(3); | 77 | 2.20k | if (!out) | 78 | 0 | return NULL; | 79 | | | 80 | 2.20k | pos = FASTSEARCH(str, str_len, sep, sep_len, -1, FAST_RSEARCH); | 81 | | | 82 | 2.20k | if (pos < 0) { | 83 | | #if STRINGLIB_MUTABLE | 84 | | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(NULL, 0)); | 85 | | PyTuple_SET_ITEM(out, 1, STRINGLIB_NEW(NULL, 0)); | 86 | | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str, str_len)); | 87 | | | 88 | | if (PyErr_Occurred()) { | 89 | | Py_DECREF(out); | 90 | | return NULL; | 91 | | } | 92 | | #else | 93 | 940 | Py_INCREF(STRINGLIB_EMPTY); | 94 | 940 | PyTuple_SET_ITEM(out, 0, (PyObject*) STRINGLIB_EMPTY); | 95 | 940 | Py_INCREF(STRINGLIB_EMPTY); | 96 | 940 | PyTuple_SET_ITEM(out, 1, (PyObject*) STRINGLIB_EMPTY); | 97 | 940 | Py_INCREF(str_obj); | 98 | 940 | PyTuple_SET_ITEM(out, 2, (PyObject*) str_obj); | 99 | 940 | #endif | 100 | 940 | return out; | 101 | 940 | } | 102 | | | 103 | 1.26k | PyTuple_SET_ITEM(out, 0, STRINGLIB_NEW(str, pos)); | 104 | 1.26k | Py_INCREF(sep_obj); | 105 | 1.26k | PyTuple_SET_ITEM(out, 1, sep_obj); | 106 | 1.26k | pos += sep_len; | 107 | 1.26k | PyTuple_SET_ITEM(out, 2, STRINGLIB_NEW(str + pos, str_len - pos)); | 108 | | | 109 | 1.26k | if (PyErr_Occurred()) { | 110 | 0 | Py_DECREF(out); | 111 | 0 | return NULL; | 112 | 0 | } | 113 | | | 114 | 1.26k | return out; | 115 | 1.26k | } |
Unexecuted instantiation: unicodeobject.c:ucs1lib_rpartition Unexecuted instantiation: unicodeobject.c:ucs2lib_rpartition Unexecuted instantiation: unicodeobject.c:ucs4lib_rpartition |
116 | | |