annotate Objects/stringlib/find.h @ 47949:6c1237cb5aaa legacy-trunk

Re-word
author Andrew M. Kuchling <amk@amk.ca>
date Sun, 13 Jul 2008 21:43:25 +0000
parents 1fb353776dfb
children bce03f87f65d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
1 /* stringlib: find/index implementation */
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
2
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
3 #ifndef STRINGLIB_FIND_H
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
4 #define STRINGLIB_FIND_H
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
5
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
6 #ifndef STRINGLIB_FASTSEARCH_H
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
7 #error must include "stringlib/fastsearch.h" before including this module
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
8 #endif
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
9
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38424
diff changeset
10 Py_LOCAL_INLINE(Py_ssize_t)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
11 stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
12 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
13 Py_ssize_t offset)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
14 {
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
15 Py_ssize_t pos;
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
16
38514
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
17 if (sub_len == 0) {
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
18 if (str_len < 0)
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
19 return -1;
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
20 return offset;
38514
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
21 }
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
22
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
23 pos = fastsearch(str, str_len, sub, sub_len, FAST_SEARCH);
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
24
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
25 if (pos >= 0)
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
26 pos += offset;
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
27
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
28 return pos;
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
29 }
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
30
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38424
diff changeset
31 Py_LOCAL_INLINE(Py_ssize_t)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
32 stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
33 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
34 Py_ssize_t offset)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
35 {
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
36 /* XXX - create reversefastsearch helper! */
38514
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
37 if (sub_len == 0) {
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
38 if (str_len < 0)
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
39 return -1;
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
40 return str_len + offset;
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
41 } else {
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
42 Py_ssize_t j, pos = -1;
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
43 for (j = str_len - sub_len; j >= 0; --j)
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
44 if (STRINGLIB_CMP(str+j, sub, sub_len) == 0) {
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
45 pos = j + offset;
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
46 break;
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
47 }
38514
ecf7173e79ff changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents: 38441
diff changeset
48 return pos;
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
49 }
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
50 }
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
51
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
52 Py_LOCAL_INLINE(Py_ssize_t)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
53 stringlib_find_slice(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
54 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
55 Py_ssize_t start, Py_ssize_t end)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
56 {
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
57 if (start < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
58 start += str_len;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
59 if (start < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
60 start = 0;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
61 if (end > str_len)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
62 end = str_len;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
63 if (end < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
64 end += str_len;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
65 if (end < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
66 end = 0;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
67
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
68 return stringlib_find(
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
69 str + start, end - start,
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
70 sub, sub_len, start
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
71 );
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
72 }
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
73
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38424
diff changeset
74 Py_LOCAL_INLINE(Py_ssize_t)
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
75 stringlib_rfind_slice(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
76 const STRINGLIB_CHAR* sub, Py_ssize_t sub_len,
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
77 Py_ssize_t start, Py_ssize_t end)
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
78 {
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
79 if (start < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
80 start += str_len;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
81 if (start < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
82 start = 0;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
83 if (end > str_len)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
84 end = str_len;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
85 if (end < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
86 end += str_len;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
87 if (end < 0)
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
88 end = 0;
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
89
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
90 return stringlib_rfind(str + start, end - start, sub, sub_len, start);
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
91 }
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
92
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
93 #ifdef STRINGLIB_STR
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
94
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38424
diff changeset
95 Py_LOCAL_INLINE(int)
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
96 stringlib_contains_obj(PyObject* str, PyObject* sub)
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
97 {
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
98 return stringlib_find(
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
99 STRINGLIB_STR(str), STRINGLIB_LEN(str),
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
100 STRINGLIB_STR(sub), STRINGLIB_LEN(sub), 0
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
101 ) != -1;
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
102 }
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
103
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
104 #endif /* STRINGLIB_STR */
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
105
43888
1fb353776dfb Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents: 43887
diff changeset
106 #ifdef FROM_UNICODE
1fb353776dfb Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents: 43887
diff changeset
107
43886
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
108 /*
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
109 This function is a helper for the "find" family (find, rfind, index,
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
110 rindex) of unicodeobject.c file, because they all have the same
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
111 behaviour for the arguments.
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
112
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
113 It does not touch the variables received until it knows everything
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
114 is ok.
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
115
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
116 Note that we receive a pointer to the pointer of the substring object,
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
117 so when we create that object in this function we don't DECREF it,
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
118 because it continues living in the caller functions (those functions,
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
119 after finishing using the substring, must DECREF it).
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
120 */
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
121
43887
2df53f05392c Fix for stupid error (I need to remember to do a full 'make clean + make'
Facundo Batista <facundobatista@gmail.com>
parents: 43886
diff changeset
122 Py_LOCAL_INLINE(int)
43886
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
123 _ParseTupleFinds (PyObject *args, PyObject **substring,
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
124 Py_ssize_t *start, Py_ssize_t *end) {
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
125 PyObject *tmp_substring;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
126 Py_ssize_t tmp_start = 0;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
127 Py_ssize_t tmp_end = PY_SSIZE_T_MAX;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
128 PyObject *obj_start=Py_None, *obj_end=Py_None;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
129
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
130 if (!PyArg_ParseTuple(args, "O|OO:find", &tmp_substring,
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
131 &obj_start, &obj_end))
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
132 return 0;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
133
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
134 /* To support None in "start" and "end" arguments, meaning
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
135 the same as if they were not passed.
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
136 */
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
137 if (obj_start != Py_None)
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
138 if (!_PyEval_SliceIndex(obj_start, &tmp_start))
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
139 return 0;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
140 if (obj_end != Py_None)
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
141 if (!_PyEval_SliceIndex(obj_end, &tmp_end))
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
142 return 0;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
143
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
144 tmp_substring = PyUnicode_FromObject(tmp_substring);
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
145 if (!tmp_substring)
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
146 return 0;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
147
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
148 *start = tmp_start;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
149 *end = tmp_end;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
150 *substring = tmp_substring;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
151 return 1;
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
152 }
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
153
43888
1fb353776dfb Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents: 43887
diff changeset
154 #endif /* FROM_UNICODE */
43886
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
155
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
156 #endif /* STRINGLIB_FIND_H */
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
157
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
158 /*
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
159 Local variables:
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
160 c-basic-offset: 4
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
161 indent-tabs-mode: nil
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
162 End:
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
163 */