11# -*- coding: utf-8 -*-
22"""XNum functions."""
33import re
4- from typing import Match , List
4+ from typing import Match , List , Any
55from .params import NumeralSystem , NUMERAL_MAPS , ALL_DIGIT_MAPS
66from .params import INVALID_SOURCE_MESSAGE , INVALID_TEXT_MESSAGE
77from .params import INVALID_TARGET_MESSAGE1 , INVALID_TARGET_MESSAGE2
@@ -32,9 +32,9 @@ def translate_digit(char: str, target: NumeralSystem) -> str:
3232 return char
3333
3434
35- def convert (text : str , target : NumeralSystem , source : NumeralSystem = NumeralSystem . AUTO ) -> str :
35+ def _validate_convert (text : Any , target : Any , source : Any ) -> bool :
3636 """
37- Convert function .
37+ Validate convert inputs .
3838
3939 :param text: input text
4040 :param target: target numeral system
@@ -48,7 +48,18 @@ def convert(text: str, target: NumeralSystem, source: NumeralSystem = NumeralSys
4848 raise ValueError (INVALID_TARGET_MESSAGE2 )
4949 if not isinstance (source , NumeralSystem ):
5050 raise ValueError (INVALID_SOURCE_MESSAGE )
51+ return True
52+
5153
54+ def convert (text : str , target : NumeralSystem , source : NumeralSystem = NumeralSystem .AUTO ) -> str :
55+ """
56+ Convert function.
57+
58+ :param text: input text
59+ :param target: target numeral system
60+ :param source: source numeral system
61+ """
62+ _validate_convert (text = text , target = target , source = source )
5263 all_digits = list (ALL_DIGIT_MAPS .keys ())
5364 all_digits .sort (key = len , reverse = True )
5465 pattern = r"(?:{})" .format ("|" .join (re .escape (digit ) for digit in all_digits ))
0 commit comments