Skip to content

Commit

Permalink
Fix text
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishmack committed Feb 4, 2024
1 parent 632ff5a commit 067a344
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
3 changes: 2 additions & 1 deletion ghcjs-base.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ library
ghc-prim,
binary >= 0.8 && < 0.11,
bytestring >= 0.10 && < 0.13,
text >= 1.1 && < 2.2,
-- text internals need to be utf8 (text <2.0 is utf16)
text >= 2.0 && < 2.2,
aeson >= 0.8 && < 2.3,
scientific >= 0.3.7 && < 0.4,
vector >= 0.10 && < 0.14,
Expand Down
25 changes: 5 additions & 20 deletions jsbits/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,18 @@
convert a Data.Text buffer with offset/length to a JavaScript string
*/
function h$textToString(arr, off, len) {
var a = [];
var end = off+len;
var k = 0;
var u1 = arr.u1;
var s = '';
for(var i=off;i<end;i++) {
var cc = u1[i];
a[k++] = cc;
if(k === 60000) {
s += String.fromCharCode.apply(this, a);
k = 0;
a = [];
}
}
return s + String.fromCharCode.apply(this, a);
return new TextDecoder().decode(arr.u8.subarray(off, off+len));
}

/*
convert a JavaScript string to a Data.Text buffer, second return
value is length
*/
function h$textFromString(s) {
var l = s.length;
var b = h$newByteArray(l * 2);
var u1 = b.u1;
for(var i=l-1;i>=0;i--) u1[i] = s.charCodeAt(i);
RETURN_UBX_TUP2(b, l);
var encoder = new TextEncoder("utf-8");
u8 = encoder.encode(s);
b = h$wrapBuffer(u8.buffer, true, u8.byteOffset, u8.byteLength);
RETURN_UBX_TUP2(b, u8.byteLength);
}

function h$lazyTextToString(txt) {
Expand Down

0 comments on commit 067a344

Please sign in to comment.