Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
6934957f
Commit
6934957f
authored
Aug 15, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix indentation and remove dead code.
parent
6f7cb958
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
132 deletions
+98
-132
Objects/bytes_methods.c
Objects/bytes_methods.c
+98
-132
No files found.
Objects/bytes_methods.c
View file @
6934957f
...
@@ -246,23 +246,15 @@ Return a copy of B with all ASCII characters converted to lowercase.");
...
@@ -246,23 +246,15 @@ Return a copy of B with all ASCII characters converted to lowercase.");
void
void
_Py_bytes_lower
(
char
*
result
,
const
char
*
cptr
,
Py_ssize_t
len
)
_Py_bytes_lower
(
char
*
result
,
const
char
*
cptr
,
Py_ssize_t
len
)
{
{
Py_ssize_t
i
;
Py_ssize_t
i
;
/*
Py_MEMCPY
(
result
,
cptr
,
len
);
newobj = PyBytes_FromStringAndSize(NULL, len);
if (!newobj)
return NULL;
s = PyBytes_AS_STRING(newobj);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
*/
int
c
=
Py_CHARMASK
(
result
[
i
]);
if
(
Py_ISUPPER
(
c
))
Py_MEMCPY
(
result
,
cptr
,
len
);
result
[
i
]
=
Py_TOLOWER
(
c
);
}
for
(
i
=
0
;
i
<
len
;
i
++
)
{
int
c
=
Py_CHARMASK
(
result
[
i
]);
if
(
Py_ISUPPER
(
c
))
result
[
i
]
=
Py_TOLOWER
(
c
);
}
}
}
...
@@ -274,23 +266,15 @@ Return a copy of B with all ASCII characters converted to uppercase.");
...
@@ -274,23 +266,15 @@ Return a copy of B with all ASCII characters converted to uppercase.");
void
void
_Py_bytes_upper
(
char
*
result
,
const
char
*
cptr
,
Py_ssize_t
len
)
_Py_bytes_upper
(
char
*
result
,
const
char
*
cptr
,
Py_ssize_t
len
)
{
{
Py_ssize_t
i
;
Py_ssize_t
i
;
/*
newobj = PyBytes_FromStringAndSize(NULL, len);
if (!newobj)
return NULL;
s = PyBytes_AS_STRING(newobj);
Py_MEMCPY
(
result
,
cptr
,
len
);
*/
Py_MEMCPY
(
result
,
cptr
,
len
);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
int
c
=
Py_CHARMASK
(
result
[
i
]);
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
Py_ISLOWER
(
c
))
int
c
=
Py_CHARMASK
(
result
[
i
]);
result
[
i
]
=
Py_TOUPPER
(
c
);
if
(
Py_ISLOWER
(
c
))
}
result
[
i
]
=
Py_TOUPPER
(
c
);
}
}
}
...
@@ -303,29 +287,23 @@ characters, all remaining cased characters have lowercase.");
...
@@ -303,29 +287,23 @@ characters, all remaining cased characters have lowercase.");
void
void
_Py_bytes_title
(
char
*
result
,
char
*
s
,
Py_ssize_t
len
)
_Py_bytes_title
(
char
*
result
,
char
*
s
,
Py_ssize_t
len
)
{
{
Py_ssize_t
i
;
Py_ssize_t
i
;
int
previous_is_cased
=
0
;
int
previous_is_cased
=
0
;
/*
for
(
i
=
0
;
i
<
len
;
i
++
)
{
newobj = PyBytes_FromStringAndSize(NULL, len);
int
c
=
Py_CHARMASK
(
*
s
++
);
if (newobj == NULL)
if
(
Py_ISLOWER
(
c
))
{
return NULL;
if
(
!
previous_is_cased
)
s_new = PyBytes_AsString(newobj);
c
=
Py_TOUPPER
(
c
);
*/
previous_is_cased
=
1
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
}
else
if
(
Py_ISUPPER
(
c
))
{
int
c
=
Py_CHARMASK
(
*
s
++
);
if
(
previous_is_cased
)
if
(
Py_ISLOWER
(
c
))
{
c
=
Py_TOLOWER
(
c
);
if
(
!
previous_is_cased
)
previous_is_cased
=
1
;
c
=
Py_TOUPPER
(
c
);
}
else
previous_is_cased
=
1
;
previous_is_cased
=
0
;
}
else
if
(
Py_ISUPPER
(
c
))
{
*
result
++
=
c
;
if
(
previous_is_cased
)
}
c
=
Py_TOLOWER
(
c
);
previous_is_cased
=
1
;
}
else
previous_is_cased
=
0
;
*
result
++
=
c
;
}
}
}
...
@@ -338,30 +316,24 @@ and the rest lower-cased.");
...
@@ -338,30 +316,24 @@ and the rest lower-cased.");
void
void
_Py_bytes_capitalize
(
char
*
result
,
char
*
s
,
Py_ssize_t
len
)
_Py_bytes_capitalize
(
char
*
result
,
char
*
s
,
Py_ssize_t
len
)
{
{
Py_ssize_t
i
;
Py_ssize_t
i
;
/*
if
(
0
<
len
)
{
newobj = PyBytes_FromStringAndSize(NULL, len);
int
c
=
Py_CHARMASK
(
*
s
++
);
if (newobj == NULL)
if
(
Py_ISLOWER
(
c
))
return NULL;
*
result
=
Py_TOUPPER
(
c
);
s_new = PyBytes_AsString(newobj);
else
*/
*
result
=
c
;
if
(
0
<
len
)
{
result
++
;
int
c
=
Py_CHARMASK
(
*
s
++
);
}
if
(
Py_ISLOWER
(
c
))
for
(
i
=
1
;
i
<
len
;
i
++
)
{
*
result
=
Py_TOUPPER
(
c
);
int
c
=
Py_CHARMASK
(
*
s
++
);
else
if
(
Py_ISUPPER
(
c
))
*
result
=
c
;
*
result
=
Py_TOLOWER
(
c
);
result
++
;
else
}
*
result
=
c
;
for
(
i
=
1
;
i
<
len
;
i
++
)
{
result
++
;
int
c
=
Py_CHARMASK
(
*
s
++
);
}
if
(
Py_ISUPPER
(
c
))
*
result
=
Py_TOLOWER
(
c
);
else
*
result
=
c
;
result
++
;
}
}
}
...
@@ -374,26 +346,20 @@ to lowercase ASCII and vice versa.");
...
@@ -374,26 +346,20 @@ to lowercase ASCII and vice versa.");
void
void
_Py_bytes_swapcase
(
char
*
result
,
char
*
s
,
Py_ssize_t
len
)
_Py_bytes_swapcase
(
char
*
result
,
char
*
s
,
Py_ssize_t
len
)
{
{
Py_ssize_t
i
;
Py_ssize_t
i
;
/*
for
(
i
=
0
;
i
<
len
;
i
++
)
{
newobj = PyBytes_FromStringAndSize(NULL, len);
int
c
=
Py_CHARMASK
(
*
s
++
);
if (newobj == NULL)
if
(
Py_ISLOWER
(
c
))
{
return NULL;
*
result
=
Py_TOUPPER
(
c
);
s_new = PyBytes_AsString(newobj);
*/
for
(
i
=
0
;
i
<
len
;
i
++
)
{
int
c
=
Py_CHARMASK
(
*
s
++
);
if
(
Py_ISLOWER
(
c
))
{
*
result
=
Py_TOUPPER
(
c
);
}
else
if
(
Py_ISUPPER
(
c
))
{
*
result
=
Py_TOLOWER
(
c
);
}
else
*
result
=
c
;
result
++
;
}
}
else
if
(
Py_ISUPPER
(
c
))
{
*
result
=
Py_TOLOWER
(
c
);
}
else
*
result
=
c
;
result
++
;
}
}
}
...
@@ -419,47 +385,47 @@ _getbuffer(PyObject *obj, Py_buffer *view)
...
@@ -419,47 +385,47 @@ _getbuffer(PyObject *obj, Py_buffer *view)
}
}
if
(
buffer
->
bf_getbuffer
(
obj
,
view
,
PyBUF_SIMPLE
)
<
0
)
if
(
buffer
->
bf_getbuffer
(
obj
,
view
,
PyBUF_SIMPLE
)
<
0
)
return
-
1
;
return
-
1
;
return
view
->
len
;
return
view
->
len
;
}
}
PyObject
*
PyObject
*
_Py_bytes_maketrans
(
PyObject
*
args
)
_Py_bytes_maketrans
(
PyObject
*
args
)
{
{
PyObject
*
frm
,
*
to
,
*
res
=
NULL
;
PyObject
*
frm
,
*
to
,
*
res
=
NULL
;
Py_buffer
bfrm
,
bto
;
Py_buffer
bfrm
,
bto
;
Py_ssize_t
i
;
Py_ssize_t
i
;
char
*
p
;
char
*
p
;
bfrm
.
len
=
-
1
;
bfrm
.
len
=
-
1
;
bto
.
len
=
-
1
;
bto
.
len
=
-
1
;
if
(
!
PyArg_ParseTuple
(
args
,
"OO:maketrans"
,
&
frm
,
&
to
))
if
(
!
PyArg_ParseTuple
(
args
,
"OO:maketrans"
,
&
frm
,
&
to
))
return
NULL
;
return
NULL
;
if
(
_getbuffer
(
frm
,
&
bfrm
)
<
0
)
if
(
_getbuffer
(
frm
,
&
bfrm
)
<
0
)
return
NULL
;
return
NULL
;
if
(
_getbuffer
(
to
,
&
bto
)
<
0
)
if
(
_getbuffer
(
to
,
&
bto
)
<
0
)
goto
done
;
goto
done
;
if
(
bfrm
.
len
!=
bto
.
len
)
{
if
(
bfrm
.
len
!=
bto
.
len
)
{
PyErr_Format
(
PyExc_ValueError
,
PyErr_Format
(
PyExc_ValueError
,
"maketrans arguments must have same length"
);
"maketrans arguments must have same length"
);
goto
done
;
goto
done
;
}
}
res
=
PyBytes_FromStringAndSize
(
NULL
,
256
);
res
=
PyBytes_FromStringAndSize
(
NULL
,
256
);
if
(
!
res
)
{
if
(
!
res
)
{
goto
done
;
goto
done
;
}
}
p
=
PyBytes_AS_STRING
(
res
);
p
=
PyBytes_AS_STRING
(
res
);
for
(
i
=
0
;
i
<
256
;
i
++
)
for
(
i
=
0
;
i
<
256
;
i
++
)
p
[
i
]
=
i
;
p
[
i
]
=
i
;
for
(
i
=
0
;
i
<
bfrm
.
len
;
i
++
)
{
for
(
i
=
0
;
i
<
bfrm
.
len
;
i
++
)
{
p
[((
unsigned
char
*
)
bfrm
.
buf
)[
i
]]
=
((
char
*
)
bto
.
buf
)[
i
];
p
[((
unsigned
char
*
)
bfrm
.
buf
)[
i
]]
=
((
char
*
)
bto
.
buf
)[
i
];
}
}
done:
done:
if
(
bfrm
.
len
!=
-
1
)
if
(
bfrm
.
len
!=
-
1
)
PyBuffer_Release
(
&
bfrm
);
PyBuffer_Release
(
&
bfrm
);
if
(
bto
.
len
!=
-
1
)
if
(
bto
.
len
!=
-
1
)
PyBuffer_Release
(
&
bto
);
PyBuffer_Release
(
&
bto
);
return
res
;
return
res
;
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment