Last active
February 1, 2018 11:36
-
-
Save to/71e875a61bf09d45cfe30ad78712e422 to your computer and use it in GitHub Desktop.
NFD/NFC
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
var Normalization = { | |
conds : [ | |
['\u3099', 78, '\u3094\u30F4'], | |
['\u3099', 1, 'がぎぐげござじずぜぞだぢづでどばびぶべぼガギグゲゴザジズゼゾダヂヅデドバビブベボ'], | |
['\u309A', 2, 'ぱぴぷぺぽパピプペポ'] | |
] | |
, | |
decompress : function(text){ | |
// 濁音/半濁音を分離する | |
Normalization.conds.forEach(function(cond){ | |
text = text.replace(new RegExp('[' + cond[2] + ']', 'g'), | |
function(part){ | |
return String.fromCharCode(part.charCodeAt(0) - cond[1]) + cond[0]; | |
}); | |
}); | |
return text; | |
} | |
, | |
compress : function(text){ | |
// 濁音/半濁音を合成する | |
Normalization.conds.forEach(function(cond){ | |
text = text.replace( | |
new RegExp('[' + cond[3] + ']' + cond[0], 'g'), | |
function(part){ | |
return String.fromCharCode(part.charCodeAt(0) + cond[1]); | |
}); | |
}); | |
return text; | |
} | |
} | |
// 濁音/半濁音を取り除いた文字列を準備する | |
Normalization.conds.forEach(function(cond){ | |
cond[3] = cond[2].replace(/./g, function(c){ | |
return String.fromCharCode(c.charCodeAt(0) - cond[1]); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment