Skip to content

Commit

Permalink
Removed latin1 checkboxes
Browse files Browse the repository at this point in the history
Fixed some bugs relating to hex and dec with ascii - now adds space between adjacent hex/dec numbers
Changed hex and dec 'show ascii' to 'keep ascii'
  • Loading branch information
r12a committed Jul 24, 2018
1 parent 7a6310a commit 0d59779
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 60 deletions.
75 changes: 30 additions & 45 deletions beta.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<option value="dec">Dec code point</option>
<option value="utf8">UTF-8 units</option>
<option value="utf16">UTF-16 units</option>
</select>
</select>
</label>

&nbsp;&nbsp;&nbsp;
Expand Down Expand Up @@ -116,7 +116,7 @@
return false;" >View in UniView</button>
<br/>
<textarea id="chars" name="chars" rows="2" cols="5"></textarea></td>
</tr>
</tr>


<tr>
Expand All @@ -131,8 +131,8 @@
<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><br/>
<textarea id="XML" name="XML" rows="2" cols="5"></textarea>
</td>
</tr>
</td>
</tr>


<tr>
Expand All @@ -142,9 +142,7 @@
return false;" >Convert</button><span style="padding-top: 20px;"><img src="copy.png" alt="Copy" title="Copy to clipboard" class="icon" onclick="document.getElementById('hexNCRs').focus();document.getElementById('hexNCRs').select();document.execCommand('copy')" /></span><img src="selectall.png" alt="Select" title="Select all text in the box" class="icon" onclick="document.getElementById('hexNCRs').focus();document.getElementById('hexNCRs').select();" />

<span class="options" id="hexNCROptions"><label>Show ascii<input class="check" type="checkbox" id="hexncrascii" checked="checked" data-fn="ascii"
onclick="document.getElementById('hexncrlatin1').checked = false; hexNCRs.value = convertCharStr2SelectiveCPs(convertHexNCR2Char(hexNCRs.value), getParameters(parentNode), true, '&#x', ';', 'hex');" /></label>
<label>Latin1<input type="checkbox" id="hexncrlatin1" data-fn="latin1"
onclick="document.getElementById('hexncrascii').checked = false; hexNCRs.value = convertCharStr2SelectiveCPs(convertHexNCR2Char(hexNCRs.value), getParameters(parentNode), true, '&#x', ';', 'hex');"/></label></span>
onclick="hexNCRs.value = convertCharStr2SelectiveCPs(convertHexNCR2Char(hexNCRs.value), getParameters(parentNode), true, '&#x', ';', 'hex');" /></label></span>
<br/>
<textarea id="hexNCRs" name="hexNCRs" rows="3" cols="5"></textarea></td>

Expand All @@ -156,10 +154,8 @@
return false;" >Convert</button><span style="padding-top: 20px;"><img src="copy.png" alt="Copy" title="Copy to clipboard" class="icon" onclick="document.getElementById('decNCRs').focus();document.getElementById('decNCRs').select();document.execCommand('copy')" /></span><img src="selectall.png" alt="Select" title="Select all text in the box" class="icon" onclick="document.getElementById('decNCRs').focus();document.getElementById('decNCRs').select();" />

<span class="options" id="decNCROptions"><label>Show ascii<input type="checkbox" id="decncrascii" checked="checked" data-fn="ascii"
onclick="document.getElementById('decncrlatin1').checked = false; decNCRs.value = convertCharStr2SelectiveCPs(convertDecNCR2Char(decNCRs.value), getParameters(parentNode), true, '&#', ';', 'dec');" /></label>
<label>Latin1<input type="checkbox" id="decncrlatin1" data-fn="latin1"
onclick="document.getElementById('decncrascii').checked = false; decNCRs.value = convertCharStr2SelectiveCPs(convertDecNCR2Char(decNCRs.value), getParameters(parentNode), true, '&#', ';', 'dec');"/></label>
</span><br/>
onclick="decNCRs.value = convertCharStr2SelectiveCPs(convertDecNCR2Char(decNCRs.value), getParameters(parentNode), true, '&#', ';', 'dec');" /></label>
</span><br/>
<textarea id="decNCRs" name="decNCRs" rows="3" cols="5"></textarea></td>
</tr>

Expand Down Expand Up @@ -192,7 +188,7 @@

<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>
</span>
<br/>
<textarea id="rust" name="rust" rows="3" cols="5"></textarea></td>
</tr>
Expand All @@ -218,7 +214,7 @@
</span>
<br/>
<textarea id="perl" name="perl" rows="3" cols="5"></textarea></td>
</tr>
</tr>



