|
19 | 19 | #include "Python.h" |
20 | 20 | #include "pycore_object.h" // _PyObject_VisitType() |
21 | 21 | #include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI |
| 22 | +#include "pycore_unicodectype.h" // _PyUnicode_IsXidStart() |
22 | 23 |
|
23 | 24 | #include <stdbool.h> |
24 | 25 | #include <stddef.h> // offsetof() |
@@ -1525,6 +1526,58 @@ unicodedata_UCD_name_impl(PyObject *self, int chr, PyObject *default_value) |
1525 | 1526 | return PyUnicode_FromString(name); |
1526 | 1527 | } |
1527 | 1528 |
|
| 1529 | +/*[clinic input] |
| 1530 | +unicodedata.UCD.isxidstart |
| 1531 | +
|
| 1532 | + self: self |
| 1533 | + chr: int(accept={str}) |
| 1534 | + / |
| 1535 | +
|
| 1536 | +Return True if the character has the XID_Start property, else False. |
| 1537 | +
|
| 1538 | +[clinic start generated code]*/ |
| 1539 | + |
| 1540 | +static PyObject * |
| 1541 | +unicodedata_UCD_isxidstart_impl(PyObject *self, int chr) |
| 1542 | +/*[clinic end generated code: output=944005823c72c3ef input=9353f88d709c21fb]*/ |
| 1543 | +{ |
| 1544 | + if (UCD_Check(self)) { |
| 1545 | + const change_record *old = get_old_record(self, chr); |
| 1546 | + if (old->category_changed == 0) { |
| 1547 | + /* unassigned */ |
| 1548 | + Py_RETURN_FALSE; |
| 1549 | + } |
| 1550 | + } |
| 1551 | + |
| 1552 | + return PyBool_FromLong(_PyUnicode_IsXidStart(chr)); |
| 1553 | +} |
| 1554 | + |
| 1555 | +/*[clinic input] |
| 1556 | +unicodedata.UCD.isxidcontinue |
| 1557 | +
|
| 1558 | + self: self |
| 1559 | + chr: int(accept={str}) |
| 1560 | + / |
| 1561 | +
|
| 1562 | +Return True if the character has the XID_Continue property, else False. |
| 1563 | +
|
| 1564 | +[clinic start generated code]*/ |
| 1565 | + |
| 1566 | +static PyObject * |
| 1567 | +unicodedata_UCD_isxidcontinue_impl(PyObject *self, int chr) |
| 1568 | +/*[clinic end generated code: output=9438dcbff5ca3e41 input=bbb8dd3ac0d2d709]*/ |
| 1569 | +{ |
| 1570 | + if (UCD_Check(self)) { |
| 1571 | + const change_record *old = get_old_record(self, chr); |
| 1572 | + if (old->category_changed == 0) { |
| 1573 | + /* unassigned */ |
| 1574 | + Py_RETURN_FALSE; |
| 1575 | + } |
| 1576 | + } |
| 1577 | + |
| 1578 | + return PyBool_FromLong(_PyUnicode_IsXidContinue(chr)); |
| 1579 | +} |
| 1580 | + |
1528 | 1581 | /*[clinic input] |
1529 | 1582 | unicodedata.UCD.lookup |
1530 | 1583 |
|
@@ -1590,6 +1643,8 @@ static PyMethodDef unicodedata_functions[] = { |
1590 | 1643 | UNICODEDATA_UCD_EAST_ASIAN_WIDTH_METHODDEF |
1591 | 1644 | UNICODEDATA_UCD_DECOMPOSITION_METHODDEF |
1592 | 1645 | UNICODEDATA_UCD_NAME_METHODDEF |
| 1646 | + UNICODEDATA_UCD_ISXIDSTART_METHODDEF |
| 1647 | + UNICODEDATA_UCD_ISXIDCONTINUE_METHODDEF |
1593 | 1648 | UNICODEDATA_UCD_LOOKUP_METHODDEF |
1594 | 1649 | UNICODEDATA_UCD_IS_NORMALIZED_METHODDEF |
1595 | 1650 | UNICODEDATA_UCD_NORMALIZE_METHODDEF |
|
0 commit comments