Created
January 11, 2018 14:42
-
-
Save cblavier/9ff624d9afd3cdc5671786cfeefeb6ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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