summaryrefslogtreecommitdiff
path: root/Objects/stringlib/find.h
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2007-11-18 19:35:23 +0000
committerChristian Heimes <christian@cheimes.de>2007-11-18 19:35:23 +0000
commit9cd177526afc086a300b548588880329c32f607d (patch)
treee842c29c3f11a1bcd885863fa8ea90e40f155bc8 /Objects/stringlib/find.h
parent81ca7c784c4dd58dde691284321e3e220550a75c (diff)
downloadcpython-git-9cd177526afc086a300b548588880329c32f607d.tar.gz
Merged revisions 59005-59040 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk I've tried to fix test_cmd_line_script but I wasn't able to get all tests right. Nick, can you please have a look? ........ r59020 | facundo.batista | 2007-11-16 19:04:14 +0100 (Fri, 16 Nov 2007) | 12 lines Now in find, rfind, index, and rindex, you can use None as defaults, as usual with slicing (both with str and unicode strings). This fixes issue 1259. For str only the stringobject.c file was modified. But for unicode, I needed to repeat in the four functions a lot of code, so created a new function that does part of the job for them (and placed it in find.h, following a suggestion of Barry). Also added tests for this behaviour. ........ r59021 | facundo.batista | 2007-11-16 19:41:24 +0100 (Fri, 16 Nov 2007) | 4 lines Fix for stupid error (I need to remember to do a full 'make clean + make' cycle before the tests...). Sorry. ........ r59022 | facundo.batista | 2007-11-16 20:16:15 +0100 (Fri, 16 Nov 2007) | 3 lines Made _ParseTupleFinds only defined to unicodeobject.c ........ r59024 | raymond.hettinger | 2007-11-17 02:51:22 +0100 (Sat, 17 Nov 2007) | 1 line Fix signature in example ........ r59033 | brett.cannon | 2007-11-17 08:07:29 +0100 (Sat, 17 Nov 2007) | 5 lines Remove a confusing sentence about pth files and which directories are searched for them. Closes issue #1431. Thanks Giambattista Bloisi for the help. ........ r59039 | nick.coghlan | 2007-11-18 12:56:28 +0100 (Sun, 18 Nov 2007) | 1 line Patch #1739468: Directories and zipfiles containing __main__.py are now executable ........
Diffstat (limited to 'Objects/stringlib/find.h')
-rw-r--r--Objects/stringlib/find.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/Objects/stringlib/find.h b/Objects/stringlib/find.h
index 3b924b63f5..46337e1773 100644
--- a/Objects/stringlib/find.h
+++ b/Objects/stringlib/find.h
@@ -103,6 +103,56 @@ stringlib_contains_obj(PyObject* str, PyObject* sub)
#endif /* STRINGLIB_STR */
+#ifdef FROM_UNICODE
+
+/*
+This function is a helper for the "find" family (find, rfind, index,
+rindex) of unicodeobject.c file, because they all have the same
+behaviour for the arguments.
+
+It does not touch the variables received until it knows everything
+is ok.
+
+Note that we receive a pointer to the pointer of the substring object,
+so when we create that object in this function we don't DECREF it,
+because it continues living in the caller functions (those functions,
+after finishing using the substring, must DECREF it).
+*/
+
+Py_LOCAL_INLINE(int)
+_ParseTupleFinds (PyObject *args, PyObject **substring,
+ Py_ssize_t *start, Py_ssize_t *end) {
+ PyObject *tmp_substring;
+ Py_ssize_t tmp_start = 0;
+ Py_ssize_t tmp_end = PY_SSIZE_T_MAX;
+ PyObject *obj_start=Py_None, *obj_end=Py_None;
+
+ if (!PyArg_ParseTuple(args, "O|OO:find", &tmp_substring,
+ &obj_start, &obj_end))
+ return 0;
+
+ /* To support None in "start" and "end" arguments, meaning
+ the same as if they were not passed.
+ */
+ if (obj_start != Py_None)
+ if (!_PyEval_SliceIndex(obj_start, &tmp_start))
+ return 0;
+ if (obj_end != Py_None)
+ if (!_PyEval_SliceIndex(obj_end, &tmp_end))
+ return 0;
+
+ tmp_substring = PyUnicode_FromObject(tmp_substring);
+ if (!tmp_substring)
+ return 0;
+
+ *start = tmp_start;
+ *end = tmp_end;
+ *substring = tmp_substring;
+ return 1;
+}
+
+#endif /* FROM_UNICODE */
+
#endif /* STRINGLIB_FIND_H */
/*