neels has uploaded this change for review.

View Change

utils: add unrpad()

In pysim.esim.saip, some encoding steps use rpad(); here is the
counterpart, that will allow to also decode values back.

Related: SYS#6768
Change-Id: I48c23390926f8c9412624edb4481e7f4cd3f4b46
---
M src/osmocom/utils.py
1 file changed, 14 insertions(+), 0 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/00/39600/1
diff --git a/src/osmocom/utils.py b/src/osmocom/utils.py
index 5947453..e7053c1 100644
--- a/src/osmocom/utils.py
+++ b/src/osmocom/utils.py
@@ -121,6 +121,20 @@
return s + c * (l - len(s))


+def unrpad(s: str, c='f') -> str:
+ """unpad string on the right side -- reverse of rpad().
+ Args:
+ s : string to pad
+ c : padding character
+ Returns:
+ String 's' with all rightmost c stripped.
+ """
+ end = len(s)
+ while end > 0 and s[end - 1] == c:
+ end -= 1
+ return s[:end]
+
+
def lpad(s: str, l: int, c='f') -> str:
"""pad string on the left side.
Args:

To view, visit change 39600. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: I48c23390926f8c9412624edb4481e7f4cd3f4b46
Gerrit-Change-Number: 39600
Gerrit-PatchSet: 1
Gerrit-Owner: neels <nhofmeyr@sysmocom.de>