Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,99 @@
|
|||
----------------------------------------
|
||||
-- Simplified CSV parser (without escape character support etc.).
|
||||
-- First line is interrepted as header with column names.
|
||||
-- @param {string} csvStr
|
||||
-- @param {string} [sep=","] - single char as string
|
||||
-- @param {string} [eol=RETURN]
|
||||
-- @return {propList}
|
||||
----------------------------------------
|
||||
on parseSimpleCSVString (csvStr, sep, eol)
|
||||
if voidP(sep) then sep=","
|
||||
if voidP(eol) then eol = RETURN
|
||||
lines = explode(eol, csvStr)
|
||||
if lines.getLast()="" then lines.deleteAt(lines.count)
|
||||
res = [:]
|
||||
res[#header] = explode(sep, lines[1])
|
||||
res[#data] = []
|
||||
cnt = lines.count
|
||||
repeat with i = 2 to cnt
|
||||
res[#data].append(explodeBySingleChar(sep, lines[i]))
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Simplified CSV creater (without escape character support etc.).
|
||||
-- @param {propList} csvData
|
||||
-- @param {string} [sep=","]
|
||||
-- @param {string} [eol=RETURN]
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on createSimpleCSVString (csvData, sep, eol)
|
||||
if voidP(sep) then sep=","
|
||||
if voidP(eol) then eol = RETURN
|
||||
res = ""
|
||||
put implode(sep, csvData[#header])&eol after res
|
||||
cnt = csvData[#data].count
|
||||
repeat with i = 1 to cnt
|
||||
put implode(sep, csvData[#data][i])&eol after res
|
||||
end repeat
|
||||
return res
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Explodes string into list
|
||||
-- @param {string} delim
|
||||
-- @param {string} str
|
||||
-- @return {list}
|
||||
----------------------------------------
|
||||
on explode (delim, str)
|
||||
if delim.length=1 then return explodeBySingleChar(delim, str)
|
||||
l = []
|
||||
if voidP(str) then return l
|
||||
dl = delim.length
|
||||
repeat while true
|
||||
pos = offset(delim, str)
|
||||
if pos=0 then exit repeat
|
||||
l.add(str.char[1..pos-1])
|
||||
delete char 1 to pos+dl-1 of str
|
||||
end repeat
|
||||
if pos=0 then pos = 1-dl
|
||||
l.add(str.char[pos+dl..str.length])
|
||||
return l
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Explode string into list based on single char delimiter
|
||||
-- (uses Lingo's build-in 'item' support, therefor faster)
|
||||
-- @param {string} delim
|
||||
-- @param {string} str
|
||||
-- @return {list}
|
||||
----------------------------------------
|
||||
on explodeBySingleChar (delim, str)
|
||||
l = []
|
||||
if voidP(str) then return l
|
||||
od = _player.itemDelimiter
|
||||
_player.itemDelimiter = delim
|
||||
cnt = str.item.count
|
||||
repeat with i = 1 to cnt
|
||||
l.add(str.item[i])
|
||||
end repeat
|
||||
_player.itemDelimiter = od
|
||||
return l
|
||||
end
|
||||
|
||||
----------------------------------------
|
||||
-- Implodes list into string
|
||||
-- @param {string} delim
|
||||
-- @param {list} l
|
||||
-- @return {string}
|
||||
----------------------------------------
|
||||
on implode (delim, l)
|
||||
str = ""
|
||||
cnt = l.count
|
||||
repeat with i = 1 to cnt
|
||||
put l[i]&delim after str
|
||||
end repeat
|
||||
delete char (str.length-delim.length+1) to str.length of str
|
||||
return str
|
||||
end
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
sep = ","
|
||||
eol = numtochar(10)
|
||||
|
||||
-- load CSV string from file
|
||||
fn = _movie.path & "file.csv"
|
||||
fp = xtra("fileIO").new()
|
||||
fp.openFile(fn, 1)
|
||||
csvStr = fp.readFile()
|
||||
fp.closeFile()
|
||||
|
||||
-- parse CSV string into propList
|
||||
csvData = parseSimpleCSVString(csvStr, sep, eol)
|
||||
|
||||
-- add SUM column
|
||||
csvData[#header].append("SUM")
|
||||
repeat with row in csvData[#data]
|
||||
sum = 0
|
||||
repeat with cell in row
|
||||
sum = sum+integer(cell)
|
||||
end repeat
|
||||
row.append(sum)
|
||||
end repeat
|
||||
|
||||
-- create CSV string from updated propList
|
||||
csvString = createSimpleCSVString(csvData, sep, eol)
|
||||
|
||||
-- save CSV string to file
|
||||
fn = _movie.path & "file.csv"
|
||||
fp.openFile(fn, 2)
|
||||
if not fp.status() then fp.delete()
|
||||
fp.createFile(fn)
|
||||
fp.openFile(fn, 2)
|
||||
fp.writeString(csvString)
|
||||
fp.closeFile()
|
||||
|
||||
-- show the CSV string
|
||||
put csvString
|
||||
|
||||
-- "C1,C2,C3,C4,C5,SUM
|
||||
1,5,9,13,17,45
|
||||
2,6,10,14,18,50
|
||||
3,7,11,15,19,55
|
||||
4,8,12,16,20,60
|
||||
"
|
||||
Loading…
Add table
Add a link
Reference in a new issue