app-conversion/index.html

423 lines
21 KiB
HTML
Executable File
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Unicode code converter</title>
<meta name="description" content="Helps you convert between Unicode character numbers, characters, UTF-8 and UTF-16 code units in hex, percent escapes,and Numeric Character References (hex and decimal)." />
<link rel="stylesheet" href="../shared/style/docs.css" />
<link rel="stylesheet" href="localstyle.css" />
<script src="../shared/code/boilerplate.js"></script>
<script src="conversionfunctions.js">//</script>
<script src="example.js">//</script>
<script src="entities.js">//</script>
<style>
.options { font-size: 80%; }
td { vertical-align: middle; }
body.app #sitelinks { margin-bottom: 0; }
#example p { margin-right:7.5%; font-size:90%; }
textarea { padding: 0 5px; }
#versionInfo a { font-weight: bold; }
.subhead { color: brown; margin-left: .75em; }
.copy { margin: 0 10px; padding: 0 .5em; font-size: .85em; background-color: darkgray; color: white; border: 0; }
.copy:hover { color: brown; }
.convert { margin: 0 10px; }
</style>
<!--
Copyright (C) 2007 Richard Ishida ishida@w3.org
This program is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version as long as you point to
http://rishida.net/ in your code.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details. http://www.gnu.org/licenses/gpl.html
-->
</head>
<body class="app">
<header>
<div id="header-boilerplate"></div>
<script>document.getElementById('header-boilerplate').innerHTML = bp_appHeader('../shared/images/world.gif','Unicode code converter','v10');</script>
</header>
<section>
<!--p style="font-size: 120%; float:left;">This is version 9beta. Please <a style="font-weight:bold;" href="https://github.com/r12a/app-conversion/issues">raise any issues here</a>.</p-->
<details>
<summary style="margin-right: 5%; margin-top: 1em;" dir="rtl" onclick="escapedInput.value=window.example_test;">Show&nbsp;instructions</summary>
<p style="clear: both;">Type or paste text in the green box and click on the <code>Convert</code> button above it. Alternative representations will appear in all the other boxes. You can also do the same in any grey box, if you want to target only certain types of escaped text. You can then cut &amp; paste the results into your document. <img src="selectall.png" alt="Select" /> selects all the text in a box (useful for deleting), and <img src="copy.png" alt="Copy"/> copies the text to the clipboard, if your browser supports that. See the <a href="help">help page</a> for other options.</p>
<p><b class="leadin">Worked example.</b> The text in the field with a green background currently contains a variety of escapes. Normally you would simply click on the <code>Convert</code> button just above the field to show the various escape formats below. Note, however, that this (unusually convoluted) text represents two characters using just a code point number therefore, for this particular example, you should select <code>Treat bare numbers as Hex code points</code> (or decimal) to convert those numbers as well as the other escapes. You should also ensure that the checkbox next to <code>Convert \n etc</code> is selected, in order to convert the <code>\n</code> and <code>\t</code> escapes.</p>
<p>After selecting those options, click on the <code>Convert</code> button.</p>
<p>You will then see the conversion results in the grey boxes. You can use checkboxes alongside many boxes to tweak the results. For more information on each of the grey boxes, see the <a href="help">help page</a>.</p>
</details>
</section>
<table id="converter" style="clear: both;">
<tr>
<td colspan="2">
<button value="Convert"
onclick="displayResults(convertAllEscapes(escapedInput.value, document.getElementById('numbers').value), escapedInput.id);
return false;" style="font-size:140%;" >Convert</button>
<button class="copy" onclick="
escapedInput.value = '';
codePoints.value = '';
decCodePoints.value = '';
UTF8.value = '';
UTF16.value = '';
zeroX.value = '';
hexNCRs.value = '';
decNCRs.value = '';
Unicode.value = '';
pEsc.value = '';
rust.value = '';
jEsc.value = '';
perl.value = '';
chars.value = '';
CSS.value = '';
XML.value = '';
escapedInput.focus(); return false;" >Clear</button>
<span class="options">
<label>Treat bare numbers as
<select id="numbers" style="border: 0; color: brown; font-size: 90%;">
<option value="none">Just numbers</option>
<option value="hex">Hex code points</option>
<option value="dec">Dec code points</option>
<option value="utf8">UTF-8 units</option>
<option value="utf16">UTF-16 units</option>
</select>
</label>
&nbsp;&nbsp;&nbsp;
<label>Convert \n etc<input type="checkbox" id="singleletterescapes" checked /></label>
</span>
&nbsp;&nbsp;&nbsp;
<button id="extract" onClick="escapedInput.value = extractEscapes(document.getElementById('escapedInput').value)">Extract</button>
&nbsp;&nbsp;&nbsp;<a href="help#use" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="escapedInput" name="escapedInput" rows="3" cols="5" style="background-color: #DFD; color:#333; height:7em;" placeholder="Add characters here, then press Convert."></textarea></td>
</tr>
<tr>
<td colspan="2" style="padding-top: 20px;"><!-- *********** CHARACTERS *********** -->
<span class="subhead">Characters</span>
<button class="copy" onclick="chars.focus(); chars.select(); document.execCommand('copy'); return false;" >Copy</button>
 
