File extension is in extensions list: Difference between revisions

Changed the way to build the list of extensions using “mapIt”; changed the way to test the extension using “anyIt”.
(Replaced "map" by "mapIt".)
(Changed the way to build the list of extensions using “mapIt”; changed the way to test the extension using “anyIt”.)
Line 1,299:
 
===Extra task===
The “splitFile” procedure no longer works in this case. We have to use “endsWith” from the “strutils” module, which changes the logic:
 
<lang nim>import strutils, sequtils
import sequtils
 
let fileNameList = [ "MyData.a##", "MyData.tar.Gz", "MyData.gzip",
"MyData.7z.backup", "MyData...", "MyData",
"MyData_v1.0.tar.bz2", "MyData_v1.0.bz2" ]
 
varconst extListExtList = @mapIt([ "pzipzip", "rar", "7z", "gz", "archive", "A##", "tar.bz2" ], '.' & it.toLowerAscii())
 
extList.apply( proc (ext: string): string = "." & ext.toLowerAscii() )
 
for fileName in fileNameList:
letecho loweredFileNamefileName, =" :", ExtList.anyIt(fileName.toLowerAscii().endsWith(it))</lang>
let matched = extList.any(proc (ext: string) : bool = loweredFileName.endsWith(ext))
echo fileName, " : ", if matched: "true" else: "false"</lang>
 
{{out}}
Anonymous user