-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rudimentary CSV parsing helper module + various fixes & tests
- Loading branch information
Showing
27 changed files
with
821 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
|
||
module Str with ... | ||
|
||
fun (~) concat(a, b) = a + b | ||
|
||
fun string(value) = globalThis.String(value) | ||
fun (~) concat2(a, b) = a + b | ||
|
||
fun concat(...xs) = xs.join("") | ||
|
||
fun from(value) = globalThis.String(value) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import Str from "./../Str.mjs"; | ||
import Predef from "./../Predef.mjs"; | ||
function CSV(strDelimiter1) { return new CSV.class(strDelimiter1); } | ||
CSV.class = class CSV { | ||
constructor(strDelimiter) { | ||
this.strDelimiter = strDelimiter; | ||
let tmp, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; | ||
tmp = this.strDelimiter || ","; | ||
this.strDelimiter = tmp; | ||
tmp1 = "(\\" + this.strDelimiter; | ||
tmp2 = tmp1 + "|\\r?\\n|\\r|^)"; | ||
tmp3 = "([^\"\\" + this.strDelimiter; | ||
tmp4 = tmp3 + "\\r\\n]*))"; | ||
tmp5 = "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + tmp4; | ||
tmp6 = tmp2 + tmp5; | ||
tmp7 = new RegExp(tmp6, "gi"); | ||
this.objPattern = tmp7; | ||
} | ||
toArrays(strData) { | ||
let arrData, arrMatches, scrut, strMatchedDelimiter, scrut1, strMatchedValue, scrut2, tmp, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6; | ||
arrData = [ | ||
[] | ||
]; | ||
tmp7: while (true) { | ||
arrMatches = this.objPattern.exec(strData) ?? null; | ||
scrut = arrMatches !== null; | ||
if (scrut) { | ||
strMatchedDelimiter = arrMatches[1]; | ||
tmp = strMatchedDelimiter != this.strDelimiter; | ||
scrut1 = strMatchedDelimiter.length && tmp; | ||
if (scrut1) { | ||
tmp1 = arrData.push([]) ?? null; | ||
} else { | ||
tmp1 = null; | ||
} | ||
scrut2 = arrMatches[2]; | ||
if (scrut2) { | ||
tmp2 = new RegExp("\"\"", "g"); | ||
tmp3 = arrMatches[2].replace(tmp2, "\""); | ||
} else { | ||
tmp3 = arrMatches[3]; | ||
} | ||
strMatchedValue = tmp3; | ||
tmp4 = arrData.length - 1; | ||
tmp5 = arrData.at(tmp4) ?? null; | ||
tmp6 = tmp5.push(strMatchedValue) ?? null; | ||
continue tmp7; | ||
} else { | ||
tmp6 = null; | ||
} | ||
break; | ||
} | ||
return arrData; | ||
} | ||
toString() { return "CSV(" + this.strDelimiter + ")"; } | ||
}; | ||
null | ||
export default CSV; |
Oops, something went wrong.