MCPcopy Index your code
hub / github.com/awayjs/core / writeUTFBytes

Method writeUTFBytes

lib/utils/ByteArray.ts:196–215  ·  view source on GitHub ↗
(s: string)

Source from the content-addressed store, hash-verified

194 }
195
196 public writeUTFBytes(s: string) {
197 const escstr = encodeURIComponent(s);
198 const binstr = escstr.replace(/%([0-9A-F]{2})/g, function(match, p1) {
199 return String.fromCharCode(parseInt('0x' + p1));
200 });
201
202 this.ensureWriteableSpace(4 + binstr.length);
203 this.writeInt(binstr.length);
204 for (let i = 0; i < binstr.length; i++) {
205 this.writeUnsignedByte(binstr.charCodeAt(i)); //todo: there are probably faster ways to do this
206 }
207 if (binstr.length % 4) {
208 const paddingbytes: number = binstr.length % 4;
209 for (let i = 0; i < paddingbytes; i++) {
210 this.writeUnsignedByte(0);
211 }
212
213 }
214 return binstr.length;
215 }
216
217 public readInt(): number {
218 const data: DataView = new DataView(this.arraybytes);

Callers

nothing calls this directly

Calls 3

ensureWriteableSpaceMethod · 0.95
writeIntMethod · 0.95
writeUnsignedByteMethod · 0.95

Tested by

no test coverage detected