diff --git a/string/metadata.txt b/string/metadata.txt index 7fd02826..6b5dc732 100644 --- a/string/metadata.txt +++ b/string/metadata.txt @@ -1,3 +1,3 @@ srctype=micropython-lib type=module -version=0.0.1 +version=0.1 diff --git a/string/setup.py b/string/setup.py index a0895c3c..a8cd9327 100644 --- a/string/setup.py +++ b/string/setup.py @@ -6,7 +6,7 @@ from setuptools import setup setup(name='micropython-string', - version='0.0.1', + version='0.1', description='string module for MicroPython', long_description="This is a module reimplemented specifically for MicroPython standard library,\nwith efficient and lean design in mind. Note that this module is likely work\nin progress and likely supports just a subset of CPython's corresponding\nmodule. Please help with the development if you are interested in this\nmodule.", url='https://github.com/micropython/micropython/issues/405', diff --git a/string/string.py b/string/string.py index dff21124..d8ed89e3 100644 --- a/string/string.py +++ b/string/string.py @@ -8,3 +8,19 @@ hexdigits = digits + 'abcdef' + 'ABCDEF' octdigits = '01234567' punctuation = """!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~""" printable = digits + ascii_letters + punctuation + whitespace + + +def translate(s, map): + import io + sb = io.StringIO() + for c in s: + v = ord(c) + if v in map: + v = map[v] + if isinstance(v, int): + sb.write(chr(v)) + elif v is not None: + sb.write(v) + else: + sb.write(c) + return sb.getvalue()