LoginSignup
1
2

シフトJIS文字表

Last updated at Posted at 2023-07-02

TextDecoder を使用してシフトJISコードを Unicode に変換して表示します。

表示されるものはブラウザにある変換表次第になります。

See the Pen シフトJIS文字表 by Ikiuo (@ikiuo) on CodePen.

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>シフトJIS文字表</title>
    <style>
     body {
         margin: auto;
         width: 750px;
     }
     table {
         border: solid 0px;
         border-left: solid 1px lightgray;
         border-top: solid 1px lightgray;
         border-collaspe: collaspe;
         border-spacing: 0;
     }
     th, td {
         border: solid 0px;
         border-right: solid 1px lightgray;
         border-bottom: solid 1px lightgray;
         padding: 4px;
     }
     th {
         background-color: #eeeeee;
     }
     td {
         text-align: center;
     }
     .undef {
         background-color: #ffeeff;
     }
    </style>
  </head>
  <body>
    <script>

     window.onload = function() {
         const td_unassigned = '<td class="undef">&nbsp;</td>';

         const decoder = new TextDecoder('sjis');
         const buffer = new ArrayBuffer(2);
         const view = new DataView(buffer);
         const sjis = new Map();
         const hcode = [];

         for (let y = 0xa1; y <= 0xdc; ++y) {
             const h = y ^ 0x20;
             let has = false;

             view.setUint8(0, h);
             for (let l = 0x40; l <= 0xfc; ++l) {
                 if (l == 0x7f)
                     continue;
                 view.setUint8(1, l);

                 const us = decoder.decode(view);
                 if (us.length < 1)
                     continue;
                 if (us.charCodeAt(0) == 0xfffd)
                     continue;
                 sjis.set(view.getUint16(0, false), us);
                 has = true;
             }
             if (has)
                 hcode.push(h);
         }

         html = '<table border="1">';
         html += '<tr><th colspan="17">シフトJIS文字表</th></tr>';
         for (const h of hcode) {
             const hh = h << 8;
             html += '<tr><th>&nbsp;</th>';
             for (let x = 0; x < 16; ++x)
                 html += `<th>${x.toString(16).toUpperCase()}</th>`;
             html += '</tr>';
             for (let lp = 0x40; lp <= 0xfc; lp += 16) {
                 const scode = hh + lp;
                 html += `<tr><th>${scode.toString(16).toUpperCase()}</th>`;
                 for (let x = 0; x < 16; ++x) {
                     const us = sjis.get(scode + x);
                     if (!us)
                         html += td_unassigned;
                     else
                         html += `<td>${us}</td>`;
                 }
                 html += '</tr>';
             }
         }
         html += '</table>'

         document.body.innerHTML = html;
     }

    </script>
  </body>
</html>
1
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2