mirror of
https://github.com/i701/sarlink-portal-api.git
synced 2025-06-28 09:50:05 +00:00
Initial commit
This commit is contained in:
29
api/utils.py
Normal file
29
api/utils.py
Normal file
@ -0,0 +1,29 @@
|
||||
def reverse_dhivehi_string(input_str):
|
||||
"""
|
||||
Reverses a Dhivehi string while preserving character composition.
|
||||
|
||||
Args:
|
||||
input_str (str): The Dhivehi string to be reversed
|
||||
|
||||
Returns:
|
||||
str: The reversed Dhivehi string
|
||||
"""
|
||||
# Reverse the string and then normalize the character order
|
||||
reversed_str = input_str[::-1]
|
||||
|
||||
# List to store the corrected characters
|
||||
corrected_chars = []
|
||||
|
||||
# Iterate through the reversed string
|
||||
i = 0
|
||||
while i < len(reversed_str):
|
||||
# Check if current character is a combining character
|
||||
if i + 1 < len(reversed_str) and "\u0300" <= reversed_str[i + 1] <= "\u036F":
|
||||
# If next character is a combining mark, add it before the base character
|
||||
corrected_chars.append(reversed_str[i + 1] + reversed_str[i])
|
||||
i += 2
|
||||
else:
|
||||
corrected_chars.append(reversed_str[i])
|
||||
i += 1
|
||||
|
||||
return "".join(corrected_chars)
|
Reference in New Issue
Block a user