<!--button
onclick="if (chars.value== '') { alert('No characters in the text area.'); } else { var list = window.open('/rishida/tools/analysestring?list='+encodeURIComponent(chars.value)+'&amp;smallgraphics=on&amp;compact=on&amp;noblock=on&amp;nounicode=on&amp;nonotes=on', 'list'); list.focus(); }
return false;" >View names</button-->
 
<!--button
onclick="var list = window.open( '/rishida/uniview/?codepoints='+convertChar2CP( chars.value ) );
return false;" >View in UniView</button-->
<button
onclick="var list = window.open( '/uniview/?charlist='+encodeURIComponent(chars.value ));
return false;" >View in UniView</button>
<button class="convert"
onclick="displayResults( chars.value, chars.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#characters" target="_blank"><img src="images/help.png" alt="help"/></a>
<br/>
<textarea id="chars" name="chars" rows="2" cols="5"></textarea></td>
</tr>
<tr>
<td colspan="2"><!-- *********** HTML/XML *********** -->
<span class="subhead">HTML/XML</span>
<button class="copy" onclick="XML.focus(); XML.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="xmlOptions">
<label>Escape invisible characters<input class="check" type="checkbox" id="xmlinvisibles" data-fn="convertinvisibles" checked="checked" onclick="XML.value = convertCharStr2XML(convertXML2Char(XML.value), getParameters(parentNode.parentNode));" /></label>
<label>Convert bidi controls to HTML markup<input type="checkbox" id="xmlbidimarkup" data-fn="bidimarkup" onclick="XML.value = convertCharStr2XML(convertXML2Char(XML.value), getParameters(parentNode.parentNode));"/></label>
</span>
<button class="convert"
onclick="displayResults( convertXML2Char(XML.value), XML.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#html" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="XML" name="XML" rows="2" cols="5"></textarea>
</td>
</tr>
<tr>
<td><!-- *********** HEX NCRS *********** -->
<span class="subhead">Hex NCRs</span>
<button class="copy" onclick="hexNCRs.focus(); hexNCRs.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="hexNCROptions"><label>Show ascii<input class="check" type="checkbox" id="hexncrascii" checked="checked" data-fn="ascii"
onclick="hexNCRs.value = convertCharStr2SelectiveCPs(convertHexNCR2Char(hexNCRs.value), getParameters(parentNode), true, '&#x', ';', 'hex');" /></label></span>
<button class="convert"
onclick="displayResults( convertHexNCR2Char(hexNCRs.value), hexNCRs.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#hexNCRs" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="hexNCRs" name="hexNCRs" rows="3" cols="5"></textarea></td>
<td><!-- *********** DEC NCRS *********** -->
<span class="subhead">Decimal NCRs</span>
<button class="copy" onclick="decNCRs.focus();decNCRs.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="decNCROptions"><label>Show ascii<input type="checkbox" id="decncrascii" checked="checked" data-fn="ascii"
onclick="decNCRs.value = convertCharStr2SelectiveCPs(convertDecNCR2Char(decNCRs.value), getParameters(parentNode), true, '&#', ';', 'dec');" /></label>
</span>
<button class="convert"
onclick="displayResults( convertDecNCR2Char(decNCRs.value), decNCRs.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#decNCRs" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="decNCRs" name="decNCRs" rows="3" cols="5"></textarea></td>
</tr>
<tr>
<td><!-- *********** JAVASCRIPT ESCAPES *********** -->
<span class="subhead">JS/Java/C</span>
<button class="copy" onclick="jEsc.focus();jEsc.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="jEscOptions">
<label>ES6<input class="check" type="checkbox" checked data-fn="es6styleSC" id="es6styleSC" onclick="document.getElementById('cstyleSC').checked =false; jEsc.value = convertCharStr2jEsc(convertjEsc2Char(jEsc.value, true), getParameters(parentNode));"/></label>
<label>C-style<input class="check" type="checkbox" data-fn="cstyleSC" id="cstyleSC" onclick="document.getElementById('es6styleSC').checked =false; jEsc.value = convertCharStr2jEsc(convertjEsc2Char(jEsc.value, true), getParameters(parentNode));" /></label>
<label>\n etc<input class="check" type="checkbox" data-fn="noCR" id="noCR" onclick="jEsc.value = convertCharStr2jEsc(convertjEsc2Char(jEsc.value, true), getParameters(parentNode));"/></label>
</span>
<!--button value="Switch"
onclick="jEsc.value = convert2C( jEsc.value );
return false;" >C-style Supp. Chars.</button-->
<button class="convert"
onclick="displayResults(convertjEsc2Char(jEsc.value, true), jEsc.id); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#javascript" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="jEsc" name="jEsc" rows="3" cols="5"></textarea></td>
<td><!-- *********** RUST ESCAPES *********** -->
<span class="subhead">Rust/Ruby</span>
<button class="copy" onclick="rust.focus();rust.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="rustOptions">
<label>\n etc<input class="check" type="checkbox" data-fn="noCR" id="noRustCR" onclick="rust.value = convertCharStr2Rust(convertRust2Char(rust.value, true), getParameters(parentNode));"/></label>
</span>
<button class="convert"
onclick="displayResults(convertRust2Char(rust.value), rust.id); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#rust" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="rust" name="rust" rows="3" cols="5"></textarea></td>
</tr>
<tr>
<td><!-- *********** CSS ESCAPES *********** -->
<span class="subhead">CSS</span>
<button class="copy" onclick="CSS.focus(); CSS.select(); document.execCommand('copy'); return false;" >Copy</button>
<button class="convert"
onclick="displayResults(convertCSS2Char(CSS.value, true), CSS.id); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#css" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="CSS" name="CSS" rows="3" cols="5"></textarea></td>
<td><!-- *********** \X NOTATION *********** -->
<span class="subhead">Perl/UTR#18</span>
<button class="copy" onclick="perl.focus(); perl.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="perlOptions">
<label>\n etc<input class="check" type="checkbox" data-fn="noCR" id="noperlCR" onclick="perl.value = convertCharStr2Perl(convertPerl2Char(perl.value, true), getParameters(parentNode));"/></label>
</span>
<button class="convert"
onclick="displayResults(convertPerl2Char(perl.value), perl.id); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#perl" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="perl" name="perl" rows="3" cols="5"></textarea></td>
</tr>
<tr>
<td colspan="2"><!-- *********** % ESCAPES *********** -->
<span class="subhead">Percent encoding for URIs</span>
<button class="copy" onclick="pEsc.focus(); pEsc.select(); document.execCommand('copy'); return false;" >Copy</button>
<button class="convert"
onclick="displayResults( convertpEnc2Char(pEsc.value), pEsc.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#percentEncoding" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="pEsc" name="pEsc" rows="2" cols="5"></textarea></td>
</tr>
<tr>
<td><!-- *********** U+ *********** -->
<span class="subhead">U+hex</span>
<button class="copy" onclick="Unicode.focus(); Unicode.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options"><label>Show ascii<input class="check" type="checkbox" id="unicodeascii" checked="checked"
onclick="preserve = 'none';
if (this.checked) { preserve = 'ascii'; }
Unicode.value = convertCharStr2CP(convertUnicode2Char(Unicode.value), preserve, true, 'unicode');"/></label>
</span>
<button onClick="Unicode.value=Unicode.value.replace(/([a-fA-F0-9])U\+/g,'$1 U+')">Separate</button>
<button class="convert"
onclick="displayResults( convertUnicode2Char(Unicode.value), Unicode.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#UHex" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="Unicode" name="Unicode" rows="3" cols="5"></textarea></td>
<td><!-- *********** 0x... *********** -->
<span class="subhead">0x...</span>
<button class="copy" onclick="zeroX.focus(); zeroX.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options"><label>Show ascii<input class="check" type="checkbox" id="zeroXascii" checked="checked"
onclick="preserve = 'none';
if (this.checked) { preserve = 'ascii'; }
zeroX.value = convertCharStr2CP(convert0x2Char(zeroX.value), preserve, true, 'zerox');" /></label>
</span>
<button onClick="zeroX.value=zeroX.value.replace(/([a-fA-F0-9])0x/g,'$1 0x')">Separate</button>
<button class="convert"
onclick="displayResults( convert0x2Char(zeroX.value), zeroX.id ); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#ZeroX" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="zeroX" name="zeroX" rows="3" cols="5"></textarea></td>
</tr>
<tr>
<td><!-- *********** UTF-8 *********** -->
<span class="subhead">UTF-8 code units</span>
<button class="copy" onclick="UTF8.focus(); UTF8.select(); document.execCommand('copy'); return false;" >Copy</button>
<button class="convert"
onclick="displayResults(convertUTF82Char(UTF8.value), UTF8.id); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#utf8" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="UTF8" name="UTF8" rows="3" cols="5"></textarea></td>
<td><!-- *********** UTF-16 *********** -->
<span class="subhead">UTF-16 code units</span>
<button class="copy" onclick="UTF16.focus(); UTF16.select(); document.execCommand('copy'); return false;" >Copy</button>
<button class="convert"
onclick="displayResults(convertUTF162Char(UTF16.value), UTF16.id); return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#utf16" target="_blank"><img src="images/help.png" alt="help"/></a> <br/>
<textarea id="UTF16" name="UTF16" rows="3" cols="5"></textarea></td>
</tr>
<tr>
<td><!-- *********** CODE POINTS *********** -->
<span class="subhead">Hex/UTF-32</span>
<button class="copy" onclick="codePoints.focus(); codePoints.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options" id="hexCPOptions">
<label>Keep ascii
<input class="check" type="checkbox" id="hexcpascii" /></label>
<label>Pad <select id="hexcppad" onclick="
if (document.getElementById('hexcpascii').checked) {
codePoints.value = convertCharStr2CP(convertNumbers2Char(codePoints.value, 'hex'), 'ascii', document.getElementById('hexcppad').value, 'hex', document.getElementById('hexcpascii').checked) }
else { codePoints.value = convertCharStr2CP(convertSpaceSeparatedNumbers2Char(codePoints.value, 'hex'), 'none', document.getElementById('hexcppad').value, 'hex', document.getElementById('hexcpascii').checked)}
;" style="border: 0; color: brown; font-size: 90%;">
<!--option value="0">0</option-->
<option value="2">2</option>
<option value="4" selected>4</option>
<option value="8">8</option>
</select></label>
</span>
<button class="convert"
onclick="if (document.getElementById('hexcpascii').checked) {
displayResults( convertNumbers2Char(codePoints.value, 'hex'), codePoints.id ); }
else { displayResults( convertSpaceSeparatedNumbers2Char(codePoints.value, 'hex'), codePoints.id )}
return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#hexCP" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="codePoints" name="codePoints" rows="3" cols="5"></textarea></td>
<td><!-- *********** DEC CODE POINTS *********** -->
<span class="subhead">Decimal</span>
<button class="copy" onclick="decCodePoints.focus(); decCodePoints.select(); document.execCommand('copy'); return false;" >Copy</button>
<span class="options">
<label>Keep ascii
<input class="check" type="checkbox" id="deccpascii" /></label>
</span>
<button class="convert"
onclick="if (document.getElementById('deccpascii').checked) {
displayResults( convertNumbers2Char(decCodePoints.value, 'dec'), decCodePoints.id ); }
else { displayResults( convertSpaceSeparatedNumbers2Char(decCodePoints.value, 'dec'), decCodePoints.id ) }
return false;" >Convert</button>
&nbsp;&nbsp;&nbsp;<a href="help#decCP" target="_blank"><img src="images/help.png" alt="help"/></a><br/>
<textarea id="decCodePoints" name="decCodePoints" rows="3" cols="5"></textarea></td>
</tr>
</table>
<p><a href="help#versionInfo">Summary of changes in this version</a>.</p>
<div class="smallprint"><span id="version">
See <a href="https://github.com/r12a/app-conversion/commits/gh-pages">recent changes</a>.
Make a <a href="https://github.com/r12a/app-conversion/issues/new">comment</a>.
Licence <a rel="license" href="http://creativecommons.org/licenses/by/4.0/">CC-By</a> © <a href="mailto:r12a@w3.org">r12a</a>
</span>
</div>
<script>
var escapedInput = document.getElementById('escapedInput');
var codePoints = document.getElementById('codePoints');
var decCodePoints = document.getElementById('decCodePoints');
var UTF8 = document.getElementById('UTF8');
var UTF16 = document.getElementById('UTF16');
var zeroX = document.getElementById('zeroX');
var hexNCRs = document.getElementById('hexNCRs');
var decNCRs = document.getElementById('decNCRs');
var Unicode = document.getElementById('Unicode');
var pEsc = document.getElementById('pEsc');
var rust = document.getElementById('rust');
var perl = document.getElementById('perl');
var jEsc = document.getElementById('jEsc');
var chars = document.getElementById('chars');
var CSS = document.getElementById('CSS');
var XML = document.getElementById('XML');
// check for parameters and take appropriate action
parameters = location.search.split('&')
parameters[0] = parameters[0].substring(1)
for (var p=0;p<parameters.length;p++) {
pairs = parameters[p].split('=')
if (pairs[0] == 'q' && pairs[1]) {
escapedInput.value = convertpEnc2Char(pairs[1])
displayResults(convertAllEscapes(escapedInput.value, "none"), escapedInput.id)
}
}
</script>
</body>
</html>