Created
May 10, 2011 14:38
-
-
Save think49/964592 to your computer and use it in GitHub Desktop.
to-hankaku.js, to-zenkaku.js : 半角文字/全角文字をそれぞれ変換する
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
/** | |
* to-hankaku.js | |
* convert to ascii code strings. | |
* | |
* @version 1.0.1 | |
* @author think49 | |
* @url https://gist.github.com/964592 | |
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License) | |
*/ | |
var toHankaku = (function (String, fromCharCode) { | |
function toHankaku (string) { | |
return String(string).replace(/\u2019/g, '\u0027').replace(/\u201D/g, '\u0022').replace(/\u3000/g, '\u0020').replace(/\uFFE5/g, '\u00A5').replace(/[\uFF01\uFF03-\uFF06\uFF08\uFF09\uFF0C-\uFF19\uFF1C-\uFF1F\uFF21-\uFF3B\uFF3D\uFF3F\uFF41-\uFF5B\uFF5D\uFF5E]/g, alphaNum); | |
} | |
function alphaNum (token) { | |
return fromCharCode(token.charCodeAt(0) - 65248); | |
} | |
return toHankaku; | |
})(String, String.fromCharCode); |
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
/** | |
* to-zenkaku.js | |
* convert to multi byte strings. | |
* | |
* @version 1.0.2 | |
* @author think49 | |
* @url https://gist.github.com/964592 | |
* @license http://www.opensource.org/licenses/mit-license.php (The MIT License) | |
*/ | |
var toZenkaku = (function (String, fromCharCode) { | |
function toZenkaku (string) { | |
return String(string).replace(/\u0020/g, '\u3000').replace(/\u0022/g, '\u201D').replace(/\u0027/g, '\u2019').replace(/\u00A5/g, '\uFFE5').replace(/[!#-&(),-9\u003C-?A-[\u005D_a-{}~]/g, alphaNum); | |
} | |
function alphaNum (token) { | |
return fromCharCode(token.charCodeAt(0) + 65248); | |
} | |
return toZenkaku; | |
})(String, String.fromCharCode); |
Author
think49
commented
May 10, 2011
- format-hankaku-zenkaku.js - Ideone.com
- 半角から全角文字列へ - babu_babu_babooのごみ箱
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment