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
d5bcf9a3
Commit
d5bcf9a3
authored
Oct 06, 1998
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Andrew Dalke's implementation of string.count().
parent
3836503a
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
Modules/stropmodule.c
Modules/stropmodule.c
+47
-0
No files found.
Modules/stropmodule.c
View file @
d5bcf9a3
...
...
@@ -617,6 +617,52 @@ strop_capitalize(self, args)
}
static
char
count__doc__
[]
=
"count(s, sub[, start[, end]]) -> int
\n
\
\n
\
Return the number of occurrences of substring sub in string
\n
\
s[start:end]. Optional arguments start and end are
\n
\
interpreted as in slice notation."
;
static
PyObject
*
strop_count
(
self
,
args
)
PyObject
*
self
;
/* Not used */
PyObject
*
args
;
{
char
*
s
,
*
sub
;
int
len
,
n
,
j
;
int
i
=
0
,
last
=
INT_MAX
;
int
m
,
r
;
if
(
!
PyArg_ParseTuple
(
args
,
"s#s#|ii"
,
&
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
;
m
=
last
+
1
-
n
;
if
(
n
==
0
)
return
PyInt_FromLong
((
long
)
(
m
-
i
));
r
=
0
;
while
(
i
<
m
)
{
if
(
!
memcmp
(
s
+
i
,
sub
,
n
))
{
r
++
;
i
+=
n
;
}
else
{
i
++
;
}
}
return
PyInt_FromLong
((
long
)
r
);
}
static
char
swapcase__doc__
[]
=
"swapcase(s) -> string
\n
\
\n
\
...
...
@@ -1122,6 +1168,7 @@ strop_methods[] = {
{
"atoi"
,
strop_atoi
,
1
,
atoi__doc__
},
{
"atol"
,
strop_atol
,
1
,
atol__doc__
},
{
"capitalize"
,
strop_capitalize
,
0
,
capitalize__doc__
},
{
"count"
,
strop_count
,
1
,
count__doc__
},
{
"find"
,
strop_find
,
1
,
find__doc__
},
{
"join"
,
strop_joinfields
,
1
,
joinfields__doc__
},
{
"joinfields"
,
strop_joinfields
,
1
,
joinfields__doc__
},
...
...
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