/src/Python-3.8.3/Objects/stringlib/clinic/transmogrify.h.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*[clinic input] |
2 | | preserve |
3 | | [clinic start generated code]*/ |
4 | | |
5 | | PyDoc_STRVAR(stringlib_expandtabs__doc__, |
6 | | "expandtabs($self, /, tabsize=8)\n" |
7 | | "--\n" |
8 | | "\n" |
9 | | "Return a copy where all tab characters are expanded using spaces.\n" |
10 | | "\n" |
11 | | "If tabsize is not given, a tab size of 8 characters is assumed."); |
12 | | |
13 | | #define STRINGLIB_EXPANDTABS_METHODDEF \ |
14 | | {"expandtabs", (PyCFunction)(void(*)(void))stringlib_expandtabs, METH_FASTCALL|METH_KEYWORDS, stringlib_expandtabs__doc__}, |
15 | | |
16 | | static PyObject * |
17 | | stringlib_expandtabs_impl(PyObject *self, int tabsize); |
18 | | |
19 | | static PyObject * |
20 | | stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) |
21 | 0 | { |
22 | 0 | PyObject *return_value = NULL; |
23 | 0 | static const char * const _keywords[] = {"tabsize", NULL}; |
24 | 0 | static _PyArg_Parser _parser = {NULL, _keywords, "expandtabs", 0}; |
25 | 0 | PyObject *argsbuf[1]; |
26 | 0 | Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0; |
27 | 0 | int tabsize = 8; |
28 | |
|
29 | 0 | args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf); |
30 | 0 | if (!args) { |
31 | 0 | goto exit; |
32 | 0 | } |
33 | 0 | if (!noptargs) { |
34 | 0 | goto skip_optional_pos; |
35 | 0 | } |
36 | 0 | if (PyFloat_Check(args[0])) { |
37 | 0 | PyErr_SetString(PyExc_TypeError, |
38 | 0 | "integer argument expected, got float" ); |
39 | 0 | goto exit; |
40 | 0 | } |
41 | 0 | tabsize = _PyLong_AsInt(args[0]); |
42 | 0 | if (tabsize == -1 && PyErr_Occurred()) { |
43 | 0 | goto exit; |
44 | 0 | } |
45 | 0 | skip_optional_pos: |
46 | 0 | return_value = stringlib_expandtabs_impl(self, tabsize); |
47 | |
|
48 | 0 | exit: |
49 | 0 | return return_value; |
50 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_expandtabs Unexecuted instantiation: bytesobject.c:stringlib_expandtabs |
51 | | |
52 | | PyDoc_STRVAR(stringlib_ljust__doc__, |
53 | | "ljust($self, width, fillchar=b\' \', /)\n" |
54 | | "--\n" |
55 | | "\n" |
56 | | "Return a left-justified string of length width.\n" |
57 | | "\n" |
58 | | "Padding is done using the specified fill character."); |
59 | | |
60 | | #define STRINGLIB_LJUST_METHODDEF \ |
61 | | {"ljust", (PyCFunction)(void(*)(void))stringlib_ljust, METH_FASTCALL, stringlib_ljust__doc__}, |
62 | | |
63 | | static PyObject * |
64 | | stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar); |
65 | | |
66 | | static PyObject * |
67 | | stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
68 | 0 | { |
69 | 0 | PyObject *return_value = NULL; |
70 | 0 | Py_ssize_t width; |
71 | 0 | char fillchar = ' '; |
72 | |
|
73 | 0 | if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) { |
74 | 0 | goto exit; |
75 | 0 | } |
76 | 0 | if (PyFloat_Check(args[0])) { |
77 | 0 | PyErr_SetString(PyExc_TypeError, |
78 | 0 | "integer argument expected, got float" ); |
79 | 0 | goto exit; |
80 | 0 | } |
81 | 0 | { |
82 | 0 | Py_ssize_t ival = -1; |
83 | 0 | PyObject *iobj = PyNumber_Index(args[0]); |
84 | 0 | if (iobj != NULL) { |
85 | 0 | ival = PyLong_AsSsize_t(iobj); |
86 | 0 | Py_DECREF(iobj); |
87 | 0 | } |
88 | 0 | if (ival == -1 && PyErr_Occurred()) { |
89 | 0 | goto exit; |
90 | 0 | } |
91 | 0 | width = ival; |
92 | 0 | } |
93 | 0 | if (nargs < 2) { |
94 | 0 | goto skip_optional; |
95 | 0 | } |
96 | 0 | if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { |
97 | 0 | fillchar = PyBytes_AS_STRING(args[1])[0]; |
98 | 0 | } |
99 | 0 | else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { |
100 | 0 | fillchar = PyByteArray_AS_STRING(args[1])[0]; |
101 | 0 | } |
102 | 0 | else { |
103 | 0 | _PyArg_BadArgument("ljust", "argument 2", "a byte string of length 1", args[1]); |
104 | 0 | goto exit; |
105 | 0 | } |
106 | 0 | skip_optional: |
107 | 0 | return_value = stringlib_ljust_impl(self, width, fillchar); |
108 | |
|
109 | 0 | exit: |
110 | 0 | return return_value; |
111 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_ljust Unexecuted instantiation: bytesobject.c:stringlib_ljust |
112 | | |
113 | | PyDoc_STRVAR(stringlib_rjust__doc__, |
114 | | "rjust($self, width, fillchar=b\' \', /)\n" |
115 | | "--\n" |
116 | | "\n" |
117 | | "Return a right-justified string of length width.\n" |
118 | | "\n" |
119 | | "Padding is done using the specified fill character."); |
120 | | |
121 | | #define STRINGLIB_RJUST_METHODDEF \ |
122 | | {"rjust", (PyCFunction)(void(*)(void))stringlib_rjust, METH_FASTCALL, stringlib_rjust__doc__}, |
123 | | |
124 | | static PyObject * |
125 | | stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar); |
126 | | |
127 | | static PyObject * |
128 | | stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
129 | 0 | { |
130 | 0 | PyObject *return_value = NULL; |
131 | 0 | Py_ssize_t width; |
132 | 0 | char fillchar = ' '; |
133 | |
|
134 | 0 | if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) { |
135 | 0 | goto exit; |
136 | 0 | } |
137 | 0 | if (PyFloat_Check(args[0])) { |
138 | 0 | PyErr_SetString(PyExc_TypeError, |
139 | 0 | "integer argument expected, got float" ); |
140 | 0 | goto exit; |
141 | 0 | } |
142 | 0 | { |
143 | 0 | Py_ssize_t ival = -1; |
144 | 0 | PyObject *iobj = PyNumber_Index(args[0]); |
145 | 0 | if (iobj != NULL) { |
146 | 0 | ival = PyLong_AsSsize_t(iobj); |
147 | 0 | Py_DECREF(iobj); |
148 | 0 | } |
149 | 0 | if (ival == -1 && PyErr_Occurred()) { |
150 | 0 | goto exit; |
151 | 0 | } |
152 | 0 | width = ival; |
153 | 0 | } |
154 | 0 | if (nargs < 2) { |
155 | 0 | goto skip_optional; |
156 | 0 | } |
157 | 0 | if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { |
158 | 0 | fillchar = PyBytes_AS_STRING(args[1])[0]; |
159 | 0 | } |
160 | 0 | else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { |
161 | 0 | fillchar = PyByteArray_AS_STRING(args[1])[0]; |
162 | 0 | } |
163 | 0 | else { |
164 | 0 | _PyArg_BadArgument("rjust", "argument 2", "a byte string of length 1", args[1]); |
165 | 0 | goto exit; |
166 | 0 | } |
167 | 0 | skip_optional: |
168 | 0 | return_value = stringlib_rjust_impl(self, width, fillchar); |
169 | |
|
170 | 0 | exit: |
171 | 0 | return return_value; |
172 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_rjust Unexecuted instantiation: bytesobject.c:stringlib_rjust |
173 | | |
174 | | PyDoc_STRVAR(stringlib_center__doc__, |
175 | | "center($self, width, fillchar=b\' \', /)\n" |
176 | | "--\n" |
177 | | "\n" |
178 | | "Return a centered string of length width.\n" |
179 | | "\n" |
180 | | "Padding is done using the specified fill character."); |
181 | | |
182 | | #define STRINGLIB_CENTER_METHODDEF \ |
183 | | {"center", (PyCFunction)(void(*)(void))stringlib_center, METH_FASTCALL, stringlib_center__doc__}, |
184 | | |
185 | | static PyObject * |
186 | | stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar); |
187 | | |
188 | | static PyObject * |
189 | | stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs) |
190 | 0 | { |
191 | 0 | PyObject *return_value = NULL; |
192 | 0 | Py_ssize_t width; |
193 | 0 | char fillchar = ' '; |
194 | |
|
195 | 0 | if (!_PyArg_CheckPositional("center", nargs, 1, 2)) { |
196 | 0 | goto exit; |
197 | 0 | } |
198 | 0 | if (PyFloat_Check(args[0])) { |
199 | 0 | PyErr_SetString(PyExc_TypeError, |
200 | 0 | "integer argument expected, got float" ); |
201 | 0 | goto exit; |
202 | 0 | } |
203 | 0 | { |
204 | 0 | Py_ssize_t ival = -1; |
205 | 0 | PyObject *iobj = PyNumber_Index(args[0]); |
206 | 0 | if (iobj != NULL) { |
207 | 0 | ival = PyLong_AsSsize_t(iobj); |
208 | 0 | Py_DECREF(iobj); |
209 | 0 | } |
210 | 0 | if (ival == -1 && PyErr_Occurred()) { |
211 | 0 | goto exit; |
212 | 0 | } |
213 | 0 | width = ival; |
214 | 0 | } |
215 | 0 | if (nargs < 2) { |
216 | 0 | goto skip_optional; |
217 | 0 | } |
218 | 0 | if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) { |
219 | 0 | fillchar = PyBytes_AS_STRING(args[1])[0]; |
220 | 0 | } |
221 | 0 | else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) { |
222 | 0 | fillchar = PyByteArray_AS_STRING(args[1])[0]; |
223 | 0 | } |
224 | 0 | else { |
225 | 0 | _PyArg_BadArgument("center", "argument 2", "a byte string of length 1", args[1]); |
226 | 0 | goto exit; |
227 | 0 | } |
228 | 0 | skip_optional: |
229 | 0 | return_value = stringlib_center_impl(self, width, fillchar); |
230 | |
|
231 | 0 | exit: |
232 | 0 | return return_value; |
233 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_center Unexecuted instantiation: bytesobject.c:stringlib_center |
234 | | |
235 | | PyDoc_STRVAR(stringlib_zfill__doc__, |
236 | | "zfill($self, width, /)\n" |
237 | | "--\n" |
238 | | "\n" |
239 | | "Pad a numeric string with zeros on the left, to fill a field of the given width.\n" |
240 | | "\n" |
241 | | "The original string is never truncated."); |
242 | | |
243 | | #define STRINGLIB_ZFILL_METHODDEF \ |
244 | | {"zfill", (PyCFunction)stringlib_zfill, METH_O, stringlib_zfill__doc__}, |
245 | | |
246 | | static PyObject * |
247 | | stringlib_zfill_impl(PyObject *self, Py_ssize_t width); |
248 | | |
249 | | static PyObject * |
250 | | stringlib_zfill(PyObject *self, PyObject *arg) |
251 | 0 | { |
252 | 0 | PyObject *return_value = NULL; |
253 | 0 | Py_ssize_t width; |
254 | |
|
255 | 0 | if (PyFloat_Check(arg)) { |
256 | 0 | PyErr_SetString(PyExc_TypeError, |
257 | 0 | "integer argument expected, got float" ); |
258 | 0 | goto exit; |
259 | 0 | } |
260 | 0 | { |
261 | 0 | Py_ssize_t ival = -1; |
262 | 0 | PyObject *iobj = PyNumber_Index(arg); |
263 | 0 | if (iobj != NULL) { |
264 | 0 | ival = PyLong_AsSsize_t(iobj); |
265 | 0 | Py_DECREF(iobj); |
266 | 0 | } |
267 | 0 | if (ival == -1 && PyErr_Occurred()) { |
268 | 0 | goto exit; |
269 | 0 | } |
270 | 0 | width = ival; |
271 | 0 | } |
272 | 0 | return_value = stringlib_zfill_impl(self, width); |
273 | |
|
274 | 0 | exit: |
275 | 0 | return return_value; |
276 | 0 | } Unexecuted instantiation: bytearrayobject.c:stringlib_zfill Unexecuted instantiation: bytesobject.c:stringlib_zfill |
277 | | /*[clinic end generated code: output=15be047aef999b4e input=a9049054013a1b77]*/ |