Skip to content

Commit c09a659

Browse files
[3.14] gh-141004: Document pyctype.h macros (GH-141272) (GH-141340)
gh-141004: Document `pyctype.h` macros (GH-141272) (cherry picked from commit df19261) Co-authored-by: Stan Ulbrych <[email protected]>
1 parent b5ae808 commit c09a659

File tree

3 files changed

+65
-12
lines changed

3 files changed

+65
-12
lines changed

Doc/c-api/conversion.rst

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,58 @@ The following functions provide locale-independent string to number conversions.
172172
173173
Case insensitive comparison of strings. The function works almost
174174
identically to :c:func:`!strncmp` except that it ignores the case.
175+
176+
177+
Character classification and conversion
178+
=======================================
179+
180+
The following macros provide locale-independent (unlike the C standard library
181+
``ctype.h``) character classification and conversion.
182+
The argument must be a signed or unsigned :c:expr:`char`.
183+
184+
185+
.. c:macro:: Py_ISALNUM(c)
186+
187+
Return true if the character *c* is an alphanumeric character.
188+
189+
190+
.. c:macro:: Py_ISALPHA(c)
191+
192+
Return true if the character *c* is an alphabetic character (``a-z`` and ``A-Z``).
193+
194+
195+
.. c:macro:: Py_ISDIGIT(c)
196+
197+
Return true if the character *c* is a decimal digit (``0-9``).
198+
199+
200+
.. c:macro:: Py_ISLOWER(c)
201+
202+
Return true if the character *c* is a lowercase ASCII letter (``a-z``).
203+
204+
205+
.. c:macro:: Py_ISUPPER(c)
206+
207+
Return true if the character *c* is an uppercase ASCII letter (``A-Z``).
208+
209+
210+
.. c:macro:: Py_ISSPACE(c)
211+
212+
Return true if the character *c* is a whitespace character (space, tab,
213+
carriage return, newline, vertical tab, or form feed).
214+
215+
216+
.. c:macro:: Py_ISXDIGIT(c)
217+
218+
Return true if the character *c* is a hexadecimal digit (``0-9``, ``a-f``, and
219+
``A-F``).
220+
221+
222+
.. c:macro:: Py_TOLOWER(c)
223+
224+
Return the lowercase equivalent of the character *c*.
225+
226+
227+
.. c:macro:: Py_TOUPPER(c)
228+
229+
Return the uppercase equivalent of the character *c*.

Doc/library/locale.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -517,8 +517,8 @@ The :mod:`locale` module defines the following exception and functions:
517517
SSH connections.
518518

519519
Python doesn't internally use locale-dependent character transformation functions
520-
from ``ctype.h``. Instead, an internal ``pyctype.h`` provides locale-independent
521-
equivalents like :c:macro:`!Py_TOLOWER`.
520+
from ``ctype.h``. Instead, ``pyctype.h`` provides locale-independent
521+
equivalents like :c:macro:`Py_TOLOWER`.
522522

523523

524524
.. data:: LC_COLLATE

Doc/whatsnew/2.7.rst

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,23 +2181,21 @@ Changes to Python's build process and to the C API include:
21812181
discussed in :issue:`5753`, and fixed by Antoine Pitrou.
21822182

21832183
* New macros: the Python header files now define the following macros:
2184-
:c:macro:`!Py_ISALNUM`,
2185-
:c:macro:`!Py_ISALPHA`,
2186-
:c:macro:`!Py_ISDIGIT`,
2187-
:c:macro:`!Py_ISLOWER`,
2188-
:c:macro:`!Py_ISSPACE`,
2189-
:c:macro:`!Py_ISUPPER`,
2190-
:c:macro:`!Py_ISXDIGIT`,
2191-
:c:macro:`!Py_TOLOWER`, and :c:macro:`!Py_TOUPPER`.
2184+
:c:macro:`Py_ISALNUM`,
2185+
:c:macro:`Py_ISALPHA`,
2186+
:c:macro:`Py_ISDIGIT`,
2187+
:c:macro:`Py_ISLOWER`,
2188+
:c:macro:`Py_ISSPACE`,
2189+
:c:macro:`Py_ISUPPER`,
2190+
:c:macro:`Py_ISXDIGIT`,
2191+
:c:macro:`Py_TOLOWER`, and :c:macro:`Py_TOUPPER`.
21922192
All of these functions are analogous to the C
21932193
standard macros for classifying characters, but ignore the current
21942194
locale setting, because in
21952195
several places Python needs to analyze characters in a
21962196
locale-independent way. (Added by Eric Smith;
21972197
:issue:`5793`.)
21982198

2199-
.. XXX these macros don't seem to be described in the c-api docs.
2200-
22012199
* Removed function: :c:func:`!PyEval_CallObject` is now only available
22022200
as a macro. A function version was being kept around to preserve
22032201
ABI linking compatibility, but that was in 1997; it can certainly be

0 commit comments

Comments
 (0)