MCPcopy Index your code
hub / github.com/clips/pattern / decode_string

Function decode_string

pattern/vector/__init__.py:62–73  ·  view source on GitHub ↗

Returns the given value as a Unicode string (if possible).

(v, encoding="utf-8")

Source from the content-addressed store, hash-verified

60# assigned to these code points.
61
62def decode_string(v, encoding="utf-8"):
63 """ Returns the given value as a Unicode string (if possible).
64 """
65 if isinstance(encoding, basestring):
66 encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore"))
67 if isinstance(v, str):
68 for e in encoding:
69 try: return v.decode(*e)
70 except:
71 pass
72 return v
73 return unicode(v)
74
75def encode_string(v, encoding="utf-8"):
76 """ Returns the given value as a Python byte string (if possible).

Callers

nothing calls this directly

Calls 1

decodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…