-
-
Save RX14/e2dd192c7cb0e7cfb2278c2c46f3bea3 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
pp string | |
string.each_byte do |byte| | |
p byte <= 0x1F | |
case byte | |
when '\t'.ord, ' '.ord, '"'.ord, '\\'.ord | |
io << '\\' | |
when byte <= 0x1F, 0x7F | |
raise ArgumentError.new("String contained invalid character #{byte.chr.inspect}") | |
end | |
io.write_byte byte | |
end |
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
string # => "foo\u{0}bar" | |
false | |
false | |
false | |
true | |
false | |
false | |
false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment