Gregory P. Smith | 60d241f | 2007-10-16 06:31:30 +0000 | [diff] [blame] | 1 | /* NOTE: this API is -ONLY- for use with single byte character strings. */ |
| 2 | /* Do not use it with Unicode. */ |
| 3 | |
| 4 | #include "bytes_methods.h" |
| 5 | |
| 6 | static PyObject* |
| 7 | stringlib_isspace(PyObject *self) |
| 8 | { |
| 9 | return _Py_bytes_isspace(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 10 | } |
| 11 | |
| 12 | static PyObject* |
| 13 | stringlib_isalpha(PyObject *self) |
| 14 | { |
| 15 | return _Py_bytes_isalpha(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 16 | } |
| 17 | |
| 18 | static PyObject* |
| 19 | stringlib_isalnum(PyObject *self) |
| 20 | { |
| 21 | return _Py_bytes_isalnum(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 22 | } |
| 23 | |
| 24 | static PyObject* |
| 25 | stringlib_isdigit(PyObject *self) |
| 26 | { |
| 27 | return _Py_bytes_isdigit(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 28 | } |
| 29 | |
| 30 | static PyObject* |
| 31 | stringlib_islower(PyObject *self) |
| 32 | { |
| 33 | return _Py_bytes_islower(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 34 | } |
| 35 | |
| 36 | static PyObject* |
| 37 | stringlib_isupper(PyObject *self) |
| 38 | { |
| 39 | return _Py_bytes_isupper(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 40 | } |
| 41 | |
| 42 | static PyObject* |
| 43 | stringlib_istitle(PyObject *self) |
| 44 | { |
| 45 | return _Py_bytes_istitle(STRINGLIB_STR(self), STRINGLIB_LEN(self)); |
| 46 | } |
| 47 | |
| 48 | |
| 49 | /* functions that return a new object partially translated by ctype funcs: */ |
| 50 | |
| 51 | static PyObject* |
| 52 | stringlib_lower(PyObject *self) |
| 53 | { |
| 54 | PyObject* newobj; |
| 55 | newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); |
| 56 | if (!newobj) |
| 57 | return NULL; |
| 58 | _Py_bytes_lower(STRINGLIB_STR(newobj), STRINGLIB_STR(self), |
| 59 | STRINGLIB_LEN(self)); |
| 60 | return newobj; |
| 61 | } |
| 62 | |
| 63 | static PyObject* |
| 64 | stringlib_upper(PyObject *self) |
| 65 | { |
| 66 | PyObject* newobj; |
| 67 | newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); |
| 68 | if (!newobj) |
| 69 | return NULL; |
| 70 | _Py_bytes_upper(STRINGLIB_STR(newobj), STRINGLIB_STR(self), |
| 71 | STRINGLIB_LEN(self)); |
| 72 | return newobj; |
| 73 | } |
| 74 | |
| 75 | static PyObject* |
| 76 | stringlib_title(PyObject *self) |
| 77 | { |
| 78 | PyObject* newobj; |
| 79 | newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); |
| 80 | if (!newobj) |
| 81 | return NULL; |
| 82 | _Py_bytes_title(STRINGLIB_STR(newobj), STRINGLIB_STR(self), |
| 83 | STRINGLIB_LEN(self)); |
| 84 | return newobj; |
| 85 | } |
| 86 | |
| 87 | static PyObject* |
| 88 | stringlib_capitalize(PyObject *self) |
| 89 | { |
| 90 | PyObject* newobj; |
| 91 | newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); |
| 92 | if (!newobj) |
| 93 | return NULL; |
| 94 | _Py_bytes_capitalize(STRINGLIB_STR(newobj), STRINGLIB_STR(self), |
| 95 | STRINGLIB_LEN(self)); |
| 96 | return newobj; |
| 97 | } |
| 98 | |
| 99 | static PyObject* |
| 100 | stringlib_swapcase(PyObject *self) |
| 101 | { |
| 102 | PyObject* newobj; |
| 103 | newobj = STRINGLIB_NEW(NULL, STRINGLIB_LEN(self)); |
| 104 | if (!newobj) |
| 105 | return NULL; |
| 106 | _Py_bytes_swapcase(STRINGLIB_STR(newobj), STRINGLIB_STR(self), |
| 107 | STRINGLIB_LEN(self)); |
| 108 | return newobj; |
| 109 | } |