Mercurial > cpython-lru_cache-weakref
annotate Objects/bytes_methods.c @ 66978:aed2bbafa550 3.1
Blocked revisions 87324 via svnmerge
........
r87324 | r.david.murray | 2010-12-16 14:08:51 -0500 (Thu, 16 Dec 2010) | 9 lines
#10719: restore messages generated on invalid compileall args
Before the introduction of filename arguments to compileall it gave semi useful
messages about not being able to 'list' names that weren't valid directories.
This fix restores that behavior. In addition to the test for this case, the
patch also adds a test for the default behavior of compileall when no arguments
are provided, and fixes a bug in one of the previously added tests.
........
| author | R. David Murray <rdmurray@bitdance.com> |
|---|---|
| date | Thu, 16 Dec 2010 19:10:16 +0000 |
| parents | de46e4250431 |
| children | 586745894ab8 |
| 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 */ |
|
53543
4b4b59f278bf
Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53094
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
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 */ |
|
53543
4b4b59f278bf
Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53094
diff
changeset
|
48 if (len == 1 && Py_ISALPHA(*p)) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
49 Py_RETURN_TRUE; |
|
43576
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
53 Py_RETURN_FALSE; |
|
43576
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
57 if (!Py_ISALPHA(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
58 Py_RETURN_FALSE; |
|
43576
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 */ |
|
53543
4b4b59f278bf
Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53094
diff
changeset
|
78 if (len == 1 && Py_ISALNUM(*p)) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
79 Py_RETURN_TRUE; |
|
43576
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
83 Py_RETURN_FALSE; |
|
43576
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
87 if (!Py_ISALNUM(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
88 Py_RETURN_FALSE; |
|
43576
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 */ |
|
53543
4b4b59f278bf
Merged revisions 72040 via svnmerge from
Eric Smith <eric@trueblade.com>
parents:
53094
diff
changeset
|
108 if (len == 1 && Py_ISDIGIT(*p)) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
109 Py_RETURN_TRUE; |
|
43576
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
113 Py_RETURN_FALSE; |
|
43576
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
117 if (!Py_ISDIGIT(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
118 Py_RETURN_FALSE; |
|
43576
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
144 Py_RETURN_FALSE; |
|
43576
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
149 if (Py_ISUPPER(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
150 Py_RETURN_FALSE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
151 else if (!cased && Py_ISLOWER(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
152 cased = 1; |
|
43576
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
178 Py_RETURN_FALSE; |
|
43576
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
183 if (Py_ISLOWER(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
184 Py_RETURN_FALSE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
185 else if (!cased && Py_ISUPPER(*p)) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
186 cased = 1; |
|
43576
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
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) |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
214 Py_RETURN_FALSE; |
|
43576
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++) { |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
220 register const unsigned char ch = *p; |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
221 |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
222 if (Py_ISUPPER(ch)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
223 if (previous_is_cased) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
224 Py_RETURN_FALSE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
225 previous_is_cased = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
226 cased = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
227 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
228 else if (Py_ISLOWER(ch)) { |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
229 if (!previous_is_cased) |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
230 Py_RETURN_FALSE; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
231 previous_is_cased = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
232 cased = 1; |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
233 } |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
234 else |
|
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
235 previous_is_cased = 0; |
|
43576
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 { |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
249 Py_ssize_t i; |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
250 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
251 Py_MEMCPY(result, cptr, len); |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
252 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
253 for (i = 0; i < len; i++) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
254 int c = Py_CHARMASK(result[i]); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
255 if (Py_ISUPPER(c)) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
256 result[i] = Py_TOLOWER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
257 } |
|
43576
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 |
|
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 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
|
262 "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
|
263 \n\ |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
264 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
|
265 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
266 void |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
267 _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
|
268 { |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
269 Py_ssize_t i; |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
270 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
271 Py_MEMCPY(result, cptr, len); |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
272 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
273 for (i = 0; i < len; i++) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
274 int c = Py_CHARMASK(result[i]); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
275 if (Py_ISLOWER(c)) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
276 result[i] = Py_TOUPPER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
277 } |
|
43576
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 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
280 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
281 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
|
282 "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
|
283 \n\ |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
284 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
|
285 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
|
286 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
287 void |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
288 _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
|
289 { |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
290 Py_ssize_t i; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
291 int previous_is_cased = 0; |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
292 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
293 for (i = 0; i < len; i++) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
294 int c = Py_CHARMASK(*s++); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
295 if (Py_ISLOWER(c)) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
296 if (!previous_is_cased) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
297 c = Py_TOUPPER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
298 previous_is_cased = 1; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
299 } else if (Py_ISUPPER(c)) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
300 if (previous_is_cased) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
301 c = Py_TOLOWER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
302 previous_is_cased = 1; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
303 } else |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
304 previous_is_cased = 0; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
305 *result++ = c; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
306 } |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
307 } |
|
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 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
310 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
|
311 "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
|
312 \n\ |
|
62804
c81fc1ffe946
Merged revisions 82573 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61467
diff
changeset
|
313 Return a copy of B with only its first character capitalized (ASCII)\n\ |
|
c81fc1ffe946
Merged revisions 82573 via svnmerge from
Senthil Kumaran <orsenthil@gmail.com>
parents:
61467
diff
changeset
|
314 and the rest lower-cased."); |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
315 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
316 void |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
317 _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
|
318 { |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
319 Py_ssize_t i; |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
320 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
321 if (0 < len) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
322 int c = Py_CHARMASK(*s++); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
323 if (Py_ISLOWER(c)) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
324 *result = Py_TOUPPER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
325 else |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
326 *result = c; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
327 result++; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
328 } |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
329 for (i = 1; i < len; i++) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
330 int c = Py_CHARMASK(*s++); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
331 if (Py_ISUPPER(c)) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
332 *result = Py_TOLOWER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
333 else |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
334 *result = c; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
335 result++; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
336 } |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
337 } |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
338 |
|
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 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
|
341 "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
|
342 \n\ |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
343 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
|
344 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
|
345 |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
346 void |
|
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
347 _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
|
348 { |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
349 Py_ssize_t i; |
|
43576
697cc31a83f6
For PEP3137: Adds missing methods to the mutable PyBytes object (soon
Gregory P. Smith <greg@mad-scientist.com>
parents:
diff
changeset
|
350 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
351 for (i = 0; i < len; i++) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
352 int c = Py_CHARMASK(*s++); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
353 if (Py_ISLOWER(c)) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
354 *result = Py_TOUPPER(c); |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
355 } |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
356 else if (Py_ISUPPER(c)) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
357 *result = Py_TOLOWER(c); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
358 } |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
359 else |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
360 *result = c; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
361 result++; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
362 } |
|
43576
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 |
|
53094
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
365 |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
366 PyDoc_STRVAR_shared(_Py_maketrans__doc__, |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
367 "B.maketrans(frm, to) -> translation table\n\ |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
368 \n\ |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
369 Return a translation table (a bytes object of length 256)\n\ |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
370 suitable for use in bytes.translate where each byte in frm is\n\ |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
371 mapped to the byte at the same position in to.\n\ |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
372 The strings frm and to must be of the same length."); |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
373 |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
374 static Py_ssize_t |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
375 _getbuffer(PyObject *obj, Py_buffer *view) |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
376 { |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
377 PyBufferProcs *buffer = Py_TYPE(obj)->tp_as_buffer; |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
378 |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
379 if (buffer == NULL || buffer->bf_getbuffer == NULL) |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
380 { |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
381 PyErr_Format(PyExc_TypeError, |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
382 "Type %.100s doesn't support the buffer API", |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
383 Py_TYPE(obj)->tp_name); |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
384 return -1; |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
385 } |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
386 |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
387 if (buffer->bf_getbuffer(obj, view, PyBUF_SIMPLE) < 0) |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
388 return -1; |
|
53094
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
389 return view->len; |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
390 } |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
391 |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
392 PyObject * |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
393 _Py_bytes_maketrans(PyObject *args) |
|
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
394 { |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
395 PyObject *frm, *to, *res = NULL; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
396 Py_buffer bfrm, bto; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
397 Py_ssize_t i; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
398 char *p; |
|
61467
f197407bdba2
Recorded merge of revisions 81032 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
56515
diff
changeset
|
399 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
400 bfrm.len = -1; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
401 bto.len = -1; |
|
53094
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
402 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
403 if (!PyArg_ParseTuple(args, "OO:maketrans", &frm, &to)) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
404 return NULL; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
405 if (_getbuffer(frm, &bfrm) < 0) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
406 return NULL; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
407 if (_getbuffer(to, &bto) < 0) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
408 goto done; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
409 if (bfrm.len != bto.len) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
410 PyErr_Format(PyExc_ValueError, |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
411 "maketrans arguments must have same length"); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
412 goto done; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
413 } |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
414 res = PyBytes_FromStringAndSize(NULL, 256); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
415 if (!res) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
416 goto done; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
417 } |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
418 p = PyBytes_AS_STRING(res); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
419 for (i = 0; i < 256; i++) |
|
64045
de46e4250431
Merged revisions 84070,84074 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
64043
diff
changeset
|
420 p[i] = (char) i; |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
421 for (i = 0; i < bfrm.len; i++) { |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
422 p[((unsigned char *)bfrm.buf)[i]] = ((char *)bto.buf)[i]; |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
423 } |
|
53094
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
424 |
|
64043
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
425 done: |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
426 if (bfrm.len != -1) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
427 PyBuffer_Release(&bfrm); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
428 if (bto.len != -1) |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
429 PyBuffer_Release(&bto); |
|
7a54848d4929
Merged revisions 84072 via svnmerge from
Antoine Pitrou <solipsis@pitrou.net>
parents:
62804
diff
changeset
|
430 return res; |
|
53094
4407e4d07084
Add bytes/bytearray.maketrans() to mirror str.maketrans(), and deprecate
Georg Brandl <georg@python.org>
parents:
47301
diff
changeset
|
431 } |
