Arthur de Jong

Open Source / Free Software developer

summaryrefslogtreecommitdiffstats
path: root/stdnum/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'stdnum/util.py')
-rw-r--r--stdnum/util.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/stdnum/util.py b/stdnum/util.py
index 8fa082a..bbab8b0 100644
--- a/stdnum/util.py
+++ b/stdnum/util.py
@@ -1,7 +1,7 @@
# util.py - common utility functions
# coding: utf-8
#
-# Copyright (C) 2012-2018 Arthur de Jong
+# Copyright (C) 2012-2019 Arthur de Jong
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -35,9 +35,14 @@ import warnings
from stdnum.exceptions import *
+# Regular expression to match doctests in docstrings
_strip_doctest_re = re.compile(r'^>>> .*\Z', re.DOTALL | re.MULTILINE)
+# Regular expression to match digits
+_digits_re = re.compile(r'^[0-9]+$')
+
+
def _mk_char_map(mapping):
"""Transform a dictionary with comma separated uniode chracter names
to tuples with unicode characters as key."""
@@ -129,6 +134,13 @@ def clean(number, deletechars=''):
return ''.join(x for x in number if x not in deletechars)
+def isdigits(number):
+ """Check whether the provided string only consists of digits."""
+ # This function is meant to replace str.isdigit() which will also return
+ # True for all kind of unicode digits which is generally not what we want
+ return bool(_digits_re.match(number))
+
+
def to_unicode(text):
"""Convert the specified text to a unicode string."""
if not isinstance(text, type(u'')):