Commit 31563eba authored by di68kap's avatar di68kap
Browse files

- stringview: added "endswith()", corrected type information in startswith and endswith

parent 39f232e5
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment