Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo committed Oct 7, 2024
1 parent b45d4d2 commit 9fea72f
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions runtime/mlBytes.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ function caml_bytes_set(s, i, c) {
}

//Provides: jsoo_text_encoder
var jsoo_text_encoder = new TextEncoder ();
var jsoo_text_encoder = new TextEncoder();

//Provides: jsoo_text_decoder
var jsoo_text_decoder = new TextDecoder ();
var jsoo_text_decoder = new TextDecoder();

//Provides: caml_bytes_of_utf16_jsstring
//Requires: MlBytes, jsoo_text_encoder
function caml_bytes_of_utf16_jsstring (s) {
function caml_bytes_of_utf16_jsstring(s) {
var a = jsoo_text_encoder.encode(s);
return new MlBytes(4, a, a.length);
}
Expand All @@ -337,8 +337,10 @@ function caml_bytes_of_utf16_jsstring (s) {
//Requires: caml_convert_string_to_bytes, jsoo_is_ascii
//Requires: caml_uint8_array_of_bytes
//Requires: jsoo_text_decoder
function MlBytes (tag, contents, length) {
this.t=tag; this.c=contents; this.l=length;
function MlBytes(tag, contents, length) {
this.t = tag;
this.c = contents;
this.l = length;
}
MlBytes.prototype.toString = function () {
switch (this.t) {
Expand All @@ -356,12 +358,12 @@ MlBytes.prototype.toString = function () {
return this.c;
}
};
MlBytes.prototype.toUtf16 = function (){
if(this.t == 9) return this.c;
MlBytes.prototype.toUtf16 = function () {
if (this.t == 9) return this.c;
var a = caml_uint8_array_of_bytes(this);
return jsoo_text_decoder.decode(a);
}
MlBytes.prototype.slice = function (){
};
MlBytes.prototype.slice = function () {
var content = this.t == 4 ? this.c.slice() : this.c;
return new MlBytes(this.t, content, this.l);
};
Expand Down Expand Up @@ -682,12 +684,12 @@ var jsoo_text_decoder_buff = new ArrayBuffer(1024);
//Requires: jsoo_text_decoder_buff
//If: js-string
function caml_jsstring_of_string(s) {
if(jsoo_is_ascii(s)) return s;
if (jsoo_is_ascii(s)) return s;
var a =
(s.length <= jsoo_text_decoder_buff.length)
? Uint8Array(jsoo_text_decoder_buff, 0, s.length)
: (new Uint8Array(s.length));
for(var i = 0; i < s.length; i++){
s.length <= jsoo_text_decoder_buff.length
? new Uint8Array(jsoo_text_decoder_buff, 0, s.length)
: new Uint8Array(s.length);
for (var i = 0; i < s.length; i++) {
a[i] = s.charCodeAt(i);
}
return jsoo_text_decoder.decode(a);
Expand All @@ -697,7 +699,7 @@ function caml_jsstring_of_string(s) {
//Requires: caml_string_of_array
//Requires: jsoo_text_encoder
//If: js-string
function caml_string_of_jsstring (s) {
function caml_string_of_jsstring(s) {
var a = jsoo_text_encoder.encode(s);
return caml_string_of_array(a);
}
Expand Down

0 comments on commit 9fea72f

Please sign in to comment.