forked from SyedGhazanferAnwar/MailGeek
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstring_utils.py
More file actions
33 lines (26 loc) · 898 Bytes
/
string_utils.py
File metadata and controls
33 lines (26 loc) · 898 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def reverse_string(input_string: str) -> str:
"""
Reverses the given input string using a manual character-by-character approach.
Args:
input_string (str): The string to be reversed.
Returns:
str: The reversed string.
Raises:
TypeError: If the input is not a string.
"""
# Check if input is a string
if not isinstance(input_string, str):
raise TypeError("Input must be a string")
# Handle empty string case
if len(input_string) <= 1:
return input_string
# Convert string to list for manipulation
chars = list(input_string)
# Use two-pointer technique to swap characters
left, right = 0, len(chars) - 1
while left < right:
chars[left], chars[right] = chars[right], chars[left]
left += 1
right -= 1
# Convert back to string
return ''.join(chars)