mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-04-27 22:33:10 +09:00
Update String.prototype.trim and add String.prototype.escape
This commit is contained in:
parent
91ff3c6323
commit
5b017affa1
1 changed files with 18 additions and 3 deletions
|
|
@ -313,12 +313,27 @@ jQuery(function($) {
|
|||
};
|
||||
|
||||
/**
|
||||
* @brief string prototype으로 trim 함수 추가
|
||||
* @brief string prototype으로 escape 함수 추가
|
||||
**/
|
||||
String.prototype.trim = function() {
|
||||
return this.replace(/(^\s*)|(\s*$)/g, "");
|
||||
String.prototype.escape = function(double_escape) {
|
||||
var map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
||||
var revmap = { '&amp;': '&', '&lt;': '<', '&gt;': '>', '&quot;': '"', "&#039;": ''' };
|
||||
var result = String(this).replace(/[&<>"']/g, function(m) { return map[m]; });
|
||||
if (double_escape === false) {
|
||||
return result.replace(/&(amp|lt|gt|quot|#039);/g, function(m) { return revmap[m]; });
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief string prototype으로 trim 함수 추가
|
||||
**/
|
||||
if (!String.prototype.trim) {
|
||||
String.prototype.trim = function() {
|
||||
return String(this).replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
|
||||
};
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue