1/*[clinic input] 2preserve 3[clinic start generated code]*/ 4 5PyDoc_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_CAST(stringlib_expandtabs), METH_FASTCALL|METH_KEYWORDS, stringlib_expandtabs__doc__}, 15 16static PyObject * 17stringlib_expandtabs_impl(PyObject *self, int tabsize); 18 19static PyObject * 20stringlib_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 } 40skip_optional_pos: 41 return_value = stringlib_expandtabs_impl(self, tabsize); 42 43exit: 44 return return_value; 45} 46 47PyDoc_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_CAST(stringlib_ljust), METH_FASTCALL, stringlib_ljust__doc__}, 57 58static PyObject * 59stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar); 60 61static PyObject * 62stringlib_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 } 96skip_optional: 97 return_value = stringlib_ljust_impl(self, width, fillchar); 98 99exit: 100 return return_value; 101} 102 103PyDoc_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_CAST(stringlib_rjust), METH_FASTCALL, stringlib_rjust__doc__}, 113 114static PyObject * 115stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar); 116 117static PyObject * 118stringlib_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 } 152skip_optional: 153 return_value = stringlib_rjust_impl(self, width, fillchar); 154 155exit: 156 return return_value; 157} 158 159PyDoc_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_CAST(stringlib_center), METH_FASTCALL, stringlib_center__doc__}, 169 170static PyObject * 171stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar); 172 173static PyObject * 174stringlib_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 } 208skip_optional: 209 return_value = stringlib_center_impl(self, width, fillchar); 210 211exit: 212 return return_value; 213} 214 215PyDoc_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 226static PyObject * 227stringlib_zfill_impl(PyObject *self, Py_ssize_t width); 228 229static PyObject * 230stringlib_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 249exit: 250 return return_value; 251} 252/*[clinic end generated code: output=46d058103bffedf7 input=a9049054013a1b77]*/ 253