annotate Objects/stringlib/find.h @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 66f1d4a4c799
children b36cb4602e21
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
49308
304bea8731d2 #3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48826
diff changeset
17 if (str_len < 0)
304bea8731d2 #3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48826
diff changeset
18 return -1;
304bea8731d2 #3967: Correct a crash in count() and find() methods of string-like objects.
Amaury Forgeot d'Arc <amauryfa@gmail.com>
parents: 48826
diff changeset
19 if (sub_len == 0)
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
20 return offset;
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
21
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
22 pos = fastsearch(str, str_len, sub, sub_len, -1, FAST_SEARCH);
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
23
38404
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
24 if (pos >= 0)
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
25 pos += offset;
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
26
52f2c9f74f5a needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents: 38400
diff changeset
27 return pos;
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
28 }
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
29
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38424
diff changeset
30 Py_LOCAL_INLINE(Py_ssize_t)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
31 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
32 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
33 Py_ssize_t offset)
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
34 {
58090
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
35 Py_ssize_t pos;
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
36
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
37 if (str_len < 0)
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
38 return -1;
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
39 if (sub_len == 0)
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
40 return str_len + offset;
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
41
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
42 pos = fastsearch(str, str_len, sub, sub_len, -1, FAST_RSEARCH);
58090
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
43
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
44 if (pos >= 0)
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
45 pos += offset;
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
46
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
47 return pos;
38400
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
48 }
33c328896f52 needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff changeset
49
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
50 /* helper macro to fixup start/end slice values */
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
51 #define ADJUST_INDICES(start, end, len) \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
52 if (end > len) \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
53 end = len; \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
54 else if (end < 0) { \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
55 end += len; \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
56 if (end < 0) \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
57 end = 0; \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
58 } \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
59 if (start < 0) { \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
60 start += len; \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
61 if (start < 0) \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
62 start = 0; \
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
63 }
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
64
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
65 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
66 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
67 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
68 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
69 {
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
70 ADJUST_INDICES(start, end, str_len);
58090
ddf61cd775e0 Issue #7462: Implement the stringlib fast search algorithm for the `rfind`,
Antoine Pitrou <solipsis@pitrou.net>
parents: 49308
diff changeset
71 return stringlib_find(str + start, end - start, sub, sub_len, start);
38441
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 {
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
79 ADJUST_INDICES(start, end, str_len);
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
80 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
81 }
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
82
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
83 #ifdef STRINGLIB_WANT_CONTAINS_OBJ
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
84
38440
5b0753b9d16a needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents: 38424
diff changeset
85 Py_LOCAL_INLINE(int)
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
86 stringlib_contains_obj(PyObject* str, PyObject* sub)
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
87 {
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
88 return stringlib_find(
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
89 STRINGLIB_STR(str), STRINGLIB_LEN(str),
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
90 STRINGLIB_STR(sub), STRINGLIB_LEN(sub), 0
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
91 ) != -1;
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
92 }
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
93
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
94 #endif /* STRINGLIB_WANT_CONTAINS_OBJ */
38424
3d81faf47af7 needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents: 38404
diff changeset
95
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
96 #if STRINGLIB_IS_UNICODE
43888
1fb353776dfb Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents: 43887
diff changeset
97
43886
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
98 /*
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
99 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
100 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
101 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
102
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
103 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
104 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
105
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
106 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
107 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
108 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
109 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
110 */
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
111
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
112 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
113 _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
114 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
115 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
116 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
117 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
118 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
119
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
120 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
121 &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
122 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
123
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
124 /* 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
125 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
126 */
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
127 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
128 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
129 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
130 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
131 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
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 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
135 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
136 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
137
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
138 *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 *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
140 *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
141 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
142 }
25a5f6a30292 Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents: 38514
diff changeset
143
58288
66f1d4a4c799 Issue #7622: Improve the split(), rsplit(), splitlines() and replace()
Antoine Pitrou <solipsis@pitrou.net>
parents: 58090
diff changeset
144 #endif /* STRINGLIB_IS_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
145
38441
72327f8f4a79 needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents: 38440
diff changeset
146 #endif /* STRINGLIB_FIND_H */