Skip to content
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

Make it better! #50

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading