MCPcopy Create free account
hub / github.com/breck7/scroll / _strToRows

Method _strToRows

external/.scrollLibs.js:17665–17716  ·  view source on GitHub ↗
(str, delimiter, quoteChar, newLineChar = "\n")

Source from the content-addressed store, hash-verified

17663 return this._rowsToParticle(rows, delimiter, false)
17664 }
17665 static _strToRows(str, delimiter, quoteChar, newLineChar = "\n") {
17666 const rows = [[]]
17667 const newLine = "\n"
17668 const length = str.length
17669 let currentAtom = ""
17670 let inQuote = str.substr(0, 1) === quoteChar
17671 let currentPosition = inQuote ? 1 : 0
17672 let nextChar
17673 let isLastChar
17674 let currentRow = 0
17675 let char
17676 let isNextCharAQuote
17677 while (currentPosition < length) {
17678 char = str[currentPosition]
17679 isLastChar = currentPosition + 1 === length
17680 nextChar = str[currentPosition + 1]
17681 isNextCharAQuote = nextChar === quoteChar
17682 if (inQuote) {
17683 if (char !== quoteChar) currentAtom += char
17684 else if (isNextCharAQuote) {
17685 // Both the current and next char are ", so the " is escaped
17686 currentAtom += nextChar
17687 currentPosition++ // Jump 2
17688 } else {
17689 // If the current char is a " and the next char is not, it's the end of the quotes
17690 inQuote = false
17691 if (isLastChar) rows[currentRow].push(currentAtom)
17692 }
17693 } else {
17694 if (char === delimiter) {
17695 rows[currentRow].push(currentAtom)
17696 currentAtom = ""
17697 if (isNextCharAQuote) {
17698 inQuote = true
17699 currentPosition++ // Jump 2
17700 }
17701 } else if (char === newLine) {
17702 rows[currentRow].push(currentAtom)
17703 currentAtom = ""
17704 currentRow++
17705 if (nextChar) rows[currentRow] = []
17706 if (isNextCharAQuote) {
17707 inQuote = true
17708 currentPosition++ // Jump 2
17709 }
17710 } else if (isLastChar) rows[currentRow].push(currentAtom + char)
17711 else currentAtom += char
17712 }
17713 currentPosition++
17714 }
17715 return rows
17716 }
17717 static multiply(particleA, particleB) {
17718 const productParticle = particleA.clone()
17719 productParticle.forEach((particle, index) => {

Callers 1

_getEscapedRowsMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected