summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2012-01-03 23:33:50 (GMT)
committerVictor Stinner <victor.stinner@haypocalc.com>2012-01-03 23:33:50 (GMT)
commit3fe553160c785f76ca908500a7531fceb2176203 (patch)
tree92adb3edbe5e192bc48bf8b69a4c234f4d1f27b6 /Objects/unicodeobject.c
parent332503db07ab5f8c2dea301a7ec9b8f7d4f1152f (diff)
downloadcpython-3fe553160c785f76ca908500a7531fceb2176203.zip
cpython-3fe553160c785f76ca908500a7531fceb2176203.tar.gz
cpython-3fe553160c785f76ca908500a7531fceb2176203.tar.bz2
Add a new PyUnicode_Fill() function
It is faster than the unicode_fill() function which was implemented in formatter_unicode.c.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 9a9703a..5ca2c53 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -9818,6 +9818,41 @@ PyUnicode_Join(PyObject *separator, PyObject *seq)
} \
} while (0)
+Py_ssize_t
+PyUnicode_Fill(PyObject *unicode, Py_ssize_t start, Py_ssize_t length,
+ Py_UCS4 fill_char)
+{
+ Py_ssize_t maxlen;
+ enum PyUnicode_Kind kind;
+ void *data;
+
+ if (!PyUnicode_Check(unicode)) {
+ PyErr_BadInternalCall();
+ return -1;
+ }
+ if (PyUnicode_READY(unicode) == -1)
+ return -1;
+ if (unicode_check_modifiable(unicode))
+ return -1;
+
+ if (fill_char > PyUnicode_MAX_CHAR_VALUE(unicode)) {
+ PyErr_SetString(PyExc_ValueError,
+ "fill character is bigger than "
+ "the string maximum character");
+ return -1;
+ }
+
+ maxlen = PyUnicode_GET_LENGTH(unicode) - start;
+ length = Py_MIN(maxlen, length);
+ if (length <= 0)
+ return 0;
+
+ kind = PyUnicode_KIND(unicode);
+ data = PyUnicode_DATA(unicode);
+ FILL(kind, data, fill_char, start, length);
+ return length;
+}
+
static PyObject *
pad(PyObject *self,
Py_ssize_t left,