Jump to content

Extract file extension: Difference between revisions

m
→‎{{header|Sidef}}: updated the code to match the current specification of the task
(→‎{{header|Fortran}}: Happily, no change is needed beyond adding the new trials.)
m (→‎{{header|Sidef}}: updated the code to match the current specification of the task)
Line 1,084:
 
=={{header|Sidef}}==
<lang ruby>func extension (filename) {
filename.match(/(\.[a-z0-9]+)\z/i).to_s
 
var files = [
{{update|Sidef|The format of a suffix has been clarified, and the test-cases have been replaced with new ones.}}
'http://example.com/download.tar.gz',
 
'CharacterModel.3DS',
<lang ruby>func extension (filename) {
'.desktop',
given(filename.split('.').last) {
'document',
when(filename) { "" }
'document.txt_backup',
when(/[\/_]/) { "" }
'/etc/pam.d/login',
default { "." + _ }
]
}
 
files.each {|f|
['mywebsite.com/picture/image.png',
printf("%-36s -> %-11s\n", f.dump, extension(f).dump)
'http://mywebsite.com/picture/image.png',
}</lang>
'myuniquefile.longextension',
'IAmAFileWithoutExtension',
'/path/to.my/file',
'file.odd_one',
].each {|f| say "#{f} -> #{extension(f).dump}" }</lang>
{{out}}
<pre>
mywebsite"http://example.com/picture/imagedownload.pngtar.gz" -> ".pnggz"
"CharacterModel.3DS" -> ".3DS"
http://mywebsite.com/picture/image.png -> ".png"
".desktop" -> ".desktop"
myuniquefile.longextension -> ".longextension"
"document" -> ""
IAmAFileWithoutExtension -> ""
"document.txt_backup" -> ""
/path/to.my/file -> ""
"/etc/pam.d/login" -> ""
file.odd_one -> ""
</pre>
 
2,756

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.