Handle StringIO#set_encoding for Ruby <= 1.9.2 and 1.9.3+.