MCPcopy Create free account
hub / github.com/Effect-TS/effect / utf8

Method utf8

packages/sql/pg/src/PgProtocol.ts:535–559  ·  view source on GitHub ↗
(value: string, nul = false)

Source from the content-addressed store, hash-verified

533 }
534
535 utf8(value: string, nul = false): void {
536 const length = value.length
537 if (length <= asciiEncodeLimit) {
538 this.reserve(length + (nul ? 1 : 0))
539 const bytes = this.bytes
540 const start = this.offset
541 let i = 0
542 for (; i < length; i++) {
543 const code = value.charCodeAt(i)
544 if (code > 0x7f) break
545 bytes[start + i] = code
546 }
547 if (i === length) {
548 const offset = start + length
549 if (nul) bytes[offset] = 0
550 this.offset = offset + (nul ? 1 : 0)
551 return
552 }
553 }
554 // UTF-8 takes at most three bytes per UTF-16 code unit, and four for the
555 // two units of a surrogate pair, so this covers any string.
556 this.reserve(length * 3 + (nul ? 1 : 0))
557 this.offset += textEncoder.encodeInto(value, this.bytes.subarray(this.offset)).written
558 if (nul) this.bytes[this.offset++] = 0
559 }
560
561 cString(value: string): void {
562 this.utf8(value, true)

Callers 4

cStringMethod · 0.95
PgProtocol.test.tsFile · 0.80
PgTypes.tsFile · 0.80
writeParameterUnsafeFunction · 0.80

Calls 1

reserveMethod · 0.95

Tested by

no test coverage detected