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