Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

initial import

  • Loading branch information...
commit 5b4ad170ed4359cd082935a786630c7d2b3b6b8f 0 parents
Tokuhiro Matsuno authored

Showing 3 changed files with 51 additions and 0 deletions. Show diff stats Hide diff stats

  1. +1 0  .gitignore
  2. +15 0 package.json
  3. +35 0 utf728.js
1  .gitignore
... ... @@ -0,0 +1 @@
  1 +node_modules/
15 package.json
... ... @@ -0,0 +1,15 @@
  1 +{
  2 + "author": "",
  3 + "name": "utf7-repl",
  4 + "version": "0.0.0",
  5 + "repository": {
  6 + "url": ""
  7 + },
  8 + "engines": {
  9 + "node": "~0.6.0"
  10 + },
  11 + "dependencies": {
  12 + "iconv": ">=0.0.0"
  13 + },
  14 + "devDependencies": {}
  15 +}
35 utf728.js
... ... @@ -0,0 +1,35 @@
  1 +var Iconv = require('iconv').Iconv,
  2 + rl = require('readline'),
  3 + util = require('util'),
  4 + undefined;
  5 +
  6 +var utf827 = new Iconv('UTF-8', 'UTF-7');
  7 +var utf728 = new Iconv('UTF-7', 'UTF-8');
  8 +function convert(str) {
  9 + if (str.match(/^\+/)) {
  10 + console.log("7");
  11 + return utf728.convert(str);
  12 + } else {
  13 + return utf827.convert(str);
  14 + }
  15 +}
  16 +
  17 +// setup readline
  18 +var rli = rl.createInterface(process.stdin, process.stdout);
  19 +
  20 +rli.setPrompt('utf7> ');
  21 +
  22 +rli.addListener('line', function(cmd) {
  23 + var e = convert(cmd);
  24 + util.puts(e);
  25 +
  26 + rli.prompt();
  27 +});
  28 +
  29 +rli.addListener('close', function() {
  30 + util.puts('');
  31 + process.stdin.destroy();
  32 +});
  33 +
  34 +rli.prompt();
  35 +

0 comments on commit 5b4ad17

Please sign in to comment.
Something went wrong with that request. Please try again.