Path: blob/main/Objects/stringlib/clinic/transmogrify.h.h
12 views
/*[clinic input]1preserve2[clinic start generated code]*/34#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)5# include "pycore_gc.h" // PyGC_Head6# include "pycore_runtime.h" // _Py_ID()7#endif8910PyDoc_STRVAR(stringlib_expandtabs__doc__,11"expandtabs($self, /, tabsize=8)\n"12"--\n"13"\n"14"Return a copy where all tab characters are expanded using spaces.\n"15"\n"16"If tabsize is not given, a tab size of 8 characters is assumed.");1718#define STRINGLIB_EXPANDTABS_METHODDEF \19{"expandtabs", _PyCFunction_CAST(stringlib_expandtabs), METH_FASTCALL|METH_KEYWORDS, stringlib_expandtabs__doc__},2021static PyObject *22stringlib_expandtabs_impl(PyObject *self, int tabsize);2324static PyObject *25stringlib_expandtabs(PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)26{27PyObject *return_value = NULL;28#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)2930#define NUM_KEYWORDS 131static struct {32PyGC_Head _this_is_not_used;33PyObject_VAR_HEAD34PyObject *ob_item[NUM_KEYWORDS];35} _kwtuple = {36.ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)37.ob_item = { &_Py_ID(tabsize), },38};39#undef NUM_KEYWORDS40#define KWTUPLE (&_kwtuple.ob_base.ob_base)4142#else // !Py_BUILD_CORE43# define KWTUPLE NULL44#endif // !Py_BUILD_CORE4546static const char * const _keywords[] = {"tabsize", NULL};47static _PyArg_Parser _parser = {48.keywords = _keywords,49.fname = "expandtabs",50.kwtuple = KWTUPLE,51};52#undef KWTUPLE53PyObject *argsbuf[1];54Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;55int tabsize = 8;5657args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);58if (!args) {59goto exit;60}61if (!noptargs) {62goto skip_optional_pos;63}64tabsize = _PyLong_AsInt(args[0]);65if (tabsize == -1 && PyErr_Occurred()) {66goto exit;67}68skip_optional_pos:69return_value = stringlib_expandtabs_impl(self, tabsize);7071exit:72return return_value;73}7475PyDoc_STRVAR(stringlib_ljust__doc__,76"ljust($self, width, fillchar=b\' \', /)\n"77"--\n"78"\n"79"Return a left-justified string of length width.\n"80"\n"81"Padding is done using the specified fill character.");8283#define STRINGLIB_LJUST_METHODDEF \84{"ljust", _PyCFunction_CAST(stringlib_ljust), METH_FASTCALL, stringlib_ljust__doc__},8586static PyObject *87stringlib_ljust_impl(PyObject *self, Py_ssize_t width, char fillchar);8889static PyObject *90stringlib_ljust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)91{92PyObject *return_value = NULL;93Py_ssize_t width;94char fillchar = ' ';9596if (!_PyArg_CheckPositional("ljust", nargs, 1, 2)) {97goto exit;98}99{100Py_ssize_t ival = -1;101PyObject *iobj = _PyNumber_Index(args[0]);102if (iobj != NULL) {103ival = PyLong_AsSsize_t(iobj);104Py_DECREF(iobj);105}106if (ival == -1 && PyErr_Occurred()) {107goto exit;108}109width = ival;110}111if (nargs < 2) {112goto skip_optional;113}114if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) {115fillchar = PyBytes_AS_STRING(args[1])[0];116}117else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) {118fillchar = PyByteArray_AS_STRING(args[1])[0];119}120else {121_PyArg_BadArgument("ljust", "argument 2", "a byte string of length 1", args[1]);122goto exit;123}124skip_optional:125return_value = stringlib_ljust_impl(self, width, fillchar);126127exit:128return return_value;129}130131PyDoc_STRVAR(stringlib_rjust__doc__,132"rjust($self, width, fillchar=b\' \', /)\n"133"--\n"134"\n"135"Return a right-justified string of length width.\n"136"\n"137"Padding is done using the specified fill character.");138139#define STRINGLIB_RJUST_METHODDEF \140{"rjust", _PyCFunction_CAST(stringlib_rjust), METH_FASTCALL, stringlib_rjust__doc__},141142static PyObject *143stringlib_rjust_impl(PyObject *self, Py_ssize_t width, char fillchar);144145static PyObject *146stringlib_rjust(PyObject *self, PyObject *const *args, Py_ssize_t nargs)147{148PyObject *return_value = NULL;149Py_ssize_t width;150char fillchar = ' ';151152if (!_PyArg_CheckPositional("rjust", nargs, 1, 2)) {153goto exit;154}155{156Py_ssize_t ival = -1;157PyObject *iobj = _PyNumber_Index(args[0]);158if (iobj != NULL) {159ival = PyLong_AsSsize_t(iobj);160Py_DECREF(iobj);161}162if (ival == -1 && PyErr_Occurred()) {163goto exit;164}165width = ival;166}167if (nargs < 2) {168goto skip_optional;169}170if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) {171fillchar = PyBytes_AS_STRING(args[1])[0];172}173else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) {174fillchar = PyByteArray_AS_STRING(args[1])[0];175}176else {177_PyArg_BadArgument("rjust", "argument 2", "a byte string of length 1", args[1]);178goto exit;179}180skip_optional:181return_value = stringlib_rjust_impl(self, width, fillchar);182183exit:184return return_value;185}186187PyDoc_STRVAR(stringlib_center__doc__,188"center($self, width, fillchar=b\' \', /)\n"189"--\n"190"\n"191"Return a centered string of length width.\n"192"\n"193"Padding is done using the specified fill character.");194195#define STRINGLIB_CENTER_METHODDEF \196{"center", _PyCFunction_CAST(stringlib_center), METH_FASTCALL, stringlib_center__doc__},197198static PyObject *199stringlib_center_impl(PyObject *self, Py_ssize_t width, char fillchar);200201static PyObject *202stringlib_center(PyObject *self, PyObject *const *args, Py_ssize_t nargs)203{204PyObject *return_value = NULL;205Py_ssize_t width;206char fillchar = ' ';207208if (!_PyArg_CheckPositional("center", nargs, 1, 2)) {209goto exit;210}211{212Py_ssize_t ival = -1;213PyObject *iobj = _PyNumber_Index(args[0]);214if (iobj != NULL) {215ival = PyLong_AsSsize_t(iobj);216Py_DECREF(iobj);217}218if (ival == -1 && PyErr_Occurred()) {219goto exit;220}221width = ival;222}223if (nargs < 2) {224goto skip_optional;225}226if (PyBytes_Check(args[1]) && PyBytes_GET_SIZE(args[1]) == 1) {227fillchar = PyBytes_AS_STRING(args[1])[0];228}229else if (PyByteArray_Check(args[1]) && PyByteArray_GET_SIZE(args[1]) == 1) {230fillchar = PyByteArray_AS_STRING(args[1])[0];231}232else {233_PyArg_BadArgument("center", "argument 2", "a byte string of length 1", args[1]);234goto exit;235}236skip_optional:237return_value = stringlib_center_impl(self, width, fillchar);238239exit:240return return_value;241}242243PyDoc_STRVAR(stringlib_zfill__doc__,244"zfill($self, width, /)\n"245"--\n"246"\n"247"Pad a numeric string with zeros on the left, to fill a field of the given width.\n"248"\n"249"The original string is never truncated.");250251#define STRINGLIB_ZFILL_METHODDEF \252{"zfill", (PyCFunction)stringlib_zfill, METH_O, stringlib_zfill__doc__},253254static PyObject *255stringlib_zfill_impl(PyObject *self, Py_ssize_t width);256257static PyObject *258stringlib_zfill(PyObject *self, PyObject *arg)259{260PyObject *return_value = NULL;261Py_ssize_t width;262263{264Py_ssize_t ival = -1;265PyObject *iobj = _PyNumber_Index(arg);266if (iobj != NULL) {267ival = PyLong_AsSsize_t(iobj);268Py_DECREF(iobj);269}270if (ival == -1 && PyErr_Occurred()) {271goto exit;272}273width = ival;274}275return_value = stringlib_zfill_impl(self, width);276277exit:278return return_value;279}280/*[clinic end generated code: output=d44a269805f6739e input=a9049054013a1b77]*/281282283