Expand All @@ -238,18 +234,11 @@
onclick="displayResults( convertUnicode2Char(Unicode.value), Unicode.id );
return false;" >Convert</button><span style="padding-top: 20px;"><img src="copy.png" alt="Copy" title="Copy to clipboard" class="icon" onclick="document.getElementById('Unicode').focus();document.getElementById('Unicode').select();document.execCommand('copy')" /></span><img src="selectall.png" alt="Select" title="Select all text in the box" class="icon" onclick="document.getElementById('Unicode').focus();document.getElementById('Unicode').select();" />

<span class="options"><label>Show ascii<input class="check" type="checkbox" id="unicodeascii" checked="checked" onclick="document.getElementById('unicodelatin1').checked =false;
preserve = 'none';
if (document.getElementById('unicodelatin1').checked) { preserve = 'latin1'; }
else if (this.checked) { preserve = 'ascii'; }
<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>
<label>Latin1<input type="checkbox" id="unicodelatin1"
onclick="document.getElementById('unicodeascii').checked =false;
preserve = 'none';
if (this.checked) { preserve = 'latin1'; }
else if (document.getElementById('unicodeascii').checked) { preserve = 'ascii'; }
Unicode.value = convertCharStr2CP(convertUnicode2Char(Unicode.value), preserve, true, 'unicode');" /></label>
</span>
</span>
<button onClick="Unicode.value=Unicode.value.replace(/([a-fA-F0-9])U\+/g,'$1 U+')">Separate</button>

<br/>
Expand All @@ -263,19 +252,11 @@
return false;" >Convert</button><span style="padding-top: 20px;"><img src="copy.png" alt="Copy" title="Copy to clipboard" class="icon" onclick="document.getElementById('zeroX').focus();document.getElementById('zeroX').select();document.execCommand('copy')" /></span><img src="selectall.png" alt="Select" title="Select all text in the box" class="icon" onclick="document.getElementById('zeroX').focus();document.getElementById('zeroX').select();" />

<span class="options"><label>Show ascii<input class="check" type="checkbox" id="zeroXascii" checked="checked"
onclick="document.getElementById('zeroXlatin1').checked =false;
preserve = 'none';
if (document.getElementById('unicodelatin1').checked) { preserve = 'latin1'; }
else if (this.checked) { preserve = 'ascii'; }
onclick="preserve = 'none';
if (this.checked) { preserve = 'ascii'; }
zeroX.value = convertCharStr2CP(convert0x2Char(zeroX.value), preserve, true, 'zerox');" /></label>

<label>Latin1<input type="checkbox" id="zeroXlatin1"
onclick="document.getElementById('zeroXascii').checked =false;
preserve = 'none';
if (this.checked) { preserve = 'latin1'; }
else if (document.getElementById('unicodeascii').checked) { preserve = 'ascii'; }
zeroX.value = convertCharStr2CP(convert0x2Char(zeroX.value), preserve, true, 'zerox');" /></label>
</span>
</span>
<button onClick="zeroX.value=zeroX.value.replace(/([a-fA-F0-9])0x/g,'$1 0x')">Separate</button>

<br/>
Expand Down Expand Up @@ -311,17 +292,17 @@
return false;" >Convert</button><span style="padding-top: 20px;"><img src="copy.png" alt="Copy" title="Copy to clipboard" class="icon" onclick="document.getElementById('codePoints').focus();document.getElementById('codePoints').select();document.execCommand('copy')" /></span><img src="selectall.png" alt="Select" title="Select all text in the box" class="icon" onclick="document.getElementById('codePoints').focus();document.getElementById('codePoints').select();" />

<span class="options" id="hexCPOptions">
<label>Show ascii<input class="check" type="checkbox" id="hexcpascii" onclick="document.getElementById('hexcplatin1').checked =false;" /></label>
<label>Latin1<input type="checkbox" id="hexcplatin1" onclick="document.getElementById('hexcpascii').checked =false;" /></label>
<label>Keep ascii
<input class="check" type="checkbox" id="hexcpascii" /></label>

<label>Pad <select id="hexcppad" onclick="document.getElementById('hexcppad').checked =false;" 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><br/>
</span><br/>
<textarea id="codePoints" name="codePoints" rows="3" cols="5"></textarea></td>


Expand All @@ -333,9 +314,10 @@
return false;" >Convert</button><span style="padding-top: 20px;"><img src="copy.png" alt="Copy" title="Copy to clipboard" class="icon" onclick="document.getElementById('decCodePoints').focus();document.getElementById('decCodePoints').select();document.execCommand('copy')" /></span><img src="selectall.png" alt="Select" title="Select all text in the box" class="icon" onclick="document.getElementById('decCodePoints').focus();document.getElementById('decCodePoints').select();" />

