Unicodeã¨ã¹ã±ã¼ã
付箋紙Greasemonkeyã§ãGM_setValueã«ç»é²ããæ¥æ¬èªã®æååã対çã«encodeURIãã¤ãã£ããã©ãencodeURIã¯URIãã¨ã³ã³ã¼ãããããã®é¢æ°ãªã®ã§ããã¾ãè¤ãããã使ãæ¹ã§ã¯ãªãã§ãããããããencodeURIã®ãããªURLã¨ã³ã³ã¼ãã£ã³ã°ã¯æååãUTF-8ã«ãã¦ãããã¨ã³ã³ã¼ã対象ã®åãã¤ãã%xxå½¢å¼*1ã§è¡¨ç¾ããã®ã§ãæ¥æ¬èªï¼æåãããããã®ã«ããã¦ãã®å ´åASCII9æåãå¿
è¦ã«ãªã£ã¦å¹çãæªãã§ãã*2
ãªã®ã§ãåè¿°ã®ãããªåã«éASCIIæåãã¨ã¹ã±ã¼ããããã ãã®ãããªã±ã¼ã¹ã§ã¯Unicodeã¨ã¹ã±ã¼ãã使ã£ãæ¹ãããã§ããJavaã®propertiesã¨ãnative2asciiã¨ãã®ãã¤ã§ãã
Unicodeã¨ã¹ã±ã¼ãã¯\uxxxx*3ã®å½¢å¼ã§ããããã®ã§ãããã¦ãã®æ¥æ¬èªï¼æåã¯ASCII6æåã«ãªã£ã¦ãURLã¨ã³ã³ã¼ãã£ã³ã°ã«æ¯ã¹ã¦3åã®2ãããã«å§ç¸®ã§ãã¾ããå°åå¯è½ãªASCIIè¨å·ã¨åè§ã¹ãã¼ã¹ãã¨ã¹ã±ã¼ãããªãã®ã§ãã®åãçããªããã
JavaScriptã«ã¯Unicodeã¨ã¹ã±ã¼ããããããã®æ¨æºé¢æ°ã¯åãã£ã¦ããªããã©*4ãStringã®ã³ã¼ã«ããã¯é¢æ°ã¤ãreplaceã¡ã½ããã使ãã°ã以ä¸ã®ããã«ç°¡åã«ä½ãã¾ãã
function escapeUnicode(str) { return str.replace(/[^ -~]|\\/g, function(m0) { var code = m0.charCodeAt(0); return '\\u' + ((code < 0x10)? '000' : (code < 0x100)? '00' : (code < 0x1000)? '0' : '') + code.toString(16); }); } function unescapeUnicode(str) { return str.replace(/\\u([a-fA-F0-9]{4})/g, function(m0, m1) { return String.fromCharCode(parseInt(m1, 16)); }); }
replaceé¢æ°ã«ã¤ãã¦è£è¶³
repalceã®ç¬¬ä¸å¼æ°ãæ£è¦è¡¨ç¾ã第äºå¼æ°ãç½®ææååã¾ãã¯ã³ã¼ã«ããã¯é¢æ°ã§ããã³ã¼ã«ããã¯é¢æ°ãæå®ããå ´åã¯ãæ£è¦è¡¨ç¾ãããããããã³ã«é¢æ°ãå¼ã³åºããã¾ãããã ããæ£è¦è¡¨ç¾ã« gãªãã·ã§ã³ãã¤ãã¦ããªãå ´åã¯ãæåã®ãããç®æããç½®æããã¾ããã
ã³ã¼ã«ããã¯é¢æ°ã«ã¯ãæ£è¦è¡¨ç¾å
ã®ã°ã«ã¼ãæ°ãNã¨ãã¦ãN+3åã®å¼æ°ã渡ããã¾ããfunctionã«æ示çã«å¼æ°ãªã¹ããå®ç¾©ãã¦åãåã£ã¦ããargumentsãªãã¸ã§ã¯ãããã¢ã¯ã»ã¹ãã¦ãOKã§ããå¼æ°ãªã¹ããå®ç¾©ããå ´åããä¸ã®escapseUnicodeé¢æ°ã§ã®ããã«å¿
è¦ãªåã ããå®ç¾©ããã°ããã§ãã
ããããã®å¼æ°ã®å
容ã¯ä»¥ä¸ã®éãã§ãã
arguments | å 容 |
---|---|
arguments[0] | ãããããç®æã®æåå |
arguments[1]ãarguments[N] | æ£è¦è¡¨ç¾ã®ã°ã«ã¼ãåç § |
arguments[N+1] | ãããããç®æã®ã¤ã³ããã¯ã¹ |
arguments[N+2] | replaceé¢æ°ãå¼ã³åºããæåå |
*1:xxã¯16é²æ°2æ¡
*2:ã¡ãªã¿ã«ãencodeURIã¨ããä¼¼ãencodeURIComponentã¨ããé¢æ°ããããéãã¯URIå ã§æå³ãæã¤è¨å·[/:?&;#]ãã¨ã¹ã±ã¼ããããããªãããencodeURIã¯ããããã¨ã¹ã±ã¼ãããªãããªã®ã§GETãã©ã¡ã¼ã¿ã«æå®ããæååã¯encodeURIComponentã使ã£ã¦ã¨ã³ã³ã¼ãããå¿ è¦ããããéã«ã©ããªå ´åã«encodeURIã使ãã¨ããã®ãã¯ããããããªã (^^;
*3:xxxxã¯16é²æ°4æ¡
*4:Unicodeã¨ã¹ã±ã¼ãã¨ï¼å®è£ ã«ãã£ã¦ã¯ï¼ããä¼¼ãã¨ã¹ã±ã¼ããããescape/unescapeé¢æ°ãJavascriptã«ã¯æ¨æºã§ããã¾ããããã©ã¦ã¶éã®äºææ§ãªã©ããããå¾®å¦ãªã®ã§ä»ã¯ãã¾ã使ããã¦ãã¾ããã