Compare equality w/o getString (in the future)

This commit is contained in:
Matt Corallo 2014-07-20 22:06:04 -04:00
parent 1d2e252595
commit 4c3ee6f23b
2 changed files with 12 additions and 6 deletions

View file

@ -99,6 +99,7 @@ window.textsecure = window.textsecure || {};
*********************************/
// Strings/arrays
//TODO: Throw all this shit in favor of consistent types
//TODO: Namespace
var StaticByteBufferProto = new dcodeIO.ByteBuffer().__proto__;
var StaticArrayBufferProto = new ArrayBuffer().__proto__;
var StaticUint8ArrayProto = new Uint8Array().__proto__;
@ -126,6 +127,15 @@ function getStringable(thing) {
thing.__proto__ == StaticWordArrayProto)));
}
function isEqual(a, b, maxLegnth) {
// TODO: Special-case arraybuffers, etc
a = getString(a);
b = getString(b);
if (maxLength === undefined)
maxLength = Math.max(a.length, b.length);
return a.substring(0, Math.min(maxLength, a.length)) == b.substring(0, Math.min(maxLength, b.length));
}
function toArrayBuffer(thing) {
//TODO: Optimize this for specific cases
if (thing === undefined)