I get the following:
doc.getDataObjectContents() I get an additional first character, but only if the text included is actually utf-16.
util.streamFromString() seems to fail entirely on characters with two unicode code units.
Am I doing something wrong?
Code: Select all
// test string from stream
function testStringStreamUTF16(str) {
const cName = 'tempTest.txt';
const tempDoc = app.newDoc();
tempDoc.createDataObject({
cName,
cValue: JSON.stringify(str,null,1),
cMIMEType: 'utf-16'
});
function outDiffs(q,p) {
try {
console.println([q.length, p.length]);
for (let i in q) {
if (q.charCodeAt(i) !== p.charCodeAt(i)) console.println(i + ": " + [q.charAt(i),p.charAt(i)] + " : " + [q.charCodeAt(i).toString(16), p.charCodeAt(i).toString(16)]);
}
} catch (e) {
console.println(e);
}
}
const q = JSON.stringify(str,null,1);
let p = util.stringFromStream(tempDoc.getDataObjectContents(cName), 'utf-16');
console.println("data object");
outDiffs(q,p);
p = util.stringFromStream(util.streamFromString(q, 'utf-16'), 'utf-16');
console.println("stream from string");
outDiffs(q,p);
}
testStringStreamUTF16([`ヸ摭㝑ůڬม疯ⅲॼᲥㆬ₌兼ৡ⏵c拀㒧刾⁊炨ᚃ屚Ñዘ㚧㨯晢Ⳃᠽઔڹ㒥戔က瀣‸∂勁稫䂥ٌ̦ቝ偸懠㑧瀪悇ᅀۙ⍣愇䗆㘲扡ࢩ瀥⥦疼况ငⷲ瑆懑剒ᮥ⌣䛆े≦䠭備怠࣎㢌Ạᐣ倨儞懲ᅧ簱䤁ੀኯ䲠䗁翆䑆ؚհ癴庨凌ᜄ䕶摻慤䠱╗⁐捆Ɉ⯧≅拐ϐ䊢ᐨ凚ສ憤ʼ姴䌂喓㑚ĩ䎠䜨ṟᅞᲀ䢠崴䌮ᐮ澵⯙甦።ଂ坒ŵ愎ᬫ䐈䉈疢琭戆 㑨ˊ䋄桀\"宁߃挈䣏ਯᄰ䬀`]);