Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for large strings and multi-byte Unicode characters #142

Merged
merged 14 commits into from
May 15, 2019
Merged
36 changes: 34 additions & 2 deletions dist/osc-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Licensed under the MIT and GPL 3 licenses.
*/

/* global require, module, process, Buffer, Long */
/* global require, module, process, Buffer, Long, util */

var osc = osc || {};

Expand Down Expand Up @@ -55,6 +55,11 @@ var osc = osc || {};
osc.Long = typeof Long !== "undefined" ? Long :
osc.isNode ? require("long") : undefined;

// Unsupported, non-API member. Can be removed when supported versions
// of Node.js expose TextDecoder as a global, as in the browser.
osc.TextDecoder = typeof TextDecoder !== "undefined" ? TextDecoder :
typeof util !== "undefined" && typeof (util.TextDecoder !== "undefined") ? util.TextDecoder : undefined;

/**
* Wraps the specified object in a DataView.
*
Expand Down Expand Up @@ -164,7 +169,34 @@ var osc = osc || {};
idx = (idx + 3) & ~0x03;
offsetState.idx = idx;

return String.fromCharCode.apply(null, charCodes);
var decoder = osc.isBufferEnv ? osc.readString.withBuffer :
osc.TextDecoder ? osc.readString.withTextDecoder : osc.readString.raw;

return decoder(charCodes);
};

osc.readString.raw = function (charCodes) {
// If no Buffer or TextDecoder, resort to fromCharCode
// This does not properly decode multi-byte Unicode characters.
var str = "";
var sliceSize = 10000;

// Processing the array in chunks so as not to exceed argument
// limit, see https://bugs.webkit.org/show_bug.cgi?id=80797
for (var i = 0; i < charCodes.length; i += sliceSize) {
str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize));
}

return str;
};

osc.readString.withTextDecoder = function (charCodes) {
var data = new Int8Array(charCodes);
return new osc.TextDecoder("utf-8").decode(data);
};

osc.readString.withBuffer = function (charCodes) {
return Buffer.from(charCodes).toString("utf-8");
};

/**
Expand Down
55 changes: 32 additions & 23 deletions dist/osc-browser.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ var osc = osc || {};
}, osc.isBuffer = function(e) {
return osc.isBufferEnv && e instanceof Buffer;
}, osc.Long = "undefined" != typeof Long ? Long : osc.isNode ? require("long") : void 0,
osc.dataView = function(e, t, r) {
osc.TextDecoder = "undefined" != typeof TextDecoder ? TextDecoder : "undefined" != typeof util && (util.TextDecoder,
1) ? util.TextDecoder : void 0, osc.dataView = function(e, t, r) {
return e.buffer ? new DataView(e.buffer, t, r) : e instanceof ArrayBuffer ? new DataView(e, t, r) : new DataView(new Uint8Array(e), t, r);
}, osc.byteArray = function(e) {
if (e instanceof Uint8Array) return e;
Expand All @@ -39,7 +40,15 @@ var osc = osc || {};
}
r.push(i);
}
return n = n + 3 & -4, t.idx = n, String.fromCharCode.apply(null, r);
return n = n + 3 & -4, t.idx = n, (osc.isBufferEnv ? osc.readString.withBuffer : osc.TextDecoder ? osc.readString.withTextDecoder : osc.readString.raw)(r);
}, osc.readString.raw = function(e) {
for (var t = "", r = 0; r < e.length; r += 1e4) t += String.fromCharCode.apply(null, e.slice(r, r + 1e4));
return t;
}, osc.readString.withTextDecoder = function(e) {
var t = new Int8Array(e);
return new osc.TextDecoder("utf-8").decode(t);
}, osc.readString.withBuffer = function(e) {
return Buffer.from(e).toString("utf-8");
}, osc.writeString = function(e) {
for (var t = e + "\0", r = t.length, n = new Uint8Array(r + 3 & -4), i = 0; i < t.length; i++) {
var s = t.charCodeAt(i);
Expand Down Expand Up @@ -380,7 +389,7 @@ var osc = osc || {};
if (a <= e) return A;
} else {
if (e <= -u) return P;
if (u <= e + 1) return S;
if (u <= e + 1) return E;
}
return e < 0 ? l(-e, t).neg() : p(e % i | 0, e / i | 0, t);
}
Expand All @@ -403,21 +412,21 @@ var osc = osc || {};
}
return s.unsigned = t, s;
}
function y(e, t) {
function v(e, t) {
return "number" == typeof e ? l(e, t) : "string" == typeof e ? h(e, t) : p(e.low, e.high, "boolean" == typeof t ? t : e.unsigned);
}
e.exports = n;
var v = null;
var y = null;
try {
v = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 ])), {}).exports;
y = new WebAssembly.Instance(new WebAssembly.Module(new Uint8Array([ 0, 97, 115, 109, 1, 0, 0, 0, 1, 13, 2, 96, 0, 1, 127, 96, 4, 127, 127, 127, 127, 1, 127, 3, 7, 6, 0, 1, 1, 1, 1, 1, 6, 6, 1, 127, 1, 65, 0, 11, 7, 50, 6, 3, 109, 117, 108, 0, 1, 5, 100, 105, 118, 95, 115, 0, 2, 5, 100, 105, 118, 95, 117, 0, 3, 5, 114, 101, 109, 95, 115, 0, 4, 5, 114, 101, 109, 95, 117, 0, 5, 8, 103, 101, 116, 95, 104, 105, 103, 104, 0, 0, 10, 191, 1, 6, 4, 0, 35, 0, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 126, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 127, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 128, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 129, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11, 36, 1, 1, 126, 32, 0, 173, 32, 1, 173, 66, 32, 134, 132, 32, 2, 173, 32, 3, 173, 66, 32, 134, 132, 130, 34, 4, 66, 32, 135, 167, 36, 0, 32, 4, 167, 11 ])), {}).exports;
} catch (e) {}
Object.defineProperty(n.prototype, "__isLong__", {
value: !0
}), n.isLong = g;
var s = {}, o = {};
n.fromInt = r, n.fromNumber = l, n.fromBits = p;
var f = Math.pow;
n.fromString = h, n.fromValue = y;
n.fromString = h, n.fromValue = v;
var i = 4294967296, a = i * i, u = a / 2, w = r(1 << 24), m = r(0);
n.ZERO = m;
var c = r(0, !0);
Expand All @@ -426,10 +435,10 @@ var osc = osc || {};
n.ONE = d;
var b = r(1, !0);
n.UONE = b;
var E = r(-1);
n.NEG_ONE = E;
var S = p(-1, 2147483647, !1);
n.MAX_VALUE = S;
var S = r(-1);
n.NEG_ONE = S;
var E = p(-1, 2147483647, !1);
n.MAX_VALUE = E;
var A = p(-1, -1, !0);
n.MAX_UNSIGNED_VALUE = A;
var P = p(0, -2147483648, !1);
Expand Down Expand Up @@ -478,7 +487,7 @@ var osc = osc || {};
}, B.isEven = function() {
return 0 == (1 & this.low);
}, B.equals = function(e) {
return g(e) || (e = y(e)), (this.unsigned === e.unsigned || this.high >>> 31 != 1 || e.high >>> 31 != 1) && this.high === e.high && this.low === e.low;
return g(e) || (e = v(e)), (this.unsigned === e.unsigned || this.high >>> 31 != 1 || e.high >>> 31 != 1) && this.high === e.high && this.low === e.low;
}, B.eq = B.equals, B.notEquals = function(e) {
return !this.eq(e);
}, B.neq = B.notEquals, B.ne = B.notEquals, B.lessThan = function(e) {
Expand All @@ -490,21 +499,21 @@ var osc = osc || {};
}, B.gt = B.greaterThan, B.greaterThanOrEqual = function(e) {
return 0 <= this.comp(e);
}, B.gte = B.greaterThanOrEqual, B.ge = B.greaterThanOrEqual, B.compare = function(e) {
if (g(e) || (e = y(e)), this.eq(e)) return 0;
if (g(e) || (e = v(e)), this.eq(e)) return 0;
var t = this.isNegative(), r = e.isNegative();
return t && !r ? -1 : !t && r ? 1 : this.unsigned ? e.high >>> 0 > this.high >>> 0 || e.high === this.high && e.low >>> 0 > this.low >>> 0 ? -1 : 1 : this.sub(e).isNegative() ? -1 : 1;
}, B.comp = B.compare, B.negate = function() {
return !this.unsigned && this.eq(P) ? P : this.not().add(d);
}, B.neg = B.negate, B.add = function(e) {
g(e) || (e = y(e));
g(e) || (e = v(e));
var t = this.high >>> 16, r = 65535 & this.high, n = this.low >>> 16, i = 65535 & this.low, s = e.high >>> 16, o = 65535 & e.high, a = e.low >>> 16, u = 0, c = 0, h = 0, f = 0;
return h += (f += i + (65535 & e.low)) >>> 16, c += (h += n + a) >>> 16, u += (c += r + o) >>> 16,
u += t + s, p((h &= 65535) << 16 | (f &= 65535), (u &= 65535) << 16 | (c &= 65535), this.unsigned);
}, B.subtract = function(e) {
return g(e) || (e = y(e)), this.add(e.neg());
return g(e) || (e = v(e)), this.add(e.neg());
}, B.sub = B.subtract, B.multiply = function(e) {
if (this.isZero()) return m;
if (g(e) || (e = y(e)), v) return p(v.mul(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned);
if (g(e) || (e = v(e)), y) return p(y.mul(this.low, this.high, e.low, e.high), y.get_high(), this.unsigned);
if (e.isZero()) return m;
if (this.eq(P)) return e.isOdd() ? P : m;
if (e.eq(P)) return this.isOdd() ? P : m;
Expand All @@ -516,16 +525,16 @@ var osc = osc || {};
c += (h += r * u) >>> 16, h &= 65535, c += (h += n * a) >>> 16, h &= 65535, c += (h += i * o) >>> 16,
c += t * u + r * a + n * o + i * s, p((f &= 65535) << 16 | (d &= 65535), (c &= 65535) << 16 | (h &= 65535), this.unsigned);
}, B.mul = B.multiply, B.divide = function(e) {
if (g(e) || (e = y(e)), e.isZero()) throw Error("division by zero");
if (v) return this.unsigned || -2147483648 !== this.high || -1 !== e.low || -1 !== e.high ? p((this.unsigned ? v.div_u : v.div_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this;
if (g(e) || (e = v(e)), e.isZero()) throw Error("division by zero");
if (y) return this.unsigned || -2147483648 !== this.high || -1 !== e.low || -1 !== e.high ? p((this.unsigned ? y.div_u : y.div_s)(this.low, this.high, e.low, e.high), y.get_high(), this.unsigned) : this;
if (this.isZero()) return this.unsigned ? c : m;
var t, r, n;
if (this.unsigned) {
if (e.unsigned || (e = e.toUnsigned()), e.gt(this)) return c;
if (e.gt(this.shru(1))) return b;
n = c;
} else {
if (this.eq(P)) return e.eq(d) || e.eq(E) ? P : e.eq(P) ? d : (t = this.shr(1).div(e).shl(1)).eq(m) ? e.isNegative() ? d : E : (r = this.sub(e.mul(t)),
if (this.eq(P)) return e.eq(d) || e.eq(S) ? P : e.eq(P) ? d : (t = this.shr(1).div(e).shl(1)).eq(m) ? e.isNegative() ? d : S : (r = this.sub(e.mul(t)),
n = t.add(r.div(e)));
if (e.eq(P)) return this.unsigned ? c : m;
if (this.isNegative()) return e.isNegative() ? this.neg().div(e.neg()) : this.neg().div(e).neg();
Expand All @@ -539,15 +548,15 @@ var osc = osc || {};
}
return n;
}, B.div = B.divide, B.modulo = function(e) {
return g(e) || (e = y(e)), v ? p((this.unsigned ? v.rem_u : v.rem_s)(this.low, this.high, e.low, e.high), v.get_high(), this.unsigned) : this.sub(this.div(e).mul(e));
return g(e) || (e = v(e)), y ? p((this.unsigned ? y.rem_u : y.rem_s)(this.low, this.high, e.low, e.high), y.get_high(), this.unsigned) : this.sub(this.div(e).mul(e));
}, B.mod = B.modulo, B.rem = B.modulo, B.not = function() {
return p(~this.low, ~this.high, this.unsigned);
}, B.and = function(e) {
return g(e) || (e = y(e)), p(this.low & e.low, this.high & e.high, this.unsigned);
return g(e) || (e = v(e)), p(this.low & e.low, this.high & e.high, this.unsigned);
}, B.or = function(e) {
return g(e) || (e = y(e)), p(this.low | e.low, this.high | e.high, this.unsigned);
return g(e) || (e = v(e)), p(this.low | e.low, this.high | e.high, this.unsigned);
}, B.xor = function(e) {
return g(e) || (e = y(e)), p(this.low ^ e.low, this.high ^ e.high, this.unsigned);
return g(e) || (e = v(e)), p(this.low ^ e.low, this.high ^ e.high, this.unsigned);
}, B.shiftLeft = function(e) {
return g(e) && (e = e.toInt()), 0 == (e &= 63) ? this : e < 32 ? p(this.low << e, this.high << e | this.low >>> 32 - e, this.unsigned) : p(0, this.low << e - 32, this.unsigned);
}, B.shl = B.shiftLeft, B.shiftRight = function(e) {
Expand Down
36 changes: 34 additions & 2 deletions dist/osc-chromeapp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Licensed under the MIT and GPL 3 licenses.
*/

/* global require, module, process, Buffer, Long */
/* global require, module, process, Buffer, Long, util */

var osc = osc || {};

Expand Down Expand Up @@ -55,6 +55,11 @@ var osc = osc || {};
osc.Long = typeof Long !== "undefined" ? Long :
osc.isNode ? require("long") : undefined;

// Unsupported, non-API member. Can be removed when supported versions
// of Node.js expose TextDecoder as a global, as in the browser.
osc.TextDecoder = typeof TextDecoder !== "undefined" ? TextDecoder :
typeof util !== "undefined" && typeof (util.TextDecoder !== "undefined") ? util.TextDecoder : undefined;

/**
* Wraps the specified object in a DataView.
*
Expand Down Expand Up @@ -164,7 +169,34 @@ var osc = osc || {};
idx = (idx + 3) & ~0x03;
offsetState.idx = idx;

return String.fromCharCode.apply(null, charCodes);
var decoder = osc.isBufferEnv ? osc.readString.withBuffer :
osc.TextDecoder ? osc.readString.withTextDecoder : osc.readString.raw;

return decoder(charCodes);
};

osc.readString.raw = function (charCodes) {
// If no Buffer or TextDecoder, resort to fromCharCode
// This does not properly decode multi-byte Unicode characters.
var str = "";
var sliceSize = 10000;

// Processing the array in chunks so as not to exceed argument
// limit, see https://bugs.webkit.org/show_bug.cgi?id=80797
for (var i = 0; i < charCodes.length; i += sliceSize) {
str += String.fromCharCode.apply(null, charCodes.slice(i, i + sliceSize));
}

return str;
};

osc.readString.withTextDecoder = function (charCodes) {
var data = new Int8Array(charCodes);
return new osc.TextDecoder("utf-8").decode(data);
};

osc.readString.withBuffer = function (charCodes) {
return Buffer.from(charCodes).toString("utf-8");
};

/**
Expand Down
Loading