<span class="options">
<label>Show ascii<input class="check" type="checkbox" id="deccpascii" onclick="document.getElementById('deccplatin1').checked =false;" /></label>
<label>Latin1<input type="checkbox" id="deccplatin1" onclick="document.getElementById('deccpascii').checked =false;" /></label>
</span><br/>
<label>Keep ascii
<input class="check" type="checkbox" id="deccpascii" /></label>

</span><br/>
<textarea id="decCodePoints" name="decCodePoints" rows="3" cols="5"></textarea></td>
</tr>
</table>
Expand All @@ -356,7 +338,7 @@ <h2 class="flush">Related links</h2>
</div>
</aside>

<p id="status">Updated <!-- #BeginDate format:IS1m -->2018-07-21 15:13<!-- #EndDate --> &bull; tags <a href="http://rishida.net/blog/index.php?tag=converter" title="Show all blog posts tagged with 'converter'">converter</a>, <a href="http://rishida.net/blog/?tag=scriptnotes" title="Show all blog posts tagged with 'scriptnotes'">scriptnotes</a></p>
<p id="status">Updated <!-- #BeginDate format:IS1m -->2018-07-23 7:58<!-- #EndDate --> &bull; tags <a href="http://rishida.net/blog/index.php?tag=converter" title="Show all blog posts tagged with 'converter'">converter</a>, <a href="http://rishida.net/blog/?tag=scriptnotes" title="Show all blog posts tagged with 'scriptnotes'">scriptnotes</a></p>


<section>
Expand All @@ -370,7 +352,7 @@ <h2>Standard use</h2>
<p><span class="leadin">Checkboxes.</span> Several of the output fields have checkboxes that allow you to slightly alter the results of a conversion. If an output field already contains a result when you click on a checkbox, you'll often see a change happen as you click. In a couple of cases, however, this doesn't happen, since it is not possible to produce good results.</p>

<p><span class="leadin">Invoking via URL.</span> You can also pass a string to the page using the q parameter in the URI. For example, <a href="/app-conversion/beta?q=Cr%C3%AApes">http://r12a.github.io/app-conversion/?q=Crêpes</a>. You can also pass a string with escapes in it, but you will need to be careful to percent escape characters such as &amp;, + and # which affect the URI syntax. For example,<a href="/app-conversion/beta?q=CrU%2B00EApes"> http://r12a.github.io/app-conversion/beta?q=CrU%2B00EApes</a>.</p>
</section>
</section>
<section>
<h2>Box inputs and outputs</h2>
<p>The following describe how the various boxes work, including what happens if you paste or type text into the named field and hit <code>Convert</code>, and the output in the named field if you hit <code>Convert</code> elsewhere.</p>
Expand Down Expand Up @@ -429,7 +411,7 @@ <h3>Rust/Ruby</h3>
<li>\u{1234 1235 1236}</li>
<li>\x10</li>
<li>\0 \b \t \n \r \v \f \\ \"</li>
</ul>
</ul>



Expand Down Expand Up @@ -517,7 +499,10 @@ <h2>Notable changes</h2>
<li>Changing checkboxes produces an immediate effect for all grey boxes now.</li>
<li>Buttons for choosing how to parse bare numbers in green box input changed from buttons to a pull-down control.</li>
<li>Example text provided with instructions tests for several more formats, and in a more useful way.</li>
<li>The Hex/UTF-32 box allows you to set padding to different lengths, including 8 digit code points, which is useful for UTF-32.</li>
<li>Bugfix: <a href="https://github.com/r12a/app-conversion/issues/3">Issue #3 Missing space separator between first two characters in some strings</a></li>
<li>Removed choice to keep Latin1 characters. Only ASCII allowed.</li>
<li>Improved the Hex/UTF-32 and Decimal boxes, so that conversion of text with or without ASCII characters works better. Note that, when <code class="kw" translate="no">Keep ASCII</code> is on, a sequence of code point values is not separated – that setting only intended for use with text that has separated code point values.</li>
</ul>
<p>Once this version appears to be stable, it will replace the old version at <a href="https://r12a.github.io/app-conversion">https://r12a.github.io/app-conversion</a>, and this URL will become a redirect.</p>

