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

Method parseBlockScalar

packages/effect/src/unstable/encoding/Yaml.ts:450–493  ·  view source on GitHub ↗
(indicator: string, parentIndent: number)

Source from the content-addressed store, hash-verified

448 }
449
450 private parseBlockScalar(indicator: string, parentIndent: number): string {
451 const style = indicator[0]
452 const chomp = indicator.includes("-") ? "strip" : indicator.includes("+") ? "keep" : "clip"
453 const explicitIndent = Number.parseInt(indicator.replace(/[^1-9]/g, ""), 10)
454 const start = this.index
455 let end = start
456 let contentIndent = Number.isNaN(explicitIndent) ? Number.POSITIVE_INFINITY : parentIndent + explicitIndent
457
458 while (end < this.lines.length) {
459 const line = this.lines[end]
460 if (line.raw.trim().length !== 0 && line.indent <= parentIndent) break
461 if (line.raw.trim().length !== 0) contentIndent = Math.min(contentIndent, line.indent)
462 end++
463 }
464 if (contentIndent === Number.POSITIVE_INFINITY) contentIndent = parentIndent + 1
465
466 const content: Array<string> = []
467 for (let index = start; index < end; index++) {
468 const line = this.lines[index]
469 if (line.raw.trim().length === 0) {
470 content.push("")
471 } else if (line.indent < contentIndent) {
472 this.fail(line, `Expected block scalar indentation of ${contentIndent} spaces`)
473 } else {
474 content.push(line.raw.slice(contentIndent))
475 }
476 }
477 this.index = end
478
479 let output = ""
480 if (style === "|") {
481 output = content.join("\n")
482 } else {
483 for (let index = 0; index < content.length; index++) {
484 output += content[index]
485 if (index < content.length - 1) {
486 output += content[index].length === 0 || content[index + 1].length === 0 ? "\n" : " "
487 }
488 }
489 }
490 if (chomp === "keep") return `${output}\n`
491 output = output.replace(/\n+$/, "")
492 return chomp === "strip" ? output : `${output}\n`
493 }
494
495 private skipIgnored(): void {
496 while (this.index < this.lines.length) {

Callers 1

parseNodeValueMethod · 0.95

Calls 4

failMethod · 0.95
pushMethod · 0.80
joinMethod · 0.80
replaceMethod · 0.45

Tested by

no test coverage detected