Mercurial > cpython-lru_cache-weakref
annotate Objects/stringlib/find.h @ 58925:eecf1bef052d 2.6
Merged revisions 78207 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r78207 | ezio.melotti | 2010-02-17 01:26:09 +0200 (Wed, 17 Feb 2010) | 1 line
#7930: fix stripid
........
| author | Ezio Melotti <ezio.melotti@gmail.com> |
|---|---|
| date | Tue, 16 Feb 2010 23:29:44 +0000 |
| parents | 304bea8731d2 |
| children | 787b969d37f0 ddf61cd775e0 |
| 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 |
|
52f2c9f74f5a
needforspeed: stringlib refactoring: use stringlib/find for string find
Fredrik Lundh <fredrik@pythonware.com>
parents:
38400
diff
changeset
|
22 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
|
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 { |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
35 /* 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
|
36 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
|
37 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
|
38 return -1; |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38441
diff
changeset
|
39 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
|
40 } else { |
|
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38441
diff
changeset
|
41 Py_ssize_t j, pos = -1; |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
42 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
|
43 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
|
44 pos = j + offset; |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
45 break; |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
46 } |
|
38514
ecf7173e79ff
changed find/rfind to return -1 for matches outside the source string
Fredrik Lundh <fredrik@pythonware.com>
parents:
38441
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 } |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
50 |
|
38441
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
51 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
|
52 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
|
53 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
|
54 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
|
55 { |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
56 if (start < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
57 start += str_len; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
58 if (start < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
59 start = 0; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
60 if (end > str_len) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
61 end = str_len; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
62 if (end < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
63 end += str_len; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
64 if (end < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
65 end = 0; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
66 |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
67 return stringlib_find( |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
68 str + start, end - start, |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
69 sub, sub_len, start |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
70 ); |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
71 } |
|
38424
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
72 |
|
38440
5b0753b9d16a
needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents:
38424
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 Py_ssize_t start, Py_ssize_t end) |
|
38424
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
77 { |
|
38441
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
78 if (start < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
79 start += str_len; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
80 if (start < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
81 start = 0; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
82 if (end > str_len) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
83 end = str_len; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
84 if (end < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
85 end += str_len; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
86 if (end < 0) |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
87 end = 0; |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
88 |
|
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
89 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
|
90 } |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
91 |
|
48826
bce03f87f65d
Silenced compiler warning
Christian Heimes <christian@cheimes.de>
parents:
43888
diff
changeset
|
92 #if defined(STRINGLIB_STR) && !defined(FROM_BYTEARRAY) |
|
38441
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
93 |
|
38440
5b0753b9d16a
needforspeed: replace improvements, changed to Py_LOCAL_INLINE
Fredrik Lundh <fredrik@pythonware.com>
parents:
38424
diff
changeset
|
94 Py_LOCAL_INLINE(int) |
|
38424
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
95 stringlib_contains_obj(PyObject* str, PyObject* sub) |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
96 { |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
97 return stringlib_find( |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
98 STRINGLIB_STR(str), STRINGLIB_LEN(str), |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
99 STRINGLIB_STR(sub), STRINGLIB_LEN(sub), 0 |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
100 ) != -1; |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
101 } |
|
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
102 |
|
38441
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
103 #endif /* STRINGLIB_STR */ |
|
38424
3d81faf47af7
needforspeed: more stringlib refactoring
Fredrik Lundh <fredrik@pythonware.com>
parents:
38404
diff
changeset
|
104 |
|
43888
1fb353776dfb
Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents:
43887
diff
changeset
|
105 #ifdef FROM_UNICODE |
|
1fb353776dfb
Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents:
43887
diff
changeset
|
106 |
|
43886
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
107 /* |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
108 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
|
109 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
|
110 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
|
111 |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
112 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
|
113 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
|
114 |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
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 |
|
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
|
121 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
|
122 _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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
129 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
|
130 &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
|
131 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
|
132 |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
133 /* 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
|
134 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
|
135 */ |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
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 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
|
144 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
|
145 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
|
146 |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
147 *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
|
148 *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
|
149 *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
|
150 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
|
151 } |
|
25a5f6a30292
Now in find, rfind, index, and rindex, you can use None as defaults,
Facundo Batista <facundobatista@gmail.com>
parents:
38514
diff
changeset
|
152 |
|
43888
1fb353776dfb
Made _ParseTupleFinds only defined to unicodeobject.c
Facundo Batista <facundobatista@gmail.com>
parents:
43887
diff
changeset
|
153 #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
|
154 |
|
38441
72327f8f4a79
needforspeed: stringlib refactoring: changed find_obj to find_slice,
Fredrik Lundh <fredrik@pythonware.com>
parents:
38440
diff
changeset
|
155 #endif /* STRINGLIB_FIND_H */ |
|
38400
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
156 |
|
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 Local variables: |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
159 c-basic-offset: 4 |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
160 indent-tabs-mode: nil |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
161 End: |
|
33c328896f52
needforspeed: stringlib refactoring, continued. added count and
Fredrik Lundh <fredrik@pythonware.com>
parents:
diff
changeset
|
162 */ |
