annotate Objects/bytes_methods.c @ 58765:2ba7677bfa95 legacy-trunk

testCopysign was defined twice in test_math; combine the definitions
author Mark Dickinson <dickinsm@gmail.com>
date Sat, 06 Feb 2010 23:11:25 +0000
parents 4bdd847b57c2
children fd25030223b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
1 #include "Python.h"
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
2 #include "bytes_methods.h"
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
3
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
4 PyDoc_STRVAR_shared(_Py_isspace__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
5 "B.isspace() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
6 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
7 Return True if all characters in B are whitespace\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
8 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
9
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
10 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
11 _Py_bytes_isspace(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
12 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
13 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
14 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
15 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
16
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
17 /* Shortcut for single character strings */
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
18 if (len == 1 && Py_ISSPACE(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
19 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
20
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
21 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
22 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
23 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
24
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
25 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
26 for (; p < e; p++) {
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
27 if (!Py_ISSPACE(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
28 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
29 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
30 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
31 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
32
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
33
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
34 PyDoc_STRVAR_shared(_Py_isalpha__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
35 "B.isalpha() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
36 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
37 Return True if all characters in B are alphabetic\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
38 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
39
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
40 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
41 _Py_bytes_isalpha(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
42 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
43 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
44 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
45 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
46
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
47 /* Shortcut for single character strings */
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
48 if (len == 1 && Py_ISALPHA(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
49 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
50
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
51 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
52 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
53 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
54
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
55 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
56 for (; p < e; p++) {
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
57 if (!Py_ISALPHA(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
58 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
59 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
60 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
61 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
62
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
63
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
64 PyDoc_STRVAR_shared(_Py_isalnum__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
65 "B.isalnum() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
66 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
67 Return True if all characters in B are alphanumeric\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
68 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
69
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
70 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
71 _Py_bytes_isalnum(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
72 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
73 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
74 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
75 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
76
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
77 /* Shortcut for single character strings */
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
78 if (len == 1 && Py_ISALNUM(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
79 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
80
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
81 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
82 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
83 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
84
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
85 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
86 for (; p < e; p++) {
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
87 if (!Py_ISALNUM(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
88 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
89 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
90 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
91 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
92
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
93
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
94 PyDoc_STRVAR_shared(_Py_isdigit__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
95 "B.isdigit() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
96 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
97 Return True if all characters in B are digits\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
98 and there is at least one character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
99
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
100 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
101 _Py_bytes_isdigit(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
102 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
103 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
104 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
105 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
106
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
107 /* Shortcut for single character strings */
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
108 if (len == 1 && Py_ISDIGIT(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
109 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
110
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
111 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
112 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
113 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
114
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
115 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
116 for (; p < e; p++) {
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
117 if (!Py_ISDIGIT(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
118 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
119 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
120 Py_RETURN_TRUE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
121 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
122
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
123
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
124 PyDoc_STRVAR_shared(_Py_islower__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
125 "B.islower() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
126 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
127 Return True if all cased characters in B are lowercase and there is\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
128 at least one cased character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
129
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
130 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
131 _Py_bytes_islower(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
132 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
133 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
134 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
135 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
136 int cased;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
137
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
138 /* Shortcut for single character strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
139 if (len == 1)
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
140 return PyBool_FromLong(Py_ISLOWER(*p));
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
141
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
142 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
143 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
144 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
145
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
146 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
147 cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
148 for (; p < e; p++) {
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
149 if (Py_ISUPPER(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
150 Py_RETURN_FALSE;
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
151 else if (!cased && Py_ISLOWER(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
152 cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
153 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
154 return PyBool_FromLong(cased);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
155 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
156
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
157
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
158 PyDoc_STRVAR_shared(_Py_isupper__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
159 "B.isupper() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
160 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
161 Return True if all cased characters in B are uppercase and there is\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
162 at least one cased character in B, False otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
163
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
164 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
165 _Py_bytes_isupper(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
166 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
167 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
168 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
169 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
170 int cased;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
171
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
172 /* Shortcut for single character strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
173 if (len == 1)
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
174 return PyBool_FromLong(Py_ISUPPER(*p));
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
175
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
176 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
177 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
178 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
179
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
180 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
181 cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
182 for (; p < e; p++) {
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
183 if (Py_ISLOWER(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
184 Py_RETURN_FALSE;
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
185 else if (!cased && Py_ISUPPER(*p))
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
186 cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
187 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
188 return PyBool_FromLong(cased);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
189 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
190
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
191
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
192 PyDoc_STRVAR_shared(_Py_istitle__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
193 "B.istitle() -> bool\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
194 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
195 Return True if B is a titlecased string and there is at least one\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
196 character in B, i.e. uppercase characters may only follow uncased\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
197 characters and lowercase characters only cased ones. Return False\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
198 otherwise.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
199
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
200 PyObject*
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
201 _Py_bytes_istitle(const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
202 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
203 register const unsigned char *p
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
204 = (unsigned char *) cptr;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
205 register const unsigned char *e;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
206 int cased, previous_is_cased;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
207
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
208 /* Shortcut for single character strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
209 if (len == 1)
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
210 return PyBool_FromLong(Py_ISUPPER(*p));
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
211
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
212 /* Special case for empty strings */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
213 if (len == 0)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
214 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
215
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
216 e = p + len;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
217 cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
218 previous_is_cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
219 for (; p < e; p++) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
220 register const unsigned char ch = *p;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
221
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
222 if (Py_ISUPPER(ch)) {
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
223 if (previous_is_cased)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
224 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
225 previous_is_cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
226 cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
227 }
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
228 else if (Py_ISLOWER(ch)) {
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
229 if (!previous_is_cased)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
230 Py_RETURN_FALSE;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
231 previous_is_cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
232 cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
233 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
234 else
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
235 previous_is_cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
236 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
237 return PyBool_FromLong(cased);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
238 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
239
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
240
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
241 PyDoc_STRVAR_shared(_Py_lower__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
242 "B.lower() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
243 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
244 Return a copy of B with all ASCII characters converted to lowercase.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
245
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
246 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
247 _Py_bytes_lower(char *result, const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
248 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
249 Py_ssize_t i;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
250
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
251 /*
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
252 newobj = PyString_FromStringAndSize(NULL, len);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
253 if (!newobj)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
254 return NULL;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
255
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
256 s = PyString_AS_STRING(newobj);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
257 */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
258
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
259 Py_MEMCPY(result, cptr, len);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
260
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
261 for (i = 0; i < len; i++) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
262 int c = Py_CHARMASK(result[i]);
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
263 if (Py_ISUPPER(c))
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
264 result[i] = Py_TOLOWER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
265 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
266 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
267
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
268
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
269 PyDoc_STRVAR_shared(_Py_upper__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
270 "B.upper() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
271 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
272 Return a copy of B with all ASCII characters converted to uppercase.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
273
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
274 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
275 _Py_bytes_upper(char *result, const char *cptr, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
276 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
277 Py_ssize_t i;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
278
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
279 /*
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
280 newobj = PyString_FromStringAndSize(NULL, len);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
281 if (!newobj)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
282 return NULL;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
283
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
284 s = PyString_AS_STRING(newobj);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
285 */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
286
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
287 Py_MEMCPY(result, cptr, len);
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
288
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
289 for (i = 0; i < len; i++) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
290 int c = Py_CHARMASK(result[i]);
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
291 if (Py_ISLOWER(c))
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
292 result[i] = Py_TOUPPER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
293 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
294 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
295
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
296
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
297 PyDoc_STRVAR_shared(_Py_title__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
298 "B.title() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
299 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
300 Return a titlecased version of B, i.e. ASCII words start with uppercase\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
301 characters, all remaining cased characters have lowercase.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
302
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
303 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
304 _Py_bytes_title(char *result, char *s, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
305 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
306 Py_ssize_t i;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
307 int previous_is_cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
308
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
309 /*
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
310 newobj = PyString_FromStringAndSize(NULL, len);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
311 if (newobj == NULL)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
312 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
313 s_new = PyString_AsString(newobj);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
314 */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
315 for (i = 0; i < len; i++) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
316 int c = Py_CHARMASK(*s++);
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
317 if (Py_ISLOWER(c)) {
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
318 if (!previous_is_cased)
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
319 c = Py_TOUPPER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
320 previous_is_cased = 1;
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
321 } else if (Py_ISUPPER(c)) {
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
322 if (previous_is_cased)
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
323 c = Py_TOLOWER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
324 previous_is_cased = 1;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
325 } else
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
326 previous_is_cased = 0;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
327 *result++ = c;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
328 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
329 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
330
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
331
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
332 PyDoc_STRVAR_shared(_Py_capitalize__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
333 "B.capitalize() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
334 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
335 Return a copy of B with only its first character capitalized (ASCII).");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
336
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
337 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
338 _Py_bytes_capitalize(char *result, char *s, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
339 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
340 Py_ssize_t i;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
341
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
342 /*
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
343 newobj = PyString_FromStringAndSize(NULL, len);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
344 if (newobj == NULL)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
345 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
346 s_new = PyString_AsString(newobj);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
347 */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
348 if (0 < len) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
349 int c = Py_CHARMASK(*s++);
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
350 if (Py_ISLOWER(c))
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
351 *result = Py_TOUPPER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
352 else
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
353 *result = c;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
354 result++;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
355 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
356 for (i = 1; i < len; i++) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
357 int c = Py_CHARMASK(*s++);
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
358 if (Py_ISUPPER(c))
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
359 *result = Py_TOLOWER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
360 else
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
361 *result = c;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
362 result++;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
363 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
364 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
365
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
366
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
367 PyDoc_STRVAR_shared(_Py_swapcase__doc__,
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
368 "B.swapcase() -> copy of B\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
369 \n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
370 Return a copy of B with uppercase ASCII characters converted\n\
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
371 to lowercase ASCII and vice versa.");
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
372
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
373 void
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
374 _Py_bytes_swapcase(char *result, char *s, Py_ssize_t len)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
375 {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
376 Py_ssize_t i;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
377
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
378 /*
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
379 newobj = PyString_FromStringAndSize(NULL, len);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
380 if (newobj == NULL)
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
381 return NULL;
47527
52294af4b663 This reverts r63675 based on the discussion in this thread:
Gregory P. Smith <greg@mad-scientist.com>
parents: 47301
diff changeset
382 s_new = PyString_AsString(newobj);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
383 */
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
384 for (i = 0; i < len; i++) {
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
385 int c = Py_CHARMASK(*s++);
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
386 if (Py_ISLOWER(c)) {
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
387 *result = Py_TOUPPER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
388 }
53539
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
389 else if (Py_ISUPPER(c)) {
4bdd847b57c2 Issue #5793: rationalize isdigit / isalpha / tolower, etc. Will port to py3k. Should fix Windows buildbot errors.
Eric Smith <eric@trueblade.com>
parents: 47527
diff changeset
390 *result = Py_TOLOWER(c);
43576
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
391 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
392 else
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
393 *result = c;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
394 result++;
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
395 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
396 }
697cc31a83f6 For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff changeset
397