aboutsummaryrefslogtreecommitdiffstats
path: root/unicode.js
diff options
context:
space:
mode:
authoranekos2008-11-11 13:48:21 +0000
committeranekos2008-11-11 13:48:21 +0000
commit581a8ce00d3cb51ba349307526ceb7f82aeafefb (patch)
tree7b21d3cad26a7fdf27e3373e5d766cc6f8aa3898 /unicode.js
parent86731c66fc83c6b6fd567d5a9f5fb4e7f17719e7 (diff)
downloadvimperator-plugins-581a8ce00d3cb51ba349307526ceb7f82aeafefb.tar.bz2
Initial release: Unicodeエスケープしてクリップボードにコピーする
git-svn-id: http://svn.coderepos.org/share/lang/javascript/vimperator-plugins/trunk@23253 d0d07461-0603-4401-acd4-de1884942a52
Diffstat (limited to 'unicode.js')
-rw-r--r--unicode.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/unicode.js b/unicode.js
new file mode 100644
index 0000000..78a3950
--- /dev/null
+++ b/unicode.js
@@ -0,0 +1,42 @@
+// ==VimperatorPlugin==
+// @name unicode escape
+// @description Copy unicode escaped text to clipboard.
+// @description-ja Unicode エスケープされてテキストをクリップボードにコピーする
+// @license Creative Commons 2.1 (Attribution + Share Alike)
+// @version 1.0
+// @author anekos (anekos@snca.net)
+// @maxVersion 2.0pre
+// @minVersion 2.0pre
+// ==/VimperatorPlugin==
+//
+// Usage:
+// :uc <MULTI_BYTE_TEXT>
+//
+// Links:
+//
+
+(function () {
+
+ function lz (s,n)
+ (''+s).replace(new RegExp('^.{0,'+(n-1)+'}$'),function(s)lz('0'+s,n));
+
+ function escape (s)
+ Array.slice(s).map(function(c)let(d=c.charCodeAt(0))(d<=127?c:'\\u'+lz(d.toString(16),4))).join('');
+
+ function unescape (s)
+ s.replace(/\\u([a-f\d]{4})/gi,function(_,c)String.fromCharCode(parseInt(c,16)));
+
+ function copyAndEcho (s)
+ (liberator.echo(s)+util.copyToClipboard(s));
+
+
+ commands.addUserCommand(
+ ['unicode', 'uc'],
+ 'unicode (un)escape',
+ function (arg, bang)
+ copyAndEcho((bang ? unescape : escape)(arg.string)),
+ {argCount: '*', bang: true},
+ true
+ );
+
+})();