Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/cpython
Path: blob/main/Objects/stringlib/ctype.h
12 views
1
#if STRINGLIB_IS_UNICODE
2
# error "ctype.h only compatible with byte-wise strings"
3
#endif
4
5
#include "pycore_bytes_methods.h"
6
7
static PyObject*
8
stringlib_isspace(PyObject *self, PyObject *Py_UNUSED(ignored))
9
{
10
return _Py_bytes_isspace(STRINGLIB_STR(self), STRINGLIB_LEN(self));
11
}
12
13
static PyObject*
14
stringlib_isalpha(PyObject *self, PyObject *Py_UNUSED(ignored))
15
{
16
return _Py_bytes_isalpha(STRINGLIB_STR(self), STRINGLIB_LEN(self));
17
}
18
19
static PyObject*
20
stringlib_isalnum(PyObject *self, PyObject *Py_UNUSED(ignored))
21
{
22
return _Py_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self));
23
}
24
25
static PyObject*
26
stringlib_isascii(PyObject *self, PyObject *Py_UNUSED(ignored))
27
{
28
return _Py_bytes_isascii(STRINGLIB_STR(self), STRINGLIB_LEN(self));
29
}
30
31
static PyObject*
32
stringlib_isdigit(PyObject *self, PyObject *Py_UNUSED(ignored))
33
{
34
return _Py_bytes_isdigit(STRINGLIB_STR(self), STRINGLIB_LEN(self));
35
}
36
37
static PyObject*
38
stringlib_islower(PyObject *self, PyObject *Py_UNUSED(ignored))
39
{
40
return _Py_bytes_islower(STRINGLIB_STR(self), STRINGLIB_LEN(self));
41
}
42
43
static PyObject*
44
stringlib_isupper(PyObject *self, PyObject *Py_UNUSED(ignored))
45
{
46
return _Py_bytes_isupper(STRINGLIB_STR(self), STRINGLIB_LEN(self));
47
}
48
49
static PyObject*
50
stringlib_istitle(PyObject *self, PyObject *Py_UNUSED(ignored))
51
{
52
return _Py_bytes_istitle(STRINGLIB_STR(self), STRINGLIB_LEN(self));
53
}
54
55
56
/* functions that return a new object partially translated by ctype funcs: */
57
58
static PyObject*
59
stringlib_lower(PyObject *self, PyObject *Py_UNUSED(ignored))
60
{
61
PyObject* newobj;
62
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
63
if (!newobj)
64
return NULL;
65
_Py_bytes_lower(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
66
STRINGLIB_LEN(self));
67
return newobj;
68
}
69
70
static PyObject*
71
stringlib_upper(PyObject *self, PyObject *Py_UNUSED(ignored))
72
{
73
PyObject* newobj;
74
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
75
if (!newobj)
76
return NULL;
77
_Py_bytes_upper(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
78
STRINGLIB_LEN(self));
79
return newobj;
80
}
81
82
static PyObject*
83
stringlib_title(PyObject *self, PyObject *Py_UNUSED(ignored))
84
{
85
PyObject* newobj;
86
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
87
if (!newobj)
88
return NULL;
89
_Py_bytes_title(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
90
STRINGLIB_LEN(self));
91
return newobj;
92
}
93
94
static PyObject*
95
stringlib_capitalize(PyObject *self, PyObject *Py_UNUSED(ignored))
96
{
97
PyObject* newobj;
98
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
99
if (!newobj)
100
return NULL;
101
_Py_bytes_capitalize(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
102
STRINGLIB_LEN(self));
103
return newobj;
104
}
105
106
static PyObject*
107
stringlib_swapcase(PyObject *self, PyObject *Py_UNUSED(ignored))
108
{
109
PyObject* newobj;
110
newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self));
111
if (!newobj)
112
return NULL;
113
_Py_bytes_swapcase(STRINGLIB_STR(newobj), STRINGLIB_STR(self),
114
STRINGLIB_LEN(self));
115
return newobj;
116
}
117
118