Skip to content

Instantly share code, notes, and snippets.

@cblavier
Created January 11, 2018 14:42
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 cblavier/9ff624d9afd3cdc5671786cfeefeb6ae to your computer and use it in GitHub Desktop.
Save cblavier/9ff624d9afd3cdc5671786cfeefeb6ae to your computer and use it in GitHub Desktop.
defmodule StringUtil do
def raw_binary_to_string(raw) do
raw
|> String.codepoints()
|> Enum.reduce(fn(w, result) ->
if String.valid?(w) do
result <> w
else
<< parsed :: 8>> = w
result <> << parsed :: utf8 >>
end
end)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment