File extension is in extensions list: Difference between revisions
Content added Content deleted
m (→{{header|Haskell}}: Tidied) |
(Added XPL0 example.) |
||
Line 2,479: | Line 2,479: | ||
MyData_v1.0.tar.bz2 true (extension: tar.bz2) |
MyData_v1.0.tar.bz2 true (extension: tar.bz2) |
||
MyData_v1.0.bz2 false |
MyData_v1.0.bz2 false |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">string 0; |
|||
func ToUpper(C); \Convert character to upper case |
|||
int C; |
|||
return if C>=^a & C<=^z then C&$DF else C; |
|||
func HasExt(File, Ext); \Return 'true' if File has Ext(ension) |
|||
char File, Ext; |
|||
int I, J; |
|||
[I:= 0; |
|||
while File(I) # 0 do I:= I+1; |
|||
while File(I) # ^. and I > 0 do I:= I-1; |
|||
I:= I+1; |
|||
J:= 0; |
|||
loop [if ToUpper(File(I+J)) # ToUpper(Ext(J)) then return false; |
|||
if Ext(J) = 0 then return true; |
|||
J:= J+1; |
|||
]; |
|||
]; |
|||
int Exts, Ext, Files, Test; |
|||
[Exts:= ["zip", "rar", "7z", "gz", "archive", "A##"]; |
|||
Files:= ["MyData.a##", "MyData.tar.Gz", "MyData.gzip" , "MyData.7z.backup", |
|||
"MyData...", "MyData" ]; |
|||
for Test:= 0 to 5 do |
|||
[for Ext:= 0 to 5 do |
|||
[if HasExt(Files(Test), Exts(Ext)) then |
|||
[Text(0, " true : "); |
|||
Ext:= 100; |
|||
]; |
|||
]; |
|||
if Ext = 6 then Text(0, "false : "); |
|||
Text(0, Files(Test)); |
|||
CrLf(0); |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
true : MyData.a## |
|||
true : MyData.tar.Gz |
|||
false : MyData.gzip |
|||
false : MyData.7z.backup |
|||
false : MyData... |
|||
false : MyData |
|||
</pre> |
</pre> |
||