Commit | Line | Data |
86382b95 |
1 | package Gitalist::Util; |
2 | |
3 | use Sub::Exporter -setup => { |
4 | exports => ['to_utf8'] |
5 | }; |
6 | |
7 | =pod |
8 | |
9 | =head1 NAME |
10 | |
11 | Gitalist::Util - Your usual catch all utility function package. |
12 | |
13 | =cut |
14 | |
15 | # decode sequences of octets in utf8 into Perl's internal form, |
16 | # which is utf-8 with utf8 flag set if needed. gitweb writes out |
17 | # in utf-8 thanks to "binmode STDOUT, ':utf8'" at beginning |
18 | sub to_utf8 { |
19 | my $str = shift; |
20 | if (utf8::valid($str)) { |
21 | utf8::decode($str); |
22 | return $str; |
23 | } else { |
24 | return decode($fallback_encoding, $str, Encode::FB_DEFAULT); |
25 | } |
26 | } |
27 | |
28 | 1; |