Character encoding auto-detection. Ruby 1.9 compatible