Guest User

Untitled

a guest
Jul 18th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def split(s):
  2. """split(s) -> list of strings
  3.  
  4. Return a list of the decoded netstrings in s.
  5. """
  6. v = {'0':0,'1':1,'2':2,'3':3,'4':4,'5':5,'6':6,'7':7,'8':8,'9':9}
  7. retval = []
  8. string = s
  9. cc = 0
  10. while cc < len(string):
  11. i = cc
  12. n = 0
  13. ch = string[i]
  14. while ch != ":":
  15. n = n * 10 + v[ch]
  16. i += 1
  17. ch = string[i]
  18.  
  19. parsed = string[i+1:i+1+n]
  20. retval.append(parsed)
  21. cc = i + n + 1 + 1
  22.  
  23. return retval
Add Comment
Please, Sign In to add comment