Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
9.2.2023: Due to updates GitLab will be unavailable for some minutes between 9:00 and 11:00.
Open sidebar
badw-it
DHParser
Commits
31563eba
Commit
31563eba
authored
Oct 26, 2018
by
di68kap
Browse files
- stringview: added "endswith()", corrected type information in startswith and endswith
parent
39f232e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
DHParser/stringview.py
View file @
31563eba
...
...
@@ -194,18 +194,29 @@ class StringView(collections.abc.Sized):
return
self
.
text
.
rfind
(
sub
,
self
.
begin
+
start
,
self
.
begin
+
end
)
-
self
.
begin
def
startswith
(
self
,
prefix
:
Union
[
str
,
Tuple
[
str
,
...]]
,
prefix
:
str
,
start
:
int
=
0
,
end
:
Optional
[
int
]
=
None
)
->
bool
:
"""Return True if S starts with the specified prefix, False otherwise.
With optional `start`, test S beginning at that position.
With optional `end`, stop comparing S at that position.
prefix can also be a tuple of strings to try.
"""
start
+=
self
.
begin
end
=
self
.
end
if
end
is
None
else
self
.
begin
+
end
return
self
.
text
.
startswith
(
prefix
,
start
,
end
)
def
endswith
(
self
,
suffix
:
str
,
start
:
int
=
0
,
end
:
Optional
[
int
]
=
None
)
->
bool
:
"""Return True if S ends with the specified suufix, False otherwise.
With optional `start`, test S beginning at that position.
With optional `end`, stop comparing S at that position.
"""
start
+=
self
.
begin
end
=
self
.
end
if
end
is
None
else
self
.
begin
+
end
return
self
.
text
.
endswith
(
suffix
,
start
,
end
)
def
match
(
self
,
regex
,
flags
=
0
):
"""Executes `regex.match` on the StringView object and returns the
result, which is either a match-object or None. Keep in mind that
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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