Skip to content

Commit

Permalink
Enhanced character conversion functions using regular expressions. (#50)
Browse files Browse the repository at this point in the history
* Enhanced character conversion functions using regular expressions.
* Improved date handling in Jalali date and time classes.
* Added new test cases for edge cases and date conversions.
  • Loading branch information
majiidd authored Jan 17, 2025
1 parent 0c0e801 commit e3a85b8
Show file tree
Hide file tree
Showing 8 changed files with 205 additions and 114 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@

# Changelog

## [5.2.0](https://github.com/majiidd/persiantools/compare/5.1.1...5.2.0) - 2025-01-17

- Enhanced character conversion functions using regular expressions.
- Improved date handling in Jalali date and time classes.
- Added new test cases for edge cases and date conversions.

## [5.1.1](https://github.com/majiidd/persiantools/compare/5.1.0...5.1.1) - 2025-01-16

- Improved leap year calculation for issue #48.

## [5.1.0](https://github.com/majiidd/persiantools/compare/5.0.0...5.1.0) - 2024-11-08

- Improved CI/CD pipeline run time through optimized caching.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2016-2024 Majid Hajiloo
Copyright (c) 2016-2025 Majid Hajiloo

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion persiantools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__title__ = "persiantools"
__url__ = "https://github.com/majiidd/persiantools"
__version__ = "5.1.1"
__version__ = "5.2.0"
__build__ = __version__
__author__ = "Majid Hajiloo"
__author_email__ = "majid.hajiloo@gmail.com"
Expand Down
9 changes: 6 additions & 3 deletions persiantools/characters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from persiantools.utils import replace
import re

CHARACTER_MAP_AR_TO_FA = {
"دِ": "د",
Expand All @@ -14,6 +14,9 @@

CHARACTER_MAP_FA_TO_AR = {"ی": "ي", "ک": "ك"}

AR_TO_FA_PATTERN = re.compile("|".join(map(re.escape, CHARACTER_MAP_AR_TO_FA.keys())))
FA_TO_AR_PATTERN = re.compile("|".join(map(re.escape, CHARACTER_MAP_FA_TO_AR.keys())))


def ar_to_fa(string: str) -> str:
"""
Expand All @@ -35,7 +38,7 @@ def ar_to_fa(string: str) -> str:
if not isinstance(string, str):
raise TypeError("Input must be of type str")

return replace(string, CHARACTER_MAP_AR_TO_FA)
return AR_TO_FA_PATTERN.sub(lambda match: CHARACTER_MAP_AR_TO_FA[match.group(0)], string)


def fa_to_ar(string: str) -> str:
Expand All @@ -58,4 +61,4 @@ def fa_to_ar(string: str) -> str:
if not isinstance(string, str):
raise TypeError("Input must be of type str")

return replace(string, CHARACTER_MAP_FA_TO_AR)
return FA_TO_AR_PATTERN.sub(lambda match: CHARACTER_MAP_FA_TO_AR[match.group(0)], string)
Loading

0 comments on commit e3a85b8

Please sign in to comment.