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
2d96f11d
Kaydet (Commit)
2d96f11d
authored
Tem 08, 2001
tarafından
Fredrik Lundh
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
map re.sub() to string.replace(), when possible
üst
44835d8e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
12 deletions
+40
-12
sre.py
Lib/sre.py
+17
-12
_sre.c
Modules/_sre.c
+23
-0
No files found.
Lib/sre.py
Dosyayı görüntüle @
2d96f11d
...
...
@@ -159,42 +159,47 @@ def _expand(pattern, match, template):
template
=
sre_parse
.
parse_template
(
template
,
pattern
)
return
sre_parse
.
expand_template
(
template
,
match
)
def
_sub
(
pattern
,
template
,
string
,
count
=
0
):
def
_sub
(
pattern
,
template
,
text
,
count
=
0
):
# internal: pattern.sub implementation hook
return
_subn
(
pattern
,
template
,
string
,
count
)[
0
]
return
_subn
(
pattern
,
template
,
text
,
count
,
1
)[
0
]
def
_subn
(
pattern
,
template
,
string
,
count
=
0
):
def
_subn
(
pattern
,
template
,
text
,
count
=
0
,
sub
=
0
):
# internal: pattern.subn implementation hook
if
callable
(
template
):
filter
=
template
else
:
template
=
_compile_repl
(
template
,
pattern
)
literals
=
template
[
1
]
if
(
sub
and
not
count
and
pattern
.
_isliteral
()
and
len
(
literals
)
==
1
and
literals
[
0
]):
# shortcut: both pattern and string are literals
return
string
.
replace
(
text
,
pattern
.
pattern
,
literals
[
0
]),
0
def
filter
(
match
,
template
=
template
):
return
sre_parse
.
expand_template
(
template
,
match
)
n
=
i
=
0
s
=
[]
append
=
s
.
append
c
=
pattern
.
scanner
(
string
)
c
=
pattern
.
scanner
(
text
)
while
not
count
or
n
<
count
:
m
=
c
.
search
()
if
not
m
:
break
b
,
e
=
m
.
span
()
if
i
<
b
:
append
(
string
[
i
:
b
])
append
(
text
[
i
:
b
])
append
(
filter
(
m
))
i
=
e
n
=
n
+
1
append
(
string
[
i
:])
return
_join
(
s
,
string
[:
0
]),
n
append
(
text
[
i
:])
return
_join
(
s
,
text
[:
0
]),
n
def
_split
(
pattern
,
string
,
maxsplit
=
0
):
def
_split
(
pattern
,
text
,
maxsplit
=
0
):
# internal: pattern.split implementation hook
n
=
i
=
0
s
=
[]
append
=
s
.
append
extend
=
s
.
extend
c
=
pattern
.
scanner
(
string
)
c
=
pattern
.
scanner
(
text
)
g
=
pattern
.
groups
while
not
maxsplit
or
n
<
maxsplit
:
m
=
c
.
search
()
...
...
@@ -202,15 +207,15 @@ def _split(pattern, string, maxsplit=0):
break
b
,
e
=
m
.
span
()
if
b
==
e
:
if
i
>=
len
(
string
):
if
i
>=
len
(
text
):
break
continue
append
(
string
[
i
:
b
])
append
(
text
[
i
:
b
])
if
g
and
b
!=
e
:
extend
(
list
(
m
.
groups
()))
i
=
e
n
=
n
+
1
append
(
string
[
i
:])
append
(
text
[
i
:])
return
s
# register myself for pickling
...
...
Modules/_sre.c
Dosyayı görüntüle @
2d96f11d
...
...
@@ -1955,6 +1955,28 @@ pattern_deepcopy(PatternObject* self, PyObject* args)
#endif
}
static
PyObject
*
pattern_isliteral
(
PatternObject
*
self
,
PyObject
*
args
)
{
/* internal: return true if pattern consists of literal text only */
SRE_CODE
*
code
;
PyObject
*
isliteral
;
if
(
!
PyArg_ParseTuple
(
args
,
":_isliteral"
))
return
NULL
;
code
=
PatternObject_GetCode
(
self
);
if
(
code
[
0
]
==
SRE_OP_INFO
&&
code
[
2
]
&
SRE_INFO_LITERAL
)
isliteral
=
Py_True
;
else
isliteral
=
Py_False
;
Py_INCREF
(
isliteral
);
return
isliteral
;
}
static
PyMethodDef
pattern_methods
[]
=
{
{
"match"
,
(
PyCFunction
)
pattern_match
,
METH_VARARGS
|
METH_KEYWORDS
},
{
"search"
,
(
PyCFunction
)
pattern_search
,
METH_VARARGS
|
METH_KEYWORDS
},
...
...
@@ -1965,6 +1987,7 @@ static PyMethodDef pattern_methods[] = {
{
"scanner"
,
(
PyCFunction
)
pattern_scanner
,
METH_VARARGS
},
{
"__copy__"
,
(
PyCFunction
)
pattern_copy
,
METH_VARARGS
},
{
"__deepcopy__"
,
(
PyCFunction
)
pattern_deepcopy
,
METH_VARARGS
},
{
"_isliteral"
,
(
PyCFunction
)
pattern_isliteral
,
METH_VARARGS
},
{
NULL
,
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