Created
December 7, 2011 04:51
-
-
Save jeffmccune/1441513 to your computer and use it in GitHub Desktop.
Urge to kill rising...
This file contains hidden or 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
class String | |
ZAML_ESCAPES = %w{\x00 \x01 \x02 \x03 \x04 \x05 \x06 \a \x08 \t \n \v \f \r \x0e \x0f \x10 \x11 \x12 \x13 \x14 \x15 \x16 \x17 \x18 \x19 \x1a \e \x1c \x1d \x1e \x1f } | |
def escaped_for_zaml | |
gsub( /\x5C/u, "\\\\\\" ). # Demi-kludge for Maglev/rubinius; the regexp should be /\\/ but parsetree chokes on that. | |
gsub( /"/u, "\\\"" ). | |
gsub( /([\x00-\x1F])/u ) { |x| ZAML_ESCAPES[ x.unpack("C")[0] ] }. | |
gsub( /([\x80-\xFF])/n ) { |x| "\\x#{x.unpack("C")[0].to_s(16)}" } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment