Add 16bit string reader/writer
This commit is contained in:
parent
32b1340266
commit
f3b2d043b9
4 changed files with 42 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue