(root)/
Python-3.12.0/
Modules/
clinic/
unicodedata.c.h
       1  /*[clinic input]
       2  preserve
       3  [clinic start generated code]*/
       4  
       5  #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
       6  #  include "pycore_gc.h"            // PyGC_Head
       7  #  include "pycore_runtime.h"       // _Py_ID()
       8  #endif
       9  
      10  
      11  PyDoc_STRVAR(unicodedata_UCD_decimal__doc__,
      12  "decimal($self, chr, default=<unrepresentable>, /)\n"
      13  "--\n"
      14  "\n"
      15  "Converts a Unicode character into its equivalent decimal value.\n"
      16  "\n"
      17  "Returns the decimal value assigned to the character chr as integer.\n"
      18  "If no such value is defined, default is returned, or, if not given,\n"
      19  "ValueError is raised.");
      20  
      21  #define UNICODEDATA_UCD_DECIMAL_METHODDEF    \
      22      {"decimal", _PyCFunction_CAST(unicodedata_UCD_decimal), METH_FASTCALL, unicodedata_UCD_decimal__doc__},
      23  
      24  static PyObject *
      25  unicodedata_UCD_decimal_impl(PyObject *self, int chr,
      26                               PyObject *default_value);
      27  
      28  static PyObject *
      29  unicodedata_UCD_decimal(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
      30  {
      31      PyObject *return_value = NULL;
      32      int chr;
      33      PyObject *default_value = NULL;
      34  
      35      if (!_PyArg_CheckPositional("decimal", nargs, 1, 2)) {
      36          goto exit;
      37      }
      38      if (!PyUnicode_Check(args[0])) {
      39          _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
      40          goto exit;
      41      }
      42      if (PyUnicode_READY(args[0])) {
      43          goto exit;
      44      }
      45      if (PyUnicode_GET_LENGTH(args[0]) != 1) {
      46          _PyArg_BadArgument("decimal", "argument 1", "a unicode character", args[0]);
      47          goto exit;
      48      }
      49      chr = PyUnicode_READ_CHAR(args[0], 0);
      50      if (nargs < 2) {
      51          goto skip_optional;
      52      }
      53      default_value = args[1];
      54  skip_optional:
      55      return_value = unicodedata_UCD_decimal_impl(self, chr, default_value);
      56  
      57  exit:
      58      return return_value;
      59  }
      60  
      61  PyDoc_STRVAR(unicodedata_UCD_digit__doc__,
      62  "digit($self, chr, default=<unrepresentable>, /)\n"
      63  "--\n"
      64  "\n"
      65  "Converts a Unicode character into its equivalent digit value.\n"
      66  "\n"
      67  "Returns the digit value assigned to the character chr as integer.\n"
      68  "If no such value is defined, default is returned, or, if not given,\n"
      69  "ValueError is raised.");
      70  
      71  #define UNICODEDATA_UCD_DIGIT_METHODDEF    \
      72      {"digit", _PyCFunction_CAST(unicodedata_UCD_digit), METH_FASTCALL, unicodedata_UCD_digit__doc__},
      73  
      74  static PyObject *
      75  unicodedata_UCD_digit_impl(PyObject *self, int chr, PyObject *default_value);
      76  
      77  static PyObject *
      78  unicodedata_UCD_digit(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
      79  {
      80      PyObject *return_value = NULL;
      81      int chr;
      82      PyObject *default_value = NULL;
      83  
      84      if (!_PyArg_CheckPositional("digit", nargs, 1, 2)) {
      85          goto exit;
      86      }
      87      if (!PyUnicode_Check(args[0])) {
      88          _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
      89          goto exit;
      90      }
      91      if (PyUnicode_READY(args[0])) {
      92          goto exit;
      93      }
      94      if (PyUnicode_GET_LENGTH(args[0]) != 1) {
      95          _PyArg_BadArgument("digit", "argument 1", "a unicode character", args[0]);
      96          goto exit;
      97      }
      98      chr = PyUnicode_READ_CHAR(args[0], 0);
      99      if (nargs < 2) {
     100          goto skip_optional;
     101      }
     102      default_value = args[1];
     103  skip_optional:
     104      return_value = unicodedata_UCD_digit_impl(self, chr, default_value);
     105  
     106  exit:
     107      return return_value;
     108  }
     109  
     110  PyDoc_STRVAR(unicodedata_UCD_numeric__doc__,
     111  "numeric($self, chr, default=<unrepresentable>, /)\n"
     112  "--\n"
     113  "\n"
     114  "Converts a Unicode character into its equivalent numeric value.\n"
     115  "\n"
     116  "Returns the numeric value assigned to the character chr as float.\n"
     117  "If no such value is defined, default is returned, or, if not given,\n"
     118  "ValueError is raised.");
     119  
     120  #define UNICODEDATA_UCD_NUMERIC_METHODDEF    \
     121      {"numeric", _PyCFunction_CAST(unicodedata_UCD_numeric), METH_FASTCALL, unicodedata_UCD_numeric__doc__},
     122  
     123  static PyObject *
     124  unicodedata_UCD_numeric_impl(PyObject *self, int chr,
     125                               PyObject *default_value);
     126  
     127  static PyObject *
     128  unicodedata_UCD_numeric(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
     129  {
     130      PyObject *return_value = NULL;
     131      int chr;
     132      PyObject *default_value = NULL;
     133  
     134      if (!_PyArg_CheckPositional("numeric", nargs, 1, 2)) {
     135          goto exit;
     136      }
     137      if (!PyUnicode_Check(args[0])) {
     138          _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
     139          goto exit;
     140      }
     141      if (PyUnicode_READY(args[0])) {
     142          goto exit;
     143      }
     144      if (PyUnicode_GET_LENGTH(args[0]) != 1) {
     145          _PyArg_BadArgument("numeric", "argument 1", "a unicode character", args[0]);
     146          goto exit;
     147      }
     148      chr = PyUnicode_READ_CHAR(args[0], 0);
     149      if (nargs < 2) {
     150          goto skip_optional;
     151      }
     152      default_value = args[1];
     153  skip_optional:
     154      return_value = unicodedata_UCD_numeric_impl(self, chr, default_value);
     155  
     156  exit:
     157      return return_value;
     158  }
     159  
     160  PyDoc_STRVAR(unicodedata_UCD_category__doc__,
     161  "category($self, chr, /)\n"
     162  "--\n"
     163  "\n"
     164  "Returns the general category assigned to the character chr as string.");
     165  
     166  #define UNICODEDATA_UCD_CATEGORY_METHODDEF    \
     167      {"category", (PyCFunction)unicodedata_UCD_category, METH_O, unicodedata_UCD_category__doc__},
     168  
     169  static PyObject *
     170  unicodedata_UCD_category_impl(PyObject *self, int chr);
     171  
     172  static PyObject *
     173  unicodedata_UCD_category(PyObject *self, PyObject *arg)
     174  {
     175      PyObject *return_value = NULL;
     176      int chr;
     177  
     178      if (!PyUnicode_Check(arg)) {
     179          _PyArg_BadArgument("category", "argument", "a unicode character", arg);
     180          goto exit;
     181      }
     182      if (PyUnicode_READY(arg)) {
     183          goto exit;
     184      }
     185      if (PyUnicode_GET_LENGTH(arg) != 1) {
     186          _PyArg_BadArgument("category", "argument", "a unicode character", arg);
     187          goto exit;
     188      }
     189      chr = PyUnicode_READ_CHAR(arg, 0);
     190      return_value = unicodedata_UCD_category_impl(self, chr);
     191  
     192  exit:
     193      return return_value;
     194  }
     195  
     196  PyDoc_STRVAR(unicodedata_UCD_bidirectional__doc__,
     197  "bidirectional($self, chr, /)\n"
     198  "--\n"
     199  "\n"
     200  "Returns the bidirectional class assigned to the character chr as string.\n"
     201  "\n"
     202  "If no such value is defined, an empty string is returned.");
     203  
     204  #define UNICODEDATA_UCD_BIDIRECTIONAL_METHODDEF    \
     205      {"bidirectional", (PyCFunction)unicodedata_UCD_bidirectional, METH_O, unicodedata_UCD_bidirectional__doc__},
     206  
     207  static PyObject *
     208  unicodedata_UCD_bidirectional_impl(PyObject *self, int chr);
     209  
     210  static PyObject *
     211  unicodedata_UCD_bidirectional(PyObject *self, PyObject *arg)
     212  {
     213      PyObject *return_value = NULL;
     214      int chr;
     215  
     216      if (!PyUnicode_Check(arg)) {
     217          _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
     218          goto exit;
     219      }
     220      if (PyUnicode_READY(arg)) {
     221          goto exit;
     222      }
     223      if (PyUnicode_GET_LENGTH(arg) != 1) {
     224          _PyArg_BadArgument("bidirectional", "argument", "a unicode character", arg);
     225          goto exit;
     226      }
     227      chr = PyUnicode_READ_CHAR(arg, 0);
     228      return_value = unicodedata_UCD_bidirectional_impl(self, chr);
     229  
     230  exit:
     231      return return_value;
     232  }
     233  
     234  PyDoc_STRVAR(unicodedata_UCD_combining__doc__,
     235  "combining($self, chr, /)\n"
     236  "--\n"
     237  "\n"
     238  "Returns the canonical combining class assigned to the character chr as integer.\n"
     239  "\n"
     240  "Returns 0 if no combining class is defined.");
     241  
     242  #define UNICODEDATA_UCD_COMBINING_METHODDEF    \
     243      {"combining", (PyCFunction)unicodedata_UCD_combining, METH_O, unicodedata_UCD_combining__doc__},
     244  
     245  static int
     246  unicodedata_UCD_combining_impl(PyObject *self, int chr);
     247  
     248  static PyObject *
     249  unicodedata_UCD_combining(PyObject *self, PyObject *arg)
     250  {
     251      PyObject *return_value = NULL;
     252      int chr;
     253      int _return_value;
     254  
     255      if (!PyUnicode_Check(arg)) {
     256          _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
     257          goto exit;
     258      }
     259      if (PyUnicode_READY(arg)) {
     260          goto exit;
     261      }
     262      if (PyUnicode_GET_LENGTH(arg) != 1) {
     263          _PyArg_BadArgument("combining", "argument", "a unicode character", arg);
     264          goto exit;
     265      }
     266      chr = PyUnicode_READ_CHAR(arg, 0);
     267      _return_value = unicodedata_UCD_combining_impl(self, chr);
     268      if ((_return_value == -1) && PyErr_Occurred()) {
     269          goto exit;
     270      }
     271      return_value = PyLong_FromLong((long)_return_value);
     272  
     273  exit:
     274      return return_value;
     275  }
     276  
     277  PyDoc_STRVAR(unicodedata_UCD_mirrored__doc__,
     278  "mirrored($self, chr, /)\n"
     279  "--\n"
     280  "\n"
     281  "Returns the mirrored property assigned to the character chr as integer.\n"
     282  "\n"
     283  "Returns 1 if the character has been identified as a \"mirrored\"\n"
     284  "character in bidirectional text, 0 otherwise.");
     285  
     286  #define UNICODEDATA_UCD_MIRRORED_METHODDEF    \
     287      {"mirrored", (PyCFunction)unicodedata_UCD_mirrored, METH_O, unicodedata_UCD_mirrored__doc__},
     288  
     289  static int
     290  unicodedata_UCD_mirrored_impl(PyObject *self, int chr);
     291  
     292  static PyObject *
     293  unicodedata_UCD_mirrored(PyObject *self, PyObject *arg)
     294  {
     295      PyObject *return_value = NULL;
     296      int chr;
     297      int _return_value;
     298  
     299      if (!PyUnicode_Check(arg)) {
     300          _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
     301          goto exit;
     302      }
     303      if (PyUnicode_READY(arg)) {
     304          goto exit;
     305      }
     306      if (PyUnicode_GET_LENGTH(arg) != 1) {
     307          _PyArg_BadArgument("mirrored", "argument", "a unicode character", arg);
     308          goto exit;
     309      }
     310      chr = PyUnicode_READ_CHAR(arg, 0);
     311      _return_value = unicodedata_UCD_mirrored_impl(self, chr);
     312      if ((_return_value == -1) && PyErr_Occurred()) {
     313          goto exit;
     314      }
     315      return_value = PyLong_FromLong((long)_return_value);
     316  
     317  exit:
     318      return return_value;
     319  }
     320  
     321  PyDoc_STRVAR(unicodedata_UCD_east_asian_width__doc__,
     322  "east_asian_width($self, chr, /)\n"
     323  "--\n"
     324  "\n"
     325  "Returns the east asian width assigned to the character chr as string.");
     326  
     327  #define UNICODEDATA_UCD_EAST_ASIAN_WIDTH_METHODDEF    \
     328      {"east_asian_width", (PyCFunction)unicodedata_UCD_east_asian_width, METH_O, unicodedata_UCD_east_asian_width__doc__},
     329  
     330  static PyObject *
     331  unicodedata_UCD_east_asian_width_impl(PyObject *self, int chr);
     332  
     333  static PyObject *
     334  unicodedata_UCD_east_asian_width(PyObject *self, PyObject *arg)
     335  {
     336      PyObject *return_value = NULL;
     337      int chr;
     338  
     339      if (!PyUnicode_Check(arg)) {
     340          _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
     341          goto exit;
     342      }
     343      if (PyUnicode_READY(arg)) {
     344          goto exit;
     345      }
     346      if (PyUnicode_GET_LENGTH(arg) != 1) {
     347          _PyArg_BadArgument("east_asian_width", "argument", "a unicode character", arg);
     348          goto exit;
     349      }
     350      chr = PyUnicode_READ_CHAR(arg, 0);
     351      return_value = unicodedata_UCD_east_asian_width_impl(self, chr);
     352  
     353  exit:
     354      return return_value;
     355  }
     356  
     357  PyDoc_STRVAR(unicodedata_UCD_decomposition__doc__,
     358  "decomposition($self, chr, /)\n"
     359  "--\n"
     360  "\n"
     361  "Returns the character decomposition mapping assigned to the character chr as string.\n"
     362  "\n"
     363  "An empty string is returned in case no such mapping is defined.");
     364  
     365  #define UNICODEDATA_UCD_DECOMPOSITION_METHODDEF    \
     366      {"decomposition", (PyCFunction)unicodedata_UCD_decomposition, METH_O, unicodedata_UCD_decomposition__doc__},
     367  
     368  static PyObject *
     369  unicodedata_UCD_decomposition_impl(PyObject *self, int chr);
     370  
     371  static PyObject *
     372  unicodedata_UCD_decomposition(PyObject *self, PyObject *arg)
     373  {
     374      PyObject *return_value = NULL;
     375      int chr;
     376  
     377      if (!PyUnicode_Check(arg)) {
     378          _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
     379          goto exit;
     380      }
     381      if (PyUnicode_READY(arg)) {
     382          goto exit;
     383      }
     384      if (PyUnicode_GET_LENGTH(arg) != 1) {
     385          _PyArg_BadArgument("decomposition", "argument", "a unicode character", arg);
     386          goto exit;
     387      }
     388      chr = PyUnicode_READ_CHAR(arg, 0);
     389      return_value = unicodedata_UCD_decomposition_impl(self, chr);
     390  
     391  exit:
     392      return return_value;
     393  }
     394  
     395  PyDoc_STRVAR(unicodedata_UCD_is_normalized__doc__,
     396  "is_normalized($self, form, unistr, /)\n"
     397  "--\n"
     398  "\n"
     399  "Return whether the Unicode string unistr is in the normal form \'form\'.\n"
     400  "\n"
     401  "Valid values for form are \'NFC\', \'NFKC\', \'NFD\', and \'NFKD\'.");
     402  
     403  #define UNICODEDATA_UCD_IS_NORMALIZED_METHODDEF    \
     404      {"is_normalized", _PyCFunction_CAST(unicodedata_UCD_is_normalized), METH_FASTCALL, unicodedata_UCD_is_normalized__doc__},
     405  
     406  static PyObject *
     407  unicodedata_UCD_is_normalized_impl(PyObject *self, PyObject *form,
     408                                     PyObject *input);
     409  
     410  static PyObject *
     411  unicodedata_UCD_is_normalized(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
     412  {
     413      PyObject *return_value = NULL;
     414      PyObject *form;
     415      PyObject *input;
     416  
     417      if (!_PyArg_CheckPositional("is_normalized", nargs, 2, 2)) {
     418          goto exit;
     419      }
     420      if (!PyUnicode_Check(args[0])) {
     421          _PyArg_BadArgument("is_normalized", "argument 1", "str", args[0]);
     422          goto exit;
     423      }
     424      if (PyUnicode_READY(args[0]) == -1) {
     425          goto exit;
     426      }
     427      form = args[0];
     428      if (!PyUnicode_Check(args[1])) {
     429          _PyArg_BadArgument("is_normalized", "argument 2", "str", args[1]);
     430          goto exit;
     431      }
     432      if (PyUnicode_READY(args[1]) == -1) {
     433          goto exit;
     434      }
     435      input = args[1];
     436      return_value = unicodedata_UCD_is_normalized_impl(self, form, input);
     437  
     438  exit:
     439      return return_value;
     440  }
     441  
     442  PyDoc_STRVAR(unicodedata_UCD_normalize__doc__,
     443  "normalize($self, form, unistr, /)\n"
     444  "--\n"
     445  "\n"
     446  "Return the normal form \'form\' for the Unicode string unistr.\n"
     447  "\n"
     448  "Valid values for form are \'NFC\', \'NFKC\', \'NFD\', and \'NFKD\'.");
     449  
     450  #define UNICODEDATA_UCD_NORMALIZE_METHODDEF    \
     451      {"normalize", _PyCFunction_CAST(unicodedata_UCD_normalize), METH_FASTCALL, unicodedata_UCD_normalize__doc__},
     452  
     453  static PyObject *
     454  unicodedata_UCD_normalize_impl(PyObject *self, PyObject *form,
     455                                 PyObject *input);
     456  
     457  static PyObject *
     458  unicodedata_UCD_normalize(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
     459  {
     460      PyObject *return_value = NULL;
     461      PyObject *form;
     462      PyObject *input;
     463  
     464      if (!_PyArg_CheckPositional("normalize", nargs, 2, 2)) {
     465          goto exit;
     466      }
     467      if (!PyUnicode_Check(args[0])) {
     468          _PyArg_BadArgument("normalize", "argument 1", "str", args[0]);
     469          goto exit;
     470      }
     471      if (PyUnicode_READY(args[0]) == -1) {
     472          goto exit;
     473      }
     474      form = args[0];
     475      if (!PyUnicode_Check(args[1])) {
     476          _PyArg_BadArgument("normalize", "argument 2", "str", args[1]);
     477          goto exit;
     478      }
     479      if (PyUnicode_READY(args[1]) == -1) {
     480          goto exit;
     481      }
     482      input = args[1];
     483      return_value = unicodedata_UCD_normalize_impl(self, form, input);
     484  
     485  exit:
     486      return return_value;
     487  }
     488  
     489  PyDoc_STRVAR(unicodedata_UCD_name__doc__,
     490  "name($self, chr, default=<unrepresentable>, /)\n"
     491  "--\n"
     492  "\n"
     493  "Returns the name assigned to the character chr as a string.\n"
     494  "\n"
     495  "If no name is defined, default is returned, or, if not given,\n"
     496  "ValueError is raised.");
     497  
     498  #define UNICODEDATA_UCD_NAME_METHODDEF    \
     499      {"name", _PyCFunction_CAST(unicodedata_UCD_name), METH_FASTCALL, unicodedata_UCD_name__doc__},
     500  
     501  static PyObject *
     502  unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value);
     503  
     504  static PyObject *
     505  unicodedata_UCD_name(PyObject *self, PyObject *const *args, Py_ssize_t nargs)
     506  {
     507      PyObject *return_value = NULL;
     508      int chr;
     509      PyObject *default_value = NULL;
     510  
     511      if (!_PyArg_CheckPositional("name", nargs, 1, 2)) {
     512          goto exit;
     513      }
     514      if (!PyUnicode_Check(args[0])) {
     515          _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
     516          goto exit;
     517      }
     518      if (PyUnicode_READY(args[0])) {
     519          goto exit;
     520      }
     521      if (PyUnicode_GET_LENGTH(args[0]) != 1) {
     522          _PyArg_BadArgument("name", "argument 1", "a unicode character", args[0]);
     523          goto exit;
     524      }
     525      chr = PyUnicode_READ_CHAR(args[0], 0);
     526      if (nargs < 2) {
     527          goto skip_optional;
     528      }
     529      default_value = args[1];
     530  skip_optional:
     531      return_value = unicodedata_UCD_name_impl(self, chr, default_value);
     532  
     533  exit:
     534      return return_value;
     535  }
     536  
     537  PyDoc_STRVAR(unicodedata_UCD_lookup__doc__,
     538  "lookup($self, name, /)\n"
     539  "--\n"
     540  "\n"
     541  "Look up character by name.\n"
     542  "\n"
     543  "If a character with the given name is found, return the\n"
     544  "corresponding character.  If not found, KeyError is raised.");
     545  
     546  #define UNICODEDATA_UCD_LOOKUP_METHODDEF    \
     547      {"lookup", (PyCFunction)unicodedata_UCD_lookup, METH_O, unicodedata_UCD_lookup__doc__},
     548  
     549  static PyObject *
     550  unicodedata_UCD_lookup_impl(PyObject *self, const char *name,
     551                              Py_ssize_t name_length);
     552  
     553  static PyObject *
     554  unicodedata_UCD_lookup(PyObject *self, PyObject *arg)
     555  {
     556      PyObject *return_value = NULL;
     557      const char *name;
     558      Py_ssize_t name_length;
     559  
     560      if (!PyArg_Parse(arg, "s#:lookup", &name, &name_length)) {
     561          goto exit;
     562      }
     563      return_value = unicodedata_UCD_lookup_impl(self, name, name_length);
     564  
     565  exit:
     566      return return_value;
     567  }
     568  /*[clinic end generated code: output=aaf601d28b352353 input=a9049054013a1b77]*/