I think the following code will be convenient to have in prototype.js:
Object.extend(String.prototype, {
escapeJS: function() {
var text = "";
for (var i = 0, len = this.length; i < len; i++) {
var ch = this.charAt(i);
switch (ch) {
case '\b':
text += "\\b"
break;
case '\n':
text += "\\n"
break;
case '\t':
text += "\\t"
break;
case '\f':
text += "\\f"
break;
case '\r':
text += "\\r"
break;
case '\"':
text += "\\u0022"
break;
case '\'':
text += "\\u0027"
break;
case '\\':
text += "\\\\"
break;
default:
text += ch;
}
}
return text;
}
}
);
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---