Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added
- Nag Mundari numeral system
- `available_systems` function
- `_validate_convert` function
### Changed
- `README.md` updated
- Test system modified
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
except ImportError:
from distutils.core import setup


def read_description() -> str:
"""Read README.md and CHANGELOG.md."""
try:
Expand Down
17 changes: 14 additions & 3 deletions xnum/functions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
"""XNum functions."""
import re
from typing import Match, List
from typing import Match, List, Any
from .params import NumeralSystem, NUMERAL_MAPS, ALL_DIGIT_MAPS
from .params import INVALID_SOURCE_MESSAGE, INVALID_TEXT_MESSAGE
from .params import INVALID_TARGET_MESSAGE1, INVALID_TARGET_MESSAGE2
Expand Down Expand Up @@ -32,9 +32,9 @@ def translate_digit(char: str, target: NumeralSystem) -> str:
return char


def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSystem.AUTO) -> str:
def _validate_convert(text: Any, target: Any, source: Any) -> bool:
"""
Convert function.
Validate convert inputs.

:param text: input text
:param target: target numeral system
Expand All @@ -48,7 +48,18 @@ def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSys
raise ValueError(INVALID_TARGET_MESSAGE2)
if not isinstance(source, NumeralSystem):
raise ValueError(INVALID_SOURCE_MESSAGE)
return True


def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSystem.AUTO) -> str:
"""
Convert function.

:param text: input text
:param target: target numeral system
:param source: source numeral system
"""
_validate_convert(text=text, target=target, source=source)
all_digits = list(ALL_DIGIT_MAPS.keys())
all_digits.sort(key=len, reverse=True)
pattern = r"(?:{})".format("|".join(re.escape(digit) for digit in all_digits))
Expand Down
Loading