Skip to content

Instantly share code, notes, and snippets.

@Arie
Last active December 16, 2015 12:58
Show Gist options
  • Save Arie/5437870 to your computer and use it in GitHub Desktop.
Save Arie/5437870 to your computer and use it in GitHub Desktop.
active support tidy_byte monkey patch
#Given this input string, tidy_bytes explodes
#L 04/22/2013 - 19:56:11: "★radist★<14><STEAM_0:0:21110245><Red>" say_team "[P-REC] Çàïèñü ïîù¸ëú"
#This horrible monkey patch fixes it:
module ActiveSupport
module Multibyte
module Unicode
def tidy_byte(byte)
if byte.is_a? Integer
if byte < 160
[database.cp1252[byte] || byte].pack("U").unpack("C*")
elsif byte < 192
[194, byte]
else
[195, byte - 64]
end
else
byte
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment