Last active
August 29, 2015 14:01
-
-
Save beratdogan/97d0b9c3fedebf65bfca to your computer and use it in GitHub Desktop.
Coffee type extends
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::htmlspecialchars = (quote_style = 2, double_encode) -> | |
optTemp = 0 | |
i = 0 | |
noquotes = false | |
string = @.toString() | |
string = string.replace(/&/g, '&') if double_encode isnt false | |
string = string.replace(/</g, '<').replace(/>/g, '>') | |
OPTS = | |
ENT_NOQUOTES: 0 | |
ENT_HTML_QUOTE_SINGLE: 1 | |
ENT_HTML_QUOTE_DOUBLE: 2 | |
ENT_COMPAT: 2 | |
ENT_QUOTES: 3 | |
ENT_IGNORE: 4 | |
noquotes = true if quote_style is 0 | |
if typeof quote_style isnt 'number' | |
quote_style = [].concat(quote_style) | |
for style in [0...quote_style] | |
if OPTS[style] is 0 | |
noquotes = true | |
else if OPTS[style] | |
optTemp = optTemp | OPTS[style] | |
quote_style = optTemp | |
string = string.replace(/'/g, ''') if quote_style & OPTS.ENT_HTML_QUOTE_SINGLE | |
string = string.replace(/"/g, '"') if !noquotes | |
string |
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::stripslashes = -> | |
(@ + '').replace(/\\(.?)/g, (s, n1) -> | |
switch n1 | |
when '\\' then return '\\' | |
when '0' then return '\u0000' | |
when '' then return '' | |
else return n1 | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment