author | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
---|---|---|
committer | Clipperz <info@clipperz.com> | 2013-01-31 13:42:04 (UTC) |
commit | 07d0357beef5d9328a2dd8d07ad7b39c87ac55e4 (patch) (unidiff) | |
tree | f7a4aed8848302db153c2a211f8e58b944eb4c5b /frontend/gamma/js/Clipperz/ByteArray.js | |
parent | 767a3dcf48b6ac911c088af5dd7738a728eb6b99 (diff) | |
download | clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.zip clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.gz clipperz-07d0357beef5d9328a2dd8d07ad7b39c87ac55e4.tar.bz2 |
Updated Copyright claims
- updated reference dates;
- removed reference to Community Edition;
- normalized logging using Clipperz.log[Warn|Error|Debug]
Diffstat (limited to 'frontend/gamma/js/Clipperz/ByteArray.js') (more/less context) (show whitespace changes)
-rw-r--r-- | frontend/gamma/js/Clipperz/ByteArray.js | 71 |
1 files changed, 16 insertions, 55 deletions
diff --git a/frontend/gamma/js/Clipperz/ByteArray.js b/frontend/gamma/js/Clipperz/ByteArray.js index ae586e7..22c7c6e 100644 --- a/frontend/gamma/js/Clipperz/ByteArray.js +++ b/frontend/gamma/js/Clipperz/ByteArray.js | |||
@@ -1,34 +1,32 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | 24 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } |
27 | 25 | ||
28 | //============================================================================= | 26 | //============================================================================= |
29 | 27 | ||
30 | Clipperz.ByteArray_abstract = function(args) { | 28 | Clipperz.ByteArray_abstract = function(args) { |
31 | return this; | 29 | return this; |
32 | } | 30 | } |
33 | 31 | ||
34 | Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | 32 | Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { |
@@ -80,29 +78,26 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
80 | throw Clipperz.Base.exception.AbstractMethod; | 78 | throw Clipperz.Base.exception.AbstractMethod; |
81 | }, | 79 | }, |
82 | 80 | ||
83 | //------------------------------------------------------------------------- | 81 | //------------------------------------------------------------------------- |
84 | 82 | ||
85 | 'length': function() { | 83 | 'length': function() { |
86 | throw Clipperz.Base.exception.AbstractMethod; | 84 | throw Clipperz.Base.exception.AbstractMethod; |
87 | }, | 85 | }, |
88 | 86 | ||
89 | //------------------------------------------------------------------------- | 87 | //------------------------------------------------------------------------- |
90 | 88 | ||
91 | 'checkByteValue': function(aValue) { | 89 | 'checkByteValue': function(aValue) { |
92 | //Clipperz.log("aValue", aValue.toString(16)); | ||
93 | //Clipperz.log("(aValue & 0xff)", (aValue & 0xff).toString(16)); | ||
94 | |||
95 | if ((aValue & 0xff) != aValue) { | 90 | if ((aValue & 0xff) != aValue) { |
96 | MochiKit.Logging.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); | 91 | Clipperz.logError("Clipperz.ByteArray.appendByte: the provided value (0x" + aValue.toString(16) + ") is not a byte value."); |
97 | throw Clipperz.ByteArray.exception.InvalidValue; | 92 | throw Clipperz.ByteArray.exception.InvalidValue; |
98 | } | 93 | } |
99 | }, | 94 | }, |
100 | 95 | ||
101 | //------------------------------------------------------------------------- | 96 | //------------------------------------------------------------------------- |
102 | 97 | ||
103 | 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { | 98 | 'xorMergeWithBlock': function(aBlock, anAllignment, paddingMode) { |
104 | var result; | 99 | var result; |
105 | var a, b; | 100 | var a, b; |
106 | var aLength; | 101 | var aLength; |
107 | var bLength; | 102 | var bLength; |
108 | var i, c; | 103 | var i, c; |
@@ -135,46 +130,34 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
135 | for (ii=0; ii<cc; ii++) { | 130 | for (ii=0; ii<cc; ii++) { |
136 | padding.appendByte(0); | 131 | padding.appendByte(0); |
137 | } | 132 | } |
138 | 133 | ||
139 | if (anAllignment == 'left') { | 134 | if (anAllignment == 'left') { |
140 | b = b.appendBlock(padding); | 135 | b = b.appendBlock(padding); |
141 | } else { | 136 | } else { |
142 | b = padding.appendBlock(b); | 137 | b = padding.appendBlock(b); |
143 | } | 138 | } |
144 | } | 139 | } |
145 | } | 140 | } |
146 | 141 | ||
147 | |||
148 | // result = new Clipperz.ByteArray(); | ||
149 | result = this.newInstance(); | 142 | result = this.newInstance(); |
150 | c = a.length(); | 143 | c = a.length(); |
151 | for (i=0; i<c; i++) { | 144 | for (i=0; i<c; i++) { |
152 | result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); | 145 | result.appendByte(a.byteAtIndex(i) ^ b.byteAtIndex(i)); |
153 | } | 146 | } |
154 | 147 | ||
155 | return result; | 148 | return result; |
156 | }, | 149 | }, |
157 | 150 | ||
158 | //------------------------------------------------------------------------- | 151 | //------------------------------------------------------------------------- |
159 | /* | ||
160 | 'shiftLeft': function(aNumberOfBitsToShift) { | ||
161 | var result; | ||
162 | |||
163 | result = this.clone(); //??????????? | ||
164 | |||
165 | return result; | ||
166 | }, | ||
167 | */ | ||
168 | //------------------------------------------------------------------------- | ||
169 | 152 | ||
170 | 'appendBlock': function(aBlock) { | 153 | 'appendBlock': function(aBlock) { |
171 | throw Clipperz.Base.exception.AbstractMethod; | 154 | throw Clipperz.Base.exception.AbstractMethod; |
172 | }, | 155 | }, |
173 | 156 | ||
174 | //------------------------------------------------------------------------- | 157 | //------------------------------------------------------------------------- |
175 | 158 | ||
176 | 'appendByte': function(aValue) { | 159 | 'appendByte': function(aValue) { |
177 | throw Clipperz.Base.exception.AbstractMethod; | 160 | throw Clipperz.Base.exception.AbstractMethod; |
178 | }, | 161 | }, |
179 | 162 | ||
180 | 'appendBytes': function(args) { | 163 | 'appendBytes': function(args) { |
@@ -283,25 +266,24 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
283 | var selectedByteMask; | 266 | var selectedByteMask; |
284 | 267 | ||
285 | bytePosition = this.length() - Math.ceil((aBitPosition + 1)/ 8); | 268 | bytePosition = this.length() - Math.ceil((aBitPosition + 1)/ 8); |
286 | bitPositionInSelectedByte = aBitPosition % 8; | 269 | bitPositionInSelectedByte = aBitPosition % 8; |
287 | selectedByte = this.byteAtIndex(bytePosition); | 270 | selectedByte = this.byteAtIndex(bytePosition); |
288 | 271 | ||
289 | if (bitPositionInSelectedByte > 0) { | 272 | if (bitPositionInSelectedByte > 0) { |
290 | selectedByteMask = (1 << bitPositionInSelectedByte); | 273 | selectedByteMask = (1 << bitPositionInSelectedByte); |
291 | } else { | 274 | } else { |
292 | selectedByteMask = 1; | 275 | selectedByteMask = 1; |
293 | } | 276 | } |
294 | result = selectedByte & selectedByteMask ? 1 : 0; | 277 | result = selectedByte & selectedByteMask ? 1 : 0; |
295 | //console.log("aBitPosition: " + aBitPosition + ", length: " + this.length() + ", bytePosition: " + bytePosition + ", bitPositionInSelectedByte: " + bitPositionInSelectedByte + ", selectedByteMask: " + selectedByteMask); | ||
296 | 278 | ||
297 | return result; | 279 | return result; |
298 | }, | 280 | }, |
299 | 281 | ||
300 | //------------------------------------------------------------------------- | 282 | //------------------------------------------------------------------------- |
301 | 283 | ||
302 | 'bitBlockAtIndexWithSize': function(aBitPosition, aSize) { | 284 | 'bitBlockAtIndexWithSize': function(aBitPosition, aSize) { |
303 | var result; | 285 | var result; |
304 | var bitValue; | 286 | var bitValue; |
305 | var i,c; | 287 | var i,c; |
306 | 288 | ||
307 | result = 0; | 289 | result = 0; |
@@ -312,27 +294,24 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
312 | } | 294 | } |
313 | 295 | ||
314 | return result; | 296 | return result; |
315 | }, | 297 | }, |
316 | 298 | ||
317 | //------------------------------------------------------------------------- | 299 | //------------------------------------------------------------------------- |
318 | 300 | ||
319 | 'asString': function() { | 301 | 'asString': function() { |
320 | varresult; | 302 | varresult; |
321 | varlength; | 303 | varlength; |
322 | vari; | 304 | vari; |
323 | 305 | ||
324 | //var startTime = new Date(); | ||
325 | |||
326 | //# result = ""; | ||
327 | result = []; | 306 | result = []; |
328 | 307 | ||
329 | i = 0; | 308 | i = 0; |
330 | length = this.length(); | 309 | length = this.length(); |
331 | 310 | ||
332 | while (i < length) { | 311 | while (i < length) { |
333 | varcurrentCharacter; | 312 | varcurrentCharacter; |
334 | varcurrentByte; | 313 | varcurrentByte; |
335 | varunicode; | 314 | varunicode; |
336 | 315 | ||
337 | currentByte = this.byteAtIndex(i); | 316 | currentByte = this.byteAtIndex(i); |
338 | 317 | ||
@@ -356,83 +335,65 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
356 | } else { //11110xxx 10xxxxxx 10xxxxxx 10xxxxxx | 335 | } else { //11110xxx 10xxxxxx 10xxxxxx 10xxxxxx |
357 | unicode = (currentByte & 0x07) << (6+6+6); | 336 | unicode = (currentByte & 0x07) << (6+6+6); |
358 | i++; currentByte = this.byteAtIndex(i); | 337 | i++; currentByte = this.byteAtIndex(i); |
359 | unicode = unicode | ((currentByte & 0x3f) << (6+6)); | 338 | unicode = unicode | ((currentByte & 0x3f) << (6+6)); |
360 | i++; currentByte = this.byteAtIndex(i); | 339 | i++; currentByte = this.byteAtIndex(i); |
361 | unicode = unicode | ((currentByte & 0x3f) << 6); | 340 | unicode = unicode | ((currentByte & 0x3f) << 6); |
362 | i++; currentByte = this.byteAtIndex(i); | 341 | i++; currentByte = this.byteAtIndex(i); |
363 | unicode = unicode | (currentByte & 0x3f); | 342 | unicode = unicode | (currentByte & 0x3f); |
364 | 343 | ||
365 | currentCharacter = String.fromCharCode(unicode); | 344 | currentCharacter = String.fromCharCode(unicode); |
366 | } | 345 | } |
367 | 346 | ||
368 | // result += currentCharacter; | ||
369 | result.push(currentCharacter); | 347 | result.push(currentCharacter); |
370 | i++; | 348 | i++; |
371 | } | 349 | } |
372 | 350 | ||
373 | //MochiKit.Logging.logDebug("[" + (new Date() - startTime) + "] ByteArray.asString"); | ||
374 | |||
375 | // return result; | ||
376 | return result.join(""); | 351 | return result.join(""); |
377 | }, | 352 | }, |
378 | 353 | ||
379 | //------------------------------------------------------------------------- | 354 | //------------------------------------------------------------------------- |
380 | 355 | ||
381 | 'toHexString': function() { | 356 | 'toHexString': function() { |
382 | throw Clipperz.Base.exception.AbstractMethod; | 357 | throw Clipperz.Base.exception.AbstractMethod; |
383 | }, | 358 | }, |
384 | 359 | ||
385 | //------------------------------------------------------------------------- | 360 | //------------------------------------------------------------------------- |
386 | 361 | ||
387 | 'base64map': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", | 362 | 'base64map': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/", |
388 | 'base64mapIndex': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(''), | 363 | 'base64mapIndex': "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".split(''), |
389 | //'base64mapInvertedIndex': { | ||
390 | // 'A': 0, 'B': 1, 'C': 2, 'D': 3, 'E': 4, 'F': 5, 'G': 6, 'H': 7, 'I': 8, 'J': 9, | ||
391 | // 'K': 10, 'L': 11, 'M': 12, 'N': 13, 'O': 14, 'P': 15, 'Q': 16, 'R': 17, 'S': 18, 'T': 19, | ||
392 | // 'U': 20, 'V': 21, 'W': 22, 'X': 23, 'Y': 24, 'Z': 25, 'a': 26, 'b': 27, 'c': 28, 'd': 29, | ||
393 | // 'e': 30, 'f': 31, 'g': 32, 'h': 33, 'i': 34, 'j': 35, 'k': 36, 'l': 37, 'm': 38, 'n': 39, | ||
394 | // 'o': 40, 'p': 41, 'q': 42, 'r': 43, 's': 44, 't': 45, 'u': 46, 'v': 47, 'w': 48, 'x': 49, | ||
395 | // 'y': 50, 'z': 51, '0': 52, '1': 53, '2': 54, '3': 55, '4': 56, '5': 57, '6': 58, '7': 59, | ||
396 | // '8': 60, '9': 61, '+': 62, '/': 63, | ||
397 | // "=": -1}, | ||
398 | 364 | ||
399 | //------------------------------------------------------------------------- | 365 | //------------------------------------------------------------------------- |
400 | 366 | ||
401 | 'appendBase64String': function(aValue) { | 367 | 'appendBase64String': function(aValue) { |
402 | var i; | 368 | var i; |
403 | var length; | 369 | var length; |
404 | 370 | ||
405 | length = aValue.length; | 371 | length = aValue.length; |
406 | 372 | ||
407 | if ((length % 4) != 0) { | 373 | if ((length % 4) != 0) { |
408 | MochiKit.Logging.logError("the value passed to the 'ByteArray.setBase64Value' is not correct"); | 374 | Clipperz.logError("the value passed to the 'ByteArray.setBase64Value' is not correct"); |
409 | throw Clipperz.ByteArray.exception.InvalidValue; | 375 | throw Clipperz.ByteArray.exception.InvalidValue; |
410 | } | 376 | } |
411 | 377 | ||
412 | i = 0; | 378 | i = 0; |
413 | while (i<length) { | 379 | while (i<length) { |
414 | var value1, value2, value3, value4; | 380 | var value1, value2, value3, value4; |
415 | var byte1, byte2, byte3; | 381 | var byte1, byte2, byte3; |
416 | 382 | ||
417 | value1 = this.base64map.indexOf(aValue.charAt(i)); | 383 | value1 = this.base64map.indexOf(aValue.charAt(i)); |
418 | value2 = this.base64map.indexOf(aValue.charAt(i+1)); | 384 | value2 = this.base64map.indexOf(aValue.charAt(i+1)); |
419 | value3 = this.base64map.indexOf(aValue.charAt(i+2)); | 385 | value3 = this.base64map.indexOf(aValue.charAt(i+2)); |
420 | value4 = this.base64map.indexOf(aValue.charAt(i+3)); | 386 | value4 = this.base64map.indexOf(aValue.charAt(i+3)); |
421 | 387 | ||
422 | // value1 = this.base64mapInvertedIndex[aValue.charAt(i)]; | ||
423 | // value2 = this.base64mapInvertedIndex[aValue.charAt(i+1)]; | ||
424 | // value3 = this.base64mapInvertedIndex[aValue.charAt(i+2)]; | ||
425 | // value4 = this.base64mapInvertedIndex[aValue.charAt(i+3)]; | ||
426 | |||
427 | byte1 = (value1 << 2) | ((value2 & 0x30) >> 4); | 388 | byte1 = (value1 << 2) | ((value2 & 0x30) >> 4); |
428 | if (value3 != -1) { | 389 | if (value3 != -1) { |
429 | byte2 = ((value2 & 0x0f) << 4) | ((value3 & 0x3c) >> 2); | 390 | byte2 = ((value2 & 0x0f) << 4) | ((value3 & 0x3c) >> 2); |
430 | 391 | ||
431 | if (value4 != -1) { | 392 | if (value4 != -1) { |
432 | byte3 = ((value3 & 0x03) << 6) | (value4); | 393 | byte3 = ((value3 & 0x03) << 6) | (value4); |
433 | } else { | 394 | } else { |
434 | byte3 = null; | 395 | byte3 = null; |
435 | } | 396 | } |
436 | } else { | 397 | } else { |
437 | byte2 = null; | 398 | byte2 = null; |
438 | byte3 = null; | 399 | byte3 = null; |
@@ -511,25 +472,25 @@ Clipperz.ByteArray_abstract.prototype = MochiKit.Base.update(null, { | |||
511 | var length; | 472 | var length; |
512 | var value1, value2, value3, value4, value5, value6, value7, value8; | 473 | var value1, value2, value3, value4, value5, value6, value7, value8; |
513 | var byte1, byte2, byte3, byte4, byte5; | 474 | var byte1, byte2, byte3, byte4, byte5; |
514 | 475 | ||
515 | value = aValue.toLowerCase(); | 476 | value = aValue.toLowerCase(); |
516 | value = value.replace(/[\s\-]/g, ''); | 477 | value = value.replace(/[\s\-]/g, ''); |
517 | value = value.replace(/[0o]/g, '0'); | 478 | value = value.replace(/[0o]/g, '0'); |
518 | value = value.replace(/[1il]/g, '1'); | 479 | value = value.replace(/[1il]/g, '1'); |
519 | 480 | ||
520 | length = value.length; | 481 | length = value.length; |
521 | 482 | ||
522 | if ((length % 8) != 0) { | 483 | if ((length % 8) != 0) { |
523 | MochiKit.Logging.logError("the value passed to the 'ByteArray.setBase32Value' is not correct"); | 484 | Clipperz.logError("the value passed to the 'ByteArray.setBase32Value' is not correct"); |
524 | throw Clipperz.ByteArray.exception.InvalidValue; | 485 | throw Clipperz.ByteArray.exception.InvalidValue; |
525 | } | 486 | } |
526 | 487 | ||
527 | i = 0; | 488 | i = 0; |
528 | while (i<length) { | 489 | while (i<length) { |
529 | value1 = this.base32map.indexOf(value.charAt(i)); | 490 | value1 = this.base32map.indexOf(value.charAt(i)); |
530 | value2 = this.base32map.indexOf(value.charAt(i+1)); | 491 | value2 = this.base32map.indexOf(value.charAt(i+1)); |
531 | value3 = this.base32map.indexOf(value.charAt(i+2)); | 492 | value3 = this.base32map.indexOf(value.charAt(i+2)); |
532 | value4 = this.base32map.indexOf(value.charAt(i+3)); | 493 | value4 = this.base32map.indexOf(value.charAt(i+3)); |
533 | value5 = this.base32map.indexOf(value.charAt(i+4)); | 494 | value5 = this.base32map.indexOf(value.charAt(i+4)); |
534 | value6 = this.base32map.indexOf(value.charAt(i+5)); | 495 | value6 = this.base32map.indexOf(value.charAt(i+5)); |
535 | value7 = this.base32map.indexOf(value.charAt(i+6)); | 496 | value7 = this.base32map.indexOf(value.charAt(i+6)); |
@@ -719,25 +680,25 @@ Clipperz.ByteArray_hex = function (args) { | |||
719 | } else if (args.constructor == String) { | 680 | } else if (args.constructor == String) { |
720 | if (args.indexOf("0x") == 0) { | 681 | if (args.indexOf("0x") == 0) { |
721 | varvalue; | 682 | varvalue; |
722 | 683 | ||
723 | value = args.substring(2).toLowerCase(); | 684 | value = args.substring(2).toLowerCase(); |
724 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activate | 685 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activate |
725 | if ((value.length % 2) == 0) { | 686 | if ((value.length % 2) == 0) { |
726 | this._value = value; | 687 | this._value = value; |
727 | } else { | 688 | } else { |
728 | this._value = "0" + value; | 689 | this._value = "0" + value; |
729 | } | 690 | } |
730 | } else { | 691 | } else { |
731 | MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); | 692 | Clipperz.logError("Clipperz.ByteArray should be inizialized with an hex string."); |
732 | throw Clipperz.ByteArray.exception.InvalidValue; | 693 | throw Clipperz.ByteArray.exception.InvalidValue; |
733 | } | 694 | } |
734 | } else { | 695 | } else { |
735 | varvalue; | 696 | varvalue; |
736 | vari,c; | 697 | vari,c; |
737 | 698 | ||
738 | c = args.length; | 699 | c = args.length; |
739 | value = new Array(c); | 700 | value = new Array(c); |
740 | for (i=0; i<c; i++) { | 701 | for (i=0; i<c; i++) { |
741 | value.push(Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i))); | 702 | value.push(Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i))); |
742 | } | 703 | } |
743 | 704 | ||
@@ -905,25 +866,25 @@ Clipperz.ByteArray_array = function (args) { | |||
905 | var result; | 866 | var result; |
906 | varvalue; | 867 | varvalue; |
907 | var i, c; | 868 | var i, c; |
908 | 869 | ||
909 | if (args.indexOf("0x") == 0) { | 870 | if (args.indexOf("0x") == 0) { |
910 | 871 | ||
911 | value = args.substring(2).toLowerCase(); | 872 | value = args.substring(2).toLowerCase(); |
912 | if (/[0123456789abcdef]*/.test(value)) { | 873 | if (/[0123456789abcdef]*/.test(value)) { |
913 | if ((value.length % 2) != 0) { | 874 | if ((value.length % 2) != 0) { |
914 | value = "0" + value; | 875 | value = "0" + value; |
915 | } | 876 | } |
916 | } else { | 877 | } else { |
917 | MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); | 878 | Clipperz.logError("Clipperz.ByteArray should be inizialized with an hex string."); |
918 | throw Clipperz.ByteArray.exception.InvalidValue; | 879 | throw Clipperz.ByteArray.exception.InvalidValue; |
919 | } | 880 | } |
920 | 881 | ||
921 | c = value.length / 2 | 882 | c = value.length / 2 |
922 | result = new Array(c); | 883 | result = new Array(c); |
923 | for (i=0; i<c; i++) { | 884 | for (i=0; i<c; i++) { |
924 | result[i] = parseInt(value.substr(i*2, 2), 16); | 885 | result[i] = parseInt(value.substr(i*2, 2), 16); |
925 | } | 886 | } |
926 | 887 | ||
927 | } else { | 888 | } else { |
928 | var unicode; | 889 | var unicode; |
929 | result = []; | 890 | result = []; |
@@ -1106,25 +1067,25 @@ Clipperz.ByteArray_string = function (args) { | |||
1106 | var result; | 1067 | var result; |
1107 | varvalue; | 1068 | varvalue; |
1108 | var i, c; | 1069 | var i, c; |
1109 | 1070 | ||
1110 | if (args.indexOf("0x") == 0) { | 1071 | if (args.indexOf("0x") == 0) { |
1111 | 1072 | ||
1112 | value = args.substring(2).toLowerCase(); | 1073 | value = args.substring(2).toLowerCase(); |
1113 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activated | 1074 | if (/[0123456789abcdef]* /.test(value)) { the space in the regexp shoud be removed if the code is activated |
1114 | if ((value.length % 2) != 0) { | 1075 | if ((value.length % 2) != 0) { |
1115 | value = "0" + value; | 1076 | value = "0" + value; |
1116 | } | 1077 | } |
1117 | } else { | 1078 | } else { |
1118 | MochiKit.Logging.logError("Clipperz.ByteArray should be inizialized with an hex string."); | 1079 | Clipperz.logError("Clipperz.ByteArray should be inizialized with an hex string."); |
1119 | throw Clipperz.ByteArray.exception.InvalidValue; | 1080 | throw Clipperz.ByteArray.exception.InvalidValue; |
1120 | } | 1081 | } |
1121 | } else { | 1082 | } else { |
1122 | value = ""; | 1083 | value = ""; |
1123 | c = args.length; | 1084 | c = args.length; |
1124 | for (i=0; i<c; i++) { | 1085 | for (i=0; i<c; i++) { |
1125 | value += Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i)); | 1086 | value += Clipperz.ByteArray.unicodeToUtf8HexString(args.charCodeAt(i)); |
1126 | } | 1087 | } |
1127 | } | 1088 | } |
1128 | 1089 | ||
1129 | c = value.length / 2 | 1090 | c = value.length / 2 |
1130 | for (i=0; i<c; i++) { | 1091 | for (i=0; i<c; i++) { |