Add 16bit string reader/writer

This commit is contained in:
Holly Stubbs 2023-05-02 10:10:47 +01:00 committed by Holly
parent 32b1340266
commit f3b2d043b9
Signed by: tgpholly
GPG Key ID: B8583C4B7D18119E
4 changed files with 42 additions and 0 deletions

View File

@ -71,4 +71,15 @@ export class ReaderBE extends ReaderBase implements IReader {
return text;
}
public readString16() {
const length = this.readUShort();
let text:string = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUShort());
}
return text;
}
}

View File

@ -71,4 +71,15 @@ export class ReaderLE extends ReaderBase implements IReader {
return text;
}
public readString16() {
const length = this.readUShort();
let text:string = "";
for (let i = 0; i < length; i++) {
text += String.fromCharCode(this.readUShort());
}
return text;
}
}

View File

@ -133,4 +133,14 @@ export class WriterBE extends WriterBase implements IWriter {
return this;
}
public writeString16(text:string) {
this.writeUShort(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUShort(text.charCodeAt(i));
}
return this;
}
}

View File

@ -132,4 +132,14 @@ export class WriterLE extends WriterBase implements IWriter {
return this;
}
public writeString16(text:string) {
this.writeUShort(text.length);
for (let i = 0; i < text.length; i++) {
this.writeUShort(text.charCodeAt(i));
}
return this;
}
}