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
93eff6fe
Kaydet (Commit)
93eff6fe
authored
May 30, 2006
tarafından
Fredrik Lundh
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
changed find/rfind to return -1 for matches outside the source string
üst
9faa3eda
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
10 deletions
+19
-10
string_tests.py
Lib/test/string_tests.py
+8
-0
find.h
Objects/stringlib/find.h
+11
-10
No files found.
Lib/test/string_tests.py
Dosyayı görüntüle @
93eff6fe
...
@@ -154,6 +154,10 @@ class CommonTest(unittest.TestCase):
...
@@ -154,6 +154,10 @@ class CommonTest(unittest.TestCase):
self
.
checkequal
(
9
,
'abcdefghiabc'
,
'find'
,
'abc'
,
1
)
self
.
checkequal
(
9
,
'abcdefghiabc'
,
'find'
,
'abc'
,
1
)
self
.
checkequal
(
-
1
,
'abcdefghiabc'
,
'find'
,
'def'
,
4
)
self
.
checkequal
(
-
1
,
'abcdefghiabc'
,
'find'
,
'def'
,
4
)
self
.
checkequal
(
0
,
'abc'
,
'find'
,
''
,
0
)
self
.
checkequal
(
3
,
'abc'
,
'find'
,
''
,
3
)
self
.
checkequal
(
-
1
,
'abc'
,
'find'
,
''
,
4
)
self
.
checkraises
(
TypeError
,
'hello'
,
'find'
)
self
.
checkraises
(
TypeError
,
'hello'
,
'find'
)
self
.
checkraises
(
TypeError
,
'hello'
,
'find'
,
42
)
self
.
checkraises
(
TypeError
,
'hello'
,
'find'
,
42
)
...
@@ -188,6 +192,10 @@ class CommonTest(unittest.TestCase):
...
@@ -188,6 +192,10 @@ class CommonTest(unittest.TestCase):
self
.
checkequal
(
0
,
'abcdefghiabc'
,
'rfind'
,
'abcd'
)
self
.
checkequal
(
0
,
'abcdefghiabc'
,
'rfind'
,
'abcd'
)
self
.
checkequal
(
-
1
,
'abcdefghiabc'
,
'rfind'
,
'abcz'
)
self
.
checkequal
(
-
1
,
'abcdefghiabc'
,
'rfind'
,
'abcz'
)
self
.
checkequal
(
3
,
'abc'
,
'rfind'
,
''
,
0
)
self
.
checkequal
(
3
,
'abc'
,
'rfind'
,
''
,
3
)
self
.
checkequal
(
-
1
,
'abc'
,
'rfind'
,
''
,
4
)
self
.
checkraises
(
TypeError
,
'hello'
,
'rfind'
)
self
.
checkraises
(
TypeError
,
'hello'
,
'rfind'
)
self
.
checkraises
(
TypeError
,
'hello'
,
'rfind'
,
42
)
self
.
checkraises
(
TypeError
,
'hello'
,
'rfind'
,
42
)
...
...
Objects/stringlib/find.h
Dosyayı görüntüle @
93eff6fe
...
@@ -14,8 +14,11 @@ stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
...
@@ -14,8 +14,11 @@ stringlib_find(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
{
{
Py_ssize_t
pos
;
Py_ssize_t
pos
;
if
(
sub_len
==
0
)
if
(
sub_len
==
0
)
{
if
(
str_len
<
0
)
return
-
1
;
return
offset
;
return
offset
;
}
pos
=
fastsearch
(
str
,
str_len
,
sub
,
sub_len
,
FAST_SEARCH
);
pos
=
fastsearch
(
str
,
str_len
,
sub
,
sub_len
,
FAST_SEARCH
);
...
@@ -30,22 +33,20 @@ stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
...
@@ -30,22 +33,20 @@ stringlib_rfind(const STRINGLIB_CHAR* str, Py_ssize_t str_len,
const
STRINGLIB_CHAR
*
sub
,
Py_ssize_t
sub_len
,
const
STRINGLIB_CHAR
*
sub
,
Py_ssize_t
sub_len
,
Py_ssize_t
offset
)
Py_ssize_t
offset
)
{
{
Py_ssize_t
pos
;
/* XXX - create reversefastsearch helper! */
/* XXX - create reversefastsearch helper! */
if
(
sub_len
==
0
)
if
(
sub_len
==
0
)
{
pos
=
str_len
+
offset
;
if
(
str_len
<
0
)
else
{
return
-
1
;
Py_ssize_t
j
;
return
str_len
+
offset
;
pos
=
-
1
;
}
else
{
Py_ssize_t
j
,
pos
=
-
1
;
for
(
j
=
str_len
-
sub_len
;
j
>=
0
;
--
j
)
for
(
j
=
str_len
-
sub_len
;
j
>=
0
;
--
j
)
if
(
STRINGLIB_CMP
(
str
+
j
,
sub
,
sub_len
)
==
0
)
{
if
(
STRINGLIB_CMP
(
str
+
j
,
sub
,
sub_len
)
==
0
)
{
pos
=
j
+
offset
;
pos
=
j
+
offset
;
break
;
break
;
}
}
}
return
pos
;
return
pos
;
}
}
}
Py_LOCAL_INLINE
(
Py_ssize_t
)
Py_LOCAL_INLINE
(
Py_ssize_t
)
...
...
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