@thomthom said:
Looks like it evaluates the string and treats the backslashes as special characters.
I had no end of troubles with slashes. Finally implemented this none-too-clever code and all the bugs went away:
=begin
qq() and qq!() do these replacements;
"'" -> "qq1"
'"' -> "qq2"
'/' -> "qq3"
'\' -> "qq4"
'\n' -> "qq5"
'\r' -> "qq6"
=end
def self.qq( str )
return str.gsub(
/\'/, 'qq1' ).gsub(
/\"/, 'qq2' ).gsub(
/\//, 'qq3' ).gsub(
/\\/, 'qq4' ).gsub(
/\n/, 'qq5' ).gsub(
/\r/, 'qq6' )
end # of qq()
def self.qq!( str )
str.gsub!( /\'/, 'qq1' )
str.gsub!( /\"/, 'qq2' )
str.gsub!( /\//, 'qq3' )
str.gsub!( /\\/, 'qq4' )
str.gsub!( /\n/, 'qq5' )
str.gsub!( /\r/, 'qq6' )
end # of qq!()
These reversers complete the Ruby:
def self.unqq( str ) # reverses qq()
return str.gsub(
/qq1/, '\'' ).gsub(
/qq2/, '"' ).gsub(
/qq3/, '/' ).gsub(
/qq4/, '\\' ).gsub(
/qq5/, '\n' ).gsub(
/qq6/, '\r' )
end # of unqq()
def self.unqq!( str ) # reverses qq!()
str.gsub!( /qq1/, '\'' )
str.gsub!( /qq2/, '"' )
str.gsub!( /qq3/, '/' )
str.gsub!( /qq4/, '\\' )
str.gsub!( /qq5/, '\n' )
str.gsub!( /qq6/, '\r' )
end # of unqq!()
These are the reversers in JavaScript:
single_quote = String.fromCharCode( 39 );
double_quote = String.fromCharCode( 34 );
ford_slash = String.fromCharCode( 47 );
back_slash = String.fromCharCode( 92 );
function unqq( msg ) {
s = msg.replace( /qq1/g, single_quote );
s = s.replace( /qq2/g, double_quote );
s = s.replace( /qq3/g, ford_slash );
s = s.replace( /qq4/g, back_slash );
s = s.replace( /qq5/g, '\\n' );
s = s.replace( /qq6/g, '\\r' );
return s;
}