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