try ... catch error for convertBinaryText
This commit is contained in:
parent
7c2c79041f
commit
8d11d1b804
@ -227,23 +227,31 @@ function convertCurrency(currency, euroValue) {
|
|||||||
// Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi (source : http://jsfiddle.net/47zwb41o)
|
// Convertis du texte (encodé en UTF-8) en binaire et l'inverse aussi (source : http://jsfiddle.net/47zwb41o)
|
||||||
// UTF-8 vers Binaire
|
// UTF-8 vers Binaire
|
||||||
function utf8ToBin(s) {
|
function utf8ToBin(s) {
|
||||||
s = unescape( encodeURIComponent(s));
|
try {
|
||||||
var chr, i = 0, l = s.length, out = '';
|
s = unescape( encodeURIComponent(s));
|
||||||
for( ; i < l; i ++ ){
|
var chr, i = 0, l = s.length, out = '';
|
||||||
chr = s.charCodeAt( i ).toString(2);
|
for( ; i < l; i ++ ){
|
||||||
while(chr.length % 8 != 0 ){ chr = '0' + chr; }
|
chr = s.charCodeAt( i ).toString(2);
|
||||||
out += chr;
|
while(chr.length % 8 != 0 ){ chr = '0' + chr; }
|
||||||
|
out += chr;
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
} catch (error) {
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
}
|
}
|
||||||
// Binaire vers UTF-8
|
// Binaire vers UTF-8
|
||||||
function binToUtf8(s){
|
function binToUtf8(s){
|
||||||
var i = 0, l = s.length, chr, out = '';
|
try {
|
||||||
for( ; i < l; i += 8){
|
var i = 0, l = s.length, chr, out = '';
|
||||||
chr = parseInt( s.substr(i, 8 ), 2).toString(16);
|
for( ; i < l; i += 8){
|
||||||
out += '%' + ((chr.length % 2 == 0) ? chr : '0' + chr);
|
chr = parseInt( s.substr(i, 8 ), 2).toString(16);
|
||||||
|
out += '%' + ((chr.length % 2 == 0) ? chr : '0' + chr);
|
||||||
|
}
|
||||||
|
return decodeURIComponent(out);
|
||||||
|
} catch (error) {
|
||||||
|
return s;
|
||||||
}
|
}
|
||||||
return decodeURIComponent(out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////
|
||||||
|
@ -185,7 +185,6 @@ $(function () {
|
|||||||
{
|
{
|
||||||
let binaryTextValue = $('#binaryTextValue').val();
|
let binaryTextValue = $('#binaryTextValue').val();
|
||||||
let convertIn = $("#convertIn option:selected").text();
|
let convertIn = $("#convertIn option:selected").text();
|
||||||
let isBinaryValue = isStringBin(binaryTextValue);
|
|
||||||
|
|
||||||
if(isEmptyValue(binaryTextValue)) {
|
if(isEmptyValue(binaryTextValue)) {
|
||||||
$('.results').html(emptyMessageError);
|
$('.results').html(emptyMessageError);
|
||||||
|
Reference in New Issue
Block a user