Expand Down
32 changes: 17 additions & 15 deletions conversionfunctions-beta.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,24 @@ function displayResults(str, src) {
}
if (src !== 'Unicode') {
preserve = 'none';
if (document.getElementById('unicodelatin1').checked) { preserve = 'latin1' }
else if (document.getElementById('unicodeascii').checked) { preserve = 'ascii' }
if (document.getElementById('unicodeascii').checked) { preserve = 'ascii' }
Unicode.value = convertCharStr2CP(str, preserve, 4, 'unicode');
}
if (src !== 'zeroX') {
preserve = 'none'
if (document.getElementById('zeroXlatin1').checked) { preserve = 'latin1'; }
else if (document.getElementById('zeroXascii').checked) { preserve = 'ascii'; }
if (document.getElementById('zeroXascii').checked) { preserve = 'ascii'; }
zeroX.value = convertCharStr2CP(str, preserve, 0, 'zerox');
}


if (src !== 'codePoints') {
preserve = 'none'
if (document.getElementById('hexcplatin1').checked) { preserve = 'latin1' }
else if (document.getElementById('hexcpascii').checked) { preserve = 'ascii' }
if (document.getElementById('hexcpascii').checked) { preserve = 'ascii' }
codePoints.value = convertCharStr2CP(str, preserve, document.getElementById('hexcppad').value, 'hex', document.getElementById('hexcpascii').checked)
}
if (src != 'decCodePoints') {
preserve = 'none';
if (document.getElementById('deccplatin1').checked) { preserve = 'latin1'; }
else if (document.getElementById('deccpascii').checked) { preserve = 'ascii'; }
if (document.getElementById('deccpascii').checked) { preserve = 'ascii'; }
decCodePoints.value = convertCharStr2CP(str, preserve, 0, 'dec', document.getElementById('deccpascii').checked)
}
if (src != 'UTF8') {
Expand Down Expand Up @@ -425,7 +421,7 @@ function convertGreenNumbers2Char ( str, type ) {
// type: string enum [none, hex, dec, utf8, utf16], what to treat numbers as

if (type === 'hex') {
str = str.replace(/(\b[A-Fa-f0-9]{2,6}\b)/g,
str = str.replace(/(\b[A-Fa-f0-9]{2,8}\b)/g,
function(matchstr, parens) {
return hex2char(parens)
}
Expand Down Expand Up @@ -493,7 +489,6 @@ function convertNumbers2Char ( str, type ) {
}
)
}
console.log(str)
return str
}

Expand All @@ -510,7 +505,6 @@ function convertSpaceSeparatedNumbers2Char ( str, type ) {
if (type === 'hex') {
str = str.replace(/([A-Fa-f0-9]{2,8}\b)/g,
function(matchstr, parens) {
console.log(parens)
return hex2char(parens)
}
)
Expand All @@ -537,7 +531,6 @@ function convertSpaceSeparatedNumbers2Char ( str, type ) {
}
)
}
console.log(str)
return str.replace(/§±§/g,'')
}

Expand Down Expand Up @@ -1286,7 +1279,7 @@ function convertCharStr2CSS ( str ) {



function convertCharStr2CP ( textString, parameters, pad, type, mixed ) { console.log(mixed)
function convertCharStr2CP ( textString, parameters, pad, type, mixed ) {
// converts a string of characters to code points, separated by space
// textString: string, the string to convert
// parameters: string enum [ascii, latin1], a set of characters to not convert
Expand All @@ -1296,6 +1289,8 @@ function convertCharStr2CP ( textString, parameters, pad, type, mixed ) { consol
var str = ''
var number
var chars = [...textString]

chars[chars.length] = ' '
for (let i=0; i<chars.length; i++) {
var cp = chars[i].codePointAt(0)

Expand All @@ -1306,7 +1301,10 @@ function convertCharStr2CP ( textString, parameters, pad, type, mixed ) { consol
case 'hex': number = chars[i].codePointAt(0).toString(16).toUpperCase()
if (pad>0) while (number.length < pad) number = '0'+number
if (!mixed) str += number+' '
else str += number
else {
if (chars[i+1].codePointAt(0) > 127) str += number+' '
else str += number
}
break
case 'zerox': number = chars[i].codePointAt(0).toString(16).toUpperCase()
if (pad>0) while (number.length < pad) number = '0'+number
Expand All @@ -1318,7 +1316,11 @@ function convertCharStr2CP ( textString, parameters, pad, type, mixed ) { consol
break
case 'dec': number = cp
if (!mixed) str += number+' '
else str += number }
else {
if (chars[i+1].codePointAt(0) > 127) str += number+' '
else str += number
}
}
}
}
return str.trim()
Expand Down

0 comments on commit 0d59779

Please sign in to comment.