Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
5c97c798
Kaydet (Commit)
5c97c798
authored
Şub 17, 2006
tarafından
Martin v. Löwis
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make ssize_t-clean.
üst
21dd1afd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
38 deletions
+40
-38
stropmodule.c
Modules/stropmodule.c
+40
-38
No files found.
Modules/stropmodule.c
Dosyayı görüntüle @
5c97c798
/* strop module */
#define PY_SSIZE_T_CLEAN
#include "Python.h"
#include <ctype.h>
...
...
@@ -26,10 +27,11 @@ PyDoc_STRVAR(strop_module__doc__,
static
PyObject
*
split_whitespace
(
char
*
s
,
int
len
,
in
t
maxsplit
)
split_whitespace
(
char
*
s
,
Py_ssize_t
len
,
Py_ssize_
t
maxsplit
)
{
int
i
=
0
,
j
,
err
;
int
countsplit
=
0
;
Py_ssize_t
i
=
0
,
j
;
int
err
;
Py_ssize_t
countsplit
=
0
;
PyObject
*
item
;
PyObject
*
list
=
PyList_New
(
0
);
...
...
@@ -45,7 +47,7 @@ split_whitespace(char *s, int len, int maxsplit)
i
=
i
+
1
;
}
if
(
j
<
i
)
{
item
=
PyString_FromStringAndSize
(
s
+
j
,
(
int
)(
i
-
j
)
);
item
=
PyString_FromStringAndSize
(
s
+
j
,
i
-
j
);
if
(
item
==
NULL
)
goto
finally
;
...
...
@@ -60,7 +62,7 @@ split_whitespace(char *s, int len, int maxsplit)
}
if
(
maxsplit
&&
(
countsplit
>=
maxsplit
)
&&
i
<
len
)
{
item
=
PyString_FromStringAndSize
(
s
+
i
,
(
int
)(
len
-
i
)
);
s
+
i
,
len
-
i
);
if
(
item
==
NULL
)
goto
finally
;
...
...
@@ -94,8 +96,8 @@ PyDoc_STRVAR(splitfields__doc__,
static
PyObject
*
strop_splitfields
(
PyObject
*
self
,
PyObject
*
args
)
{
in
t
len
,
n
,
i
,
j
,
err
;
in
t
splitcount
,
maxsplit
;
Py_ssize_
t
len
,
n
,
i
,
j
,
err
;
Py_ssize_
t
splitcount
,
maxsplit
;
char
*
s
,
*
sub
;
PyObject
*
list
,
*
item
;
...
...
@@ -104,7 +106,7 @@ strop_splitfields(PyObject *self, PyObject *args)
n
=
0
;
splitcount
=
0
;
maxsplit
=
0
;
if
(
!
PyArg_ParseTuple
(
args
,
"t#|z#
i
:split"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
maxsplit
))
if
(
!
PyArg_ParseTuple
(
args
,
"t#|z#
n
:split"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
maxsplit
))
return
NULL
;
if
(
sub
==
NULL
)
return
split_whitespace
(
s
,
len
,
maxsplit
);
...
...
@@ -120,7 +122,7 @@ strop_splitfields(PyObject *self, PyObject *args)
i
=
j
=
0
;
while
(
i
+
n
<=
len
)
{
if
(
s
[
i
]
==
sub
[
0
]
&&
(
n
==
1
||
memcmp
(
s
+
i
,
sub
,
n
)
==
0
))
{
item
=
PyString_FromStringAndSize
(
s
+
j
,
(
int
)(
i
-
j
)
);
item
=
PyString_FromStringAndSize
(
s
+
j
,
i
-
j
);
if
(
item
==
NULL
)
goto
fail
;
err
=
PyList_Append
(
list
,
item
);
...
...
@@ -135,7 +137,7 @@ strop_splitfields(PyObject *self, PyObject *args)
else
i
++
;
}
item
=
PyString_FromStringAndSize
(
s
+
j
,
(
int
)(
len
-
j
)
);
item
=
PyString_FromStringAndSize
(
s
+
j
,
len
-
j
);
if
(
item
==
NULL
)
goto
fail
;
err
=
PyList_Append
(
list
,
item
);
...
...
@@ -287,10 +289,10 @@ static PyObject *
strop_find
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
s
,
*
sub
;
int
len
,
n
,
i
=
0
,
last
=
IN
T_MAX
;
Py_ssize_t
len
,
n
,
i
=
0
,
last
=
PY_SSIZE_
T_MAX
;
WARN
;
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#|
ii
:find"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#|
nn
:find"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
return
NULL
;
if
(
last
>
len
)
...
...
@@ -330,11 +332,11 @@ static PyObject *
strop_rfind
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
s
,
*
sub
;
in
t
len
,
n
,
j
;
in
t
i
=
0
,
last
=
INT_MAX
;
Py_ssize_
t
len
,
n
,
j
;
Py_ssize_
t
i
=
0
,
last
=
INT_MAX
;
WARN
;
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#|
ii
:rfind"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#|
nn
:rfind"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
return
NULL
;
if
(
last
>
len
)
...
...
@@ -576,10 +578,10 @@ strop_expandtabs(PyObject *self, PyObject *args)
char
*
e
;
char
*
p
;
char
*
q
;
in
t
i
,
j
;
Py_ssize_
t
i
,
j
;
PyObject
*
out
;
char
*
string
;
in
t
stringlen
;
Py_ssize_
t
stringlen
;
int
tabsize
=
8
;
WARN
;
...
...
@@ -644,12 +646,12 @@ static PyObject *
strop_count
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
s
,
*
sub
;
in
t
len
,
n
;
in
t
i
=
0
,
last
=
INT_MAX
;
in
t
m
,
r
;
Py_ssize_
t
len
,
n
;
Py_ssize_
t
i
=
0
,
last
=
INT_MAX
;
Py_ssize_
t
m
,
r
;
WARN
;
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#|
ii
:count"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#|
nn
:count"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
return
NULL
;
if
(
last
>
len
)
last
=
len
;
...
...
@@ -884,7 +886,7 @@ static PyObject *
strop_maketrans
(
PyObject
*
self
,
PyObject
*
args
)
{
unsigned
char
*
c
,
*
from
=
NULL
,
*
to
=
NULL
;
in
t
i
,
fromlen
=
0
,
tolen
=
0
;
Py_ssize_
t
i
,
fromlen
=
0
,
tolen
=
0
;
PyObject
*
result
;
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#:maketrans"
,
&
from
,
&
fromlen
,
&
to
,
&
tolen
))
...
...
@@ -998,10 +1000,10 @@ strop_translate(PyObject *self, PyObject *args)
found, or -1 if not found. If len of PAT is greater than length of
MEM, the function returns -1.
*/
static
in
t
mymemfind
(
const
char
*
mem
,
int
len
,
const
char
*
pat
,
in
t
pat_len
)
static
Py_ssize_
t
mymemfind
(
const
char
*
mem
,
Py_ssize_t
len
,
const
char
*
pat
,
Py_ssize_
t
pat_len
)
{
register
in
t
ii
;
register
Py_ssize_
t
ii
;
/* pattern can not occur in the last pat_len-1 chars */
len
-=
pat_len
;
...
...
@@ -1023,11 +1025,11 @@ mymemfind(const char *mem, int len, const char *pat, int pat_len)
meaning mem=1111 and pat==11 returns 2.
mem=11111 and pat==11 also return 2.
*/
static
in
t
mymemcnt
(
const
char
*
mem
,
int
len
,
const
char
*
pat
,
in
t
pat_len
)
static
Py_ssize_
t
mymemcnt
(
const
char
*
mem
,
Py_ssize_t
len
,
const
char
*
pat
,
Py_ssize_
t
pat_len
)
{
register
in
t
offset
=
0
;
in
t
nfound
=
0
;
register
Py_ssize_
t
offset
=
0
;
Py_ssize_
t
nfound
=
0
;
while
(
len
>=
0
)
{
offset
=
mymemfind
(
mem
,
len
,
pat
,
pat_len
);
...
...
@@ -1060,15 +1062,15 @@ mymemcnt(const char *mem, int len, const char *pat, int pat_len)
NULL if an error occurred.
*/
static
char
*
mymemreplace
(
const
char
*
str
,
in
t
len
,
/* input string */
const
char
*
pat
,
in
t
pat_len
,
/* pattern string to find */
const
char
*
sub
,
in
t
sub_len
,
/* substitution string */
in
t
count
,
/* number of replacements */
in
t
*
out_len
)
mymemreplace
(
const
char
*
str
,
Py_ssize_
t
len
,
/* input string */
const
char
*
pat
,
Py_ssize_
t
pat_len
,
/* pattern string to find */
const
char
*
sub
,
Py_ssize_
t
sub_len
,
/* substitution string */
Py_ssize_
t
count
,
/* number of replacements */
Py_ssize_
t
*
out_len
)
{
char
*
out_s
;
char
*
new_s
;
in
t
nfound
,
offset
,
new_len
;
Py_ssize_
t
nfound
,
offset
,
new_len
;
if
(
len
==
0
||
pat_len
>
len
)
goto
return_same
;
...
...
@@ -1137,12 +1139,12 @@ static PyObject *
strop_replace
(
PyObject
*
self
,
PyObject
*
args
)
{
char
*
str
,
*
pat
,
*
sub
,
*
new_s
;
in
t
len
,
pat_len
,
sub_len
,
out_len
;
in
t
count
=
-
1
;
Py_ssize_
t
len
,
pat_len
,
sub_len
,
out_len
;
Py_ssize_
t
count
=
-
1
;
PyObject
*
new
;
WARN
;
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#t#|
i
:replace"
,
if
(
!
PyArg_ParseTuple
(
args
,
"t#t#t#|
n
:replace"
,
&
str
,
&
len
,
&
pat
,
&
pat_len
,
&
sub
,
&
sub_len
,
&
count
))
return
NULL
;
...
...
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