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
7b7c5786
Kaydet (Commit)
7b7c5786
authored
Mar 14, 1997
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add optional 4th argument to [r]find and [r]index (end of slice).
üst
612316f0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
99 additions
and
43 deletions
+99
-43
libstring.tex
Doc/lib/libstring.tex
+10
-7
libstring.tex
Doc/libstring.tex
+10
-7
string.py
Lib/string.py
+26
-10
stringold.py
Lib/stringold.py
+26
-10
stropmodule.c
Modules/stropmodule.c
+27
-9
No files found.
Doc/lib/libstring.tex
Dosyayı görüntüle @
7b7c5786
...
...
@@ -103,24 +103,27 @@ This doesn't understand other non-printing characters or escape
sequences.
\end{funcdesc}
\begin{funcdesc}
{
find
}{
s
\,
sub
\optional
{
\,
start
}}
Return the lowest index in
\var
{
s
}
not smaller than
\var
{
start
}
where the
substring
\var
{
sub
}
is found. Return
\code
{
-1
}
when
\var
{
sub
}
does not occur as a substring of
\var
{
s
}
with index at least
\var
{
start
}
.
\begin{funcdesc}
{
find
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}}}
Return the lowest index in
\var
{
s
}
not smaller than
\var
{
start
}
and not
greater than
\var
{
end
}
where the substring
\var
{
sub
}
is found. Return
\code
{
-1
}
when
\var
{
sub
}
does not occur as a substring of
\var
{
s
}
with
index at least
\var
{
start
}
and less than
\var
{
end
}
.
If
\var
{
start
}
is omitted, it defaults to
\code
{
0
}
. If
\var
{
start
}
is
negative,
\code
{
len(
\var
{
s
}
)
}
is added.
If
\var
{
end
}
is omitted, it defaults to
\code
{
len(
\var
{
s
}
)
}
. If
\var
{
end
}
is negative,
\code
{
len(
\var
{
s
}
)
}
is added.
\end{funcdesc}
\begin{funcdesc}
{
rfind
}{
s
\,
sub
\optional
{
\,
start
}}
\begin{funcdesc}
{
rfind
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}
}}
Like
\code
{
find
}
but find the highest index.
\end{funcdesc}
\begin{funcdesc}
{
index
}{
s
\,
sub
\optional
{
\,
start
}}
\begin{funcdesc}
{
index
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}
}}
Like
\code
{
find
}
but raise
\code
{
ValueError
}
when the substring is
not found.
\end{funcdesc}
\begin{funcdesc}
{
rindex
}{
s
\,
sub
\optional
{
\,
start
}}
\begin{funcdesc}
{
rindex
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}
}}
Like
\code
{
rfind
}
but raise
\code
{
ValueError
}
when the substring is
not found.
\end{funcdesc}
...
...
Doc/libstring.tex
Dosyayı görüntüle @
7b7c5786
...
...
@@ -103,24 +103,27 @@ This doesn't understand other non-printing characters or escape
sequences.
\end{funcdesc}
\begin{funcdesc}
{
find
}{
s
\,
sub
\optional
{
\,
start
}}
Return the lowest index in
\var
{
s
}
not smaller than
\var
{
start
}
where the
substring
\var
{
sub
}
is found. Return
\code
{
-1
}
when
\var
{
sub
}
does not occur as a substring of
\var
{
s
}
with index at least
\var
{
start
}
.
\begin{funcdesc}
{
find
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}}}
Return the lowest index in
\var
{
s
}
not smaller than
\var
{
start
}
and not
greater than
\var
{
end
}
where the substring
\var
{
sub
}
is found. Return
\code
{
-1
}
when
\var
{
sub
}
does not occur as a substring of
\var
{
s
}
with
index at least
\var
{
start
}
and less than
\var
{
end
}
.
If
\var
{
start
}
is omitted, it defaults to
\code
{
0
}
. If
\var
{
start
}
is
negative,
\code
{
len(
\var
{
s
}
)
}
is added.
If
\var
{
end
}
is omitted, it defaults to
\code
{
len(
\var
{
s
}
)
}
. If
\var
{
end
}
is negative,
\code
{
len(
\var
{
s
}
)
}
is added.
\end{funcdesc}
\begin{funcdesc}
{
rfind
}{
s
\,
sub
\optional
{
\,
start
}}
\begin{funcdesc}
{
rfind
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}
}}
Like
\code
{
find
}
but find the highest index.
\end{funcdesc}
\begin{funcdesc}
{
index
}{
s
\,
sub
\optional
{
\,
start
}}
\begin{funcdesc}
{
index
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}
}}
Like
\code
{
find
}
but raise
\code
{
ValueError
}
when the substring is
not found.
\end{funcdesc}
\begin{funcdesc}
{
rindex
}{
s
\,
sub
\optional
{
\,
start
}}
\begin{funcdesc}
{
rindex
}{
s
\,
sub
\optional
{
\,
start
\optional
{
\,
end
}
}}
Like
\code
{
rfind
}
but raise
\code
{
ValueError
}
when the substring is
not found.
\end{funcdesc}
...
...
Lib/string.py
Dosyayı görüntüle @
7b7c5786
...
...
@@ -120,15 +120,17 @@ def joinfields(words, sep = ' '):
return
res
[
len
(
sep
):]
# Find substring, raise exception if not found
def
index
(
s
,
sub
,
i
=
0
):
res
=
find
(
s
,
sub
,
i
)
def
index
(
s
,
sub
,
i
=
0
,
last
=
None
):
if
last
==
None
:
last
=
len
(
s
)
res
=
find
(
s
,
sub
,
i
,
last
)
if
res
<
0
:
raise
ValueError
,
'substring not found in string.index'
return
res
# Find last substring, raise exception if not found
def
rindex
(
s
,
sub
,
i
=
0
):
res
=
rfind
(
s
,
sub
,
i
)
def
rindex
(
s
,
sub
,
i
=
0
,
last
=
None
):
if
last
==
None
:
last
=
len
(
s
)
res
=
rfind
(
s
,
sub
,
i
,
last
)
if
res
<
0
:
raise
ValueError
,
'substring not found in string.index'
return
res
...
...
@@ -149,20 +151,34 @@ def count(s, sub, i = 0):
return
r
# Find substring, return -1 if not found
def
find
(
s
,
sub
,
i
=
0
):
if
i
<
0
:
i
=
max
(
0
,
i
+
len
(
s
))
def
find
(
s
,
sub
,
i
=
0
,
last
=
None
):
Slen
=
len
(
s
)
# cache this value, for speed
if
last
==
None
:
last
=
Slen
elif
last
<
0
:
last
=
max
(
0
,
last
+
Slen
)
elif
last
>
Slen
:
last
=
Slen
if
i
<
0
:
i
=
max
(
0
,
i
+
Slen
)
n
=
len
(
sub
)
m
=
l
en
(
s
)
+
1
-
n
m
=
l
ast
+
1
-
n
while
i
<
m
:
if
sub
==
s
[
i
:
i
+
n
]:
return
i
i
=
i
+
1
return
-
1
# Find last substring, return -1 if not found
def
rfind
(
s
,
sub
,
i
=
0
):
if
i
<
0
:
i
=
max
(
0
,
i
+
len
(
s
))
def
rfind
(
s
,
sub
,
i
=
0
,
last
=
None
):
Slen
=
len
(
s
)
# cache this value, for speed
if
last
==
None
:
last
=
Slen
elif
last
<
0
:
last
=
max
(
0
,
last
+
Slen
)
elif
last
>
Slen
:
last
=
Slen
if
i
<
0
:
i
=
max
(
0
,
i
+
Slen
)
n
=
len
(
sub
)
m
=
l
en
(
s
)
+
1
-
n
m
=
l
ast
+
1
-
n
r
=
-
1
while
i
<
m
:
if
sub
==
s
[
i
:
i
+
n
]:
r
=
i
...
...
Lib/stringold.py
Dosyayı görüntüle @
7b7c5786
...
...
@@ -120,15 +120,17 @@ def joinfields(words, sep = ' '):
return
res
[
len
(
sep
):]
# Find substring, raise exception if not found
def
index
(
s
,
sub
,
i
=
0
):
res
=
find
(
s
,
sub
,
i
)
def
index
(
s
,
sub
,
i
=
0
,
last
=
None
):
if
last
==
None
:
last
=
len
(
s
)
res
=
find
(
s
,
sub
,
i
,
last
)
if
res
<
0
:
raise
ValueError
,
'substring not found in string.index'
return
res
# Find last substring, raise exception if not found
def
rindex
(
s
,
sub
,
i
=
0
):
res
=
rfind
(
s
,
sub
,
i
)
def
rindex
(
s
,
sub
,
i
=
0
,
last
=
None
):
if
last
==
None
:
last
=
len
(
s
)
res
=
rfind
(
s
,
sub
,
i
,
last
)
if
res
<
0
:
raise
ValueError
,
'substring not found in string.index'
return
res
...
...
@@ -149,20 +151,34 @@ def count(s, sub, i = 0):
return
r
# Find substring, return -1 if not found
def
find
(
s
,
sub
,
i
=
0
):
if
i
<
0
:
i
=
max
(
0
,
i
+
len
(
s
))
def
find
(
s
,
sub
,
i
=
0
,
last
=
None
):
Slen
=
len
(
s
)
# cache this value, for speed
if
last
==
None
:
last
=
Slen
elif
last
<
0
:
last
=
max
(
0
,
last
+
Slen
)
elif
last
>
Slen
:
last
=
Slen
if
i
<
0
:
i
=
max
(
0
,
i
+
Slen
)
n
=
len
(
sub
)
m
=
l
en
(
s
)
+
1
-
n
m
=
l
ast
+
1
-
n
while
i
<
m
:
if
sub
==
s
[
i
:
i
+
n
]:
return
i
i
=
i
+
1
return
-
1
# Find last substring, return -1 if not found
def
rfind
(
s
,
sub
,
i
=
0
):
if
i
<
0
:
i
=
max
(
0
,
i
+
len
(
s
))
def
rfind
(
s
,
sub
,
i
=
0
,
last
=
None
):
Slen
=
len
(
s
)
# cache this value, for speed
if
last
==
None
:
last
=
Slen
elif
last
<
0
:
last
=
max
(
0
,
last
+
Slen
)
elif
last
>
Slen
:
last
=
Slen
if
i
<
0
:
i
=
max
(
0
,
i
+
Slen
)
n
=
len
(
sub
)
m
=
l
en
(
s
)
+
1
-
n
m
=
l
ast
+
1
-
n
r
=
-
1
while
i
<
m
:
if
sub
==
s
[
i
:
i
+
n
]:
r
=
i
...
...
Modules/stropmodule.c
Dosyayı görüntüle @
7b7c5786
...
...
@@ -33,6 +33,12 @@ PERFORMANCE OF THIS SOFTWARE.
#include "Python.h"
#ifdef HAVE_LIMITS_H
#include <limits.h>
#else
#define INT_MAX 2147483647
#endif
#include <ctype.h>
/* XXX This file assumes that the <ctype.h> is*() functions
XXX are defined for all 8-bit characters! */
...
...
@@ -286,11 +292,17 @@ strop_find(self, args)
PyObject
*
args
;
{
char
*
s
,
*
sub
;
int
len
,
n
,
i
=
0
;
int
len
,
n
,
i
=
0
,
last
=
INT_MAX
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#s#|i
"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
))
if
(
!
PyArg_ParseTuple
(
args
,
"s#s#|i
i"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
return
NULL
;
if
(
last
>
len
)
last
=
len
;
if
(
last
<
0
)
last
+=
len
;
if
(
last
<
0
)
last
=
0
;
if
(
i
<
0
)
i
+=
len
;
if
(
i
<
0
)
...
...
@@ -299,8 +311,8 @@ strop_find(self, args)
if
(
n
==
0
)
return
PyInt_FromLong
((
long
)
i
);
l
en
-=
n
;
for
(;
i
<=
l
en
;
++
i
)
l
ast
-=
n
;
for
(;
i
<=
l
ast
;
++
i
)
if
(
s
[
i
]
==
sub
[
0
]
&&
(
n
==
1
||
memcmp
(
&
s
[
i
+
1
],
&
sub
[
1
],
n
-
1
)
==
0
))
return
PyInt_FromLong
((
long
)
i
);
...
...
@@ -316,20 +328,26 @@ strop_rfind(self, args)
{
char
*
s
,
*
sub
;
int
len
,
n
,
j
;
int
i
=
0
;
int
i
=
0
,
last
=
INT_MAX
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#s#|i
"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
))
if
(
!
PyArg_ParseTuple
(
args
,
"s#s#|i
i"
,
&
s
,
&
len
,
&
sub
,
&
n
,
&
i
,
&
last
))
return
NULL
;
if
(
last
>
len
)
last
=
len
;
if
(
last
<
0
)
last
+=
len
;
if
(
last
<
0
)
last
=
0
;
if
(
i
<
0
)
i
+=
len
;
if
(
i
<
0
)
i
=
0
;
if
(
n
==
0
)
return
PyInt_FromLong
((
long
)
l
en
);
return
PyInt_FromLong
((
long
)
l
ast
);
for
(
j
=
l
en
-
n
;
j
>=
i
;
--
j
)
for
(
j
=
l
ast
-
n
;
j
>=
i
;
--
j
)
if
(
s
[
j
]
==
sub
[
0
]
&&
(
n
==
1
||
memcmp
(
&
s
[
j
+
1
],
&
sub
[
1
],
n
-
1
)
==
0
))
return
PyInt_FromLong
((
long
)
j
);
...
...
@@ -663,7 +681,7 @@ strop_atof(self, args)
errno
=
0
;
PyFPE_START_PROTECT
(
"strop_atof"
,
return
0
)
x
=
strtod
(
s
,
&
end
);
PyFPE_END_PROTECT
PyFPE_END_PROTECT
(
x
)
while
(
*
end
&&
isspace
(
Py_CHARMASK
(
*
end
)))
end
++
;
if
(
*
end
!=
'\0'
)
{
...
...
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