-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add string utility functions #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||
| """String utility functions.""" | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def reverse_words(sentence: str) -> str: | ||||||||||||||||||||||
| return " ".join(sentence.split()[::-1]) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def count_vowels(text: str) -> int: | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docstring:
|
||||||||||||||||||||||
| return sum(1 for c in text.lower() if c in "aeiou") | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def truncate(text: str, max_length: int, suffix: str = "...") -> str: | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docstring:
|
||||||||||||||||||||||
| if len(text) <= max_length: | ||||||||||||||||||||||
| return text | ||||||||||||||||||||||
| return text[: max_length - len(suffix)] + suffix | ||||||||||||||||||||||
|
Comment on lines
+12
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: When Example: Add a guard at the top of the function:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing test coverage: No test covers the edge case where
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def to_snake_case(text: str) -> str: | ||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docstring:
|
||||||||||||||||||||||
| result = [] | ||||||||||||||||||||||
| for i, char in enumerate(text): | ||||||||||||||||||||||
| if char.isupper() and i > 0: | ||||||||||||||||||||||
| result.append("_") | ||||||||||||||||||||||
| result.append(char.lower()) | ||||||||||||||||||||||
| return "".join(result) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing docstring:
|
||||||||||||||||||||||
| def is_palindrome(text: str) -> bool: | ||||||||||||||||||||||
| cleaned = "".join(c.lower() for c in text if c.isalnum()) | ||||||||||||||||||||||
| return cleaned == cleaned[::-1] | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing docstring:
reverse_wordsis a public function and must have a docstring describing what it does, its parameters, and its return value (org guideline).