make strings objects

This commit is contained in:
2023-03-19 20:05:43 +00:00
parent 2e04bb0152
commit a080152aee
9 changed files with 559 additions and 181 deletions

34
modules/csv/init.ar Normal file
View File

@@ -0,0 +1,34 @@
let read(path) = do
file = open(path, "r")
text = file.text()
data = []
splitlines = text.split("\n")
i = 0
while (i < splitlines.length) do
values = []
in_quotes = false
start = 0
line = splitlines[i]
j = 0
while (j < line.length) do
char = line[j]
if (char == "," && not in_quotes) do
value = line[start:j].rightstrip("\r").strip()
if (value && value[0] == "\"" && value[-1] == "\"") do
value = value[1:value.length - 1]
value = value.replace("\"\"", "\"")
values.append(value)
start = j + 1
else if (char == "\"") do
in_quotes = not in_quotes
if (j == line.length - 1) do
value = line[start:j + 1].rightstrip("\r").strip()
if (value && value[0] == "\"" && value[-1] == "\"") do
value = value[1:value.length - 1]
value = value.replace("\"\"", "\"")
values.append(value)
j = j + 1
data.append(values)
i = i + 1
return data