Skip to content

Instantly share code, notes, and snippets.

@sbehrens
Created August 22, 2012 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sbehrens/3427871 to your computer and use it in GitHub Desktop.
Save sbehrens/3427871 to your computer and use it in GitHub Desktop.
def decode_string(x, f):
colon = x.index(':', f)
try:
n = int(x[f:colon])
except (OverflowError, ValueError):
n = long(x[f:colon])
if x[f] == '0' and colon != f+1:
raise ValueError
colon += 1
return (x[colon:colon+n], colon+n)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment