3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-23 12:29:27 +01:00
pbot/PBot/Utils/SafeFilename.pm

24 lines
444 B
Perl
Raw Normal View History

2017-09-05 04:06:31 +02:00
package PBot::Utils::SafeFilename;
2020-02-15 23:38:32 +01:00
2017-09-05 04:06:31 +02:00
use 5.010; use warnings;
2019-07-11 03:40:53 +02:00
use feature 'unicode_strings';
2017-09-05 04:06:31 +02:00
require Exporter;
2020-02-15 23:38:32 +01:00
our @ISA = qw/Exporter/;
2017-09-05 04:06:31 +02:00
our @EXPORT = qw/safe_filename/;
sub safe_filename {
2020-02-15 23:38:32 +01:00
my $name = shift;
my $safe = '';
2017-09-05 04:06:31 +02:00
2020-02-15 23:38:32 +01:00
while ($name =~ m/(.)/gms) {
if ($1 eq '&') { $safe .= '&'; }
elsif ($1 eq '/') { $safe .= '&fslash;'; }
else { $safe .= $1; }
2017-09-05 04:06:31 +02:00
}
2020-02-15 23:38:32 +01:00
return lc $safe;
2017-09-05 04:06:31 +02:00
